add strlcpy compatibility file for non-openbsd

master v0.1.1
Shokara Kou 6 months ago
parent 6483e52df1
commit 68dd2c064d
  1. 2
      Makefile
  2. 2
      README
  3. 4
      config.mk
  4. 3
      parse.c
  5. 54
      strlcpy.c
  6. 3
      strlcpy.h

@ -1,6 +1,6 @@
include config.mk
SRC = main.c xml.c parse.c save.c
SRC = main.c xml.c parse.c save.c strlcpy.c
OBJ = ${SRC:.c=.o}
all: rssdl

@ -10,7 +10,7 @@ from Yoran Heling.
Dependencies
------------
- C89 compatible compiler
- C99 compatible compiler
- POSIX-compliant libc
- a way to pipe the feed data to rssdl

@ -2,8 +2,8 @@
PREFIX = ~/.local
# flags
#CPPFLAGS = -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=500
CFLAGS = -static -g -O3 -std=c89 -Wall -Wextra -Wshadow -pedantic -pedantic-errors -Wno-unused-parameter
CPPFLAGS = -D_XOPEN_SOURCE=500
CFLAGS = -static -g -O3 -std=c99 -Wall -Wextra -Wshadow -pedantic -pedantic-errors -Wno-unused-parameter
# compiler/linker
CC = cc

@ -6,6 +6,9 @@
#include "parse.h"
#include "save.h"
#include "xml.h"
#ifndef OpenBSD
#include "strlcpy.h"
#endif
#define istag(name) strcmp(x->tag, name) == 0

@ -0,0 +1,54 @@
/* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */
/*
* Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef OpenBSD
#include <sys/types.h>
#include <string.h>
/*
* Copy string src to buffer dst of size dsize. At most dsize-1
* chars will be copied. Always NUL terminates (unless dsize == 0).
* Returns strlen(src); if retval >= dsize, truncation occurred.
*/
size_t
strlcpy(char *dst, const char *src, size_t dsize)
{
const char *osrc = src;
size_t nleft = dsize;
/* Copy as many bytes as will fit. */
if (nleft != 0) {
while (--nleft != 0) {
if ((*dst++ = *src++) == '\0')
break;
}
}
/* Not enough room in dst, add NUL and traverse rest of src. */
if (nleft == 0) {
if (dsize != 0)
*dst = '\0'; /* NUL-terminate dst */
while (*src++)
;
}
return(src - osrc - 1); /* count does not include NUL */
}
#endif

@ -0,0 +1,3 @@
#ifndef OpenBSD
size_t strlcpy(char *, const char *, size_t);
#endif
Loading…
Cancel
Save