Put strlcpy/strlcat in separate source file

SVN revision: 1340
This commit is contained in:
2005-05-02 10:17:09 +00:00
parent dcc7e7d22e
commit 58168a67e1
4 changed files with 27 additions and 76 deletions
+8 -5
View File
@@ -45,11 +45,14 @@ regex.o: src/regex.c src/regex.h
mxml.o: $(MXMLDIR)/mxml.c $(MXMLDIR)/mxml.h
$(CC) $(CFLAGS) -DHAVE_STRLCPY -c -o mxml.o $(MXMLDIR)/mxml.c
elogd: src/elogd.c regex.o mxml.o
$(CC) $(CFLAGS) -I$(MXMLDIR) -o elogd src/elogd.c regex.o mxml.o $(LIBS)
strlcpy.o: src/strlcpy.c src/strlcpy.h
$(CC) $(CFLAGS) -c -o strlcpy.o src/strlcpy.c
debug: src/elogd.c regex.o mxml.o
$(CC) -g -I$(MXMLDIR) -o elogd src/elogd.c regex.o mxml.o $(LIBS)
elogd: src/elogd.c regex.o mxml.o strlcpy.o
$(CC) $(CFLAGS) -I$(MXMLDIR) -o elogd src/elogd.c regex.o mxml.o strlcpy.o $(LIBS)
debug: src/elogd.c regex.o mxml.o strlcpy.o
$(CC) -g -I$(MXMLDIR) -o elogd src/elogd.c regex.o mxml.o strlcpy.o $(LIBS)
%: src/%.c
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
@@ -81,5 +84,5 @@ install: $(EXECS)
restart:
/etc/rc.d/init.d/elogd restart
clean:
-$(RM) *~ $(EXECS) regex.o mxml.o
-$(RM) *~ $(EXECS) regex.o mxml.o strlcpy.o
+12 -4
View File
@@ -40,9 +40,11 @@ CLEAN :
-@erase "$(INTDIR)\elogd.obj"
-@erase "$(INTDIR)\regex.obj"
-@erase "$(INTDIR)\mxml.obj"
-@erase "$(INTDIR)\strlcpy.obj"
-@erase "$(INTDIR)\elogd.sbr"
-@erase "$(INTDIR)\regex.sbr"
-@erase "$(INTDIR)\mxml.sbr"
-@erase "$(INTDIR)\strlcpy.sbr"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\elogd.bsc"
-@erase "$(OUTDIR)\elogd.exe"
@@ -87,7 +89,7 @@ RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\elogd.bsc"
BSC32_SBRS= \
"$(INTDIR)\elogd.sbr" "$(INTDIR)\regex.sbr" "$(INTDIR)\mxml.sbr"
"$(INTDIR)\elogd.sbr" "$(INTDIR)\regex.sbr" "$(INTDIR)\mxml.sbr" $(INTDIR)\strlcpy.sbr""
"$(OUTDIR)\elogd.bsc" : "$(OUTDIR)" $(BSC32_SBRS)
$(BSC32) @<<
@@ -97,7 +99,7 @@ BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=wsock32.lib advapi32.lib /nologo /subsystem:console /stack:4000000 /incremental:no /pdb:"$(OUTDIR)\elogd.pdb" /machine:I386 /out:"$(OUTDIR)\elogd.exe"
LINK32_OBJS= \
"$(INTDIR)\elogd.obj" "$(INTDIR)\regex.obj" "$(INTDIR)\mxml.obj"
"$(INTDIR)\elogd.obj" "$(INTDIR)\regex.obj" "$(INTDIR)\mxml.obj" "$(INTDIR)\strlcpy.obj"
"$(OUTDIR)\elogd.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
@@ -122,6 +124,8 @@ CLEAN :
-@erase "$(INTDIR)\regex.sbr"
-@erase "$(INTDIR)\mxml.obj"
-@erase "$(INTDIR)\mxml.sbr"
-@erase "$(INTDIR)\strlcpy.obj"
-@erase "$(INTDIR)\strlcpy.sbr"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\elogd.bsc"
@@ -169,7 +173,7 @@ RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\elogd.bsc"
BSC32_SBRS= \
"$(INTDIR)\elogd.sbr" "$(INTDIR)\regex.sbr" "$(INTDIR)\mxml.sbr"
"$(INTDIR)\elogd.sbr" "$(INTDIR)\regex.sbr" "$(INTDIR)\mxml.sbr" "$(INTDIR)\strlcpy.sbr"
"$(OUTDIR)\elogd.bsc" : "$(OUTDIR)" $(BSC32_SBRS)
$(BSC32) @<<
@@ -179,7 +183,7 @@ BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=wsock32.lib advapi32.lib /nologo /subsystem:console /stack:4000000 /incremental:yes /pdb:"$(OUTDIR)\elogd.pdb" /debug /machine:I386 /out:"$(OUTDIR)\elogd.exe" /pdbtype:sept
LINK32_OBJS= \
"$(INTDIR)\elogd.obj" "$(INTDIR)\regex.obj" "$(INTDIR)\mxml.obj"
"$(INTDIR)\elogd.obj" "$(INTDIR)\regex.obj" "$(INTDIR)\mxml.obj" "$(INTDIR)\strlcpy.obj"
"$(OUTDIR)\elogd.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
@@ -212,5 +216,9 @@ SOURCE=..\..\mxml\mxml.c
"$(INTDIR)\mxml.obj" "$(INTDIR)\mxml.sbr" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) /D "HAVE_STRLCPY" $(SOURCE)
SOURCE=..\src\strlcpy.c
"$(INTDIR)\strlcpy.obj" "$(INTDIR)\strlcpy.sbr" : $(SOURCE) "$(INTDIR)"
$(CPP) $(CPP_PROJ) /D "HAVE_STRLCPY" $(SOURCE)
!ENDIF
+3
View File
@@ -175,6 +175,9 @@
<File
RelativePath="..\src\regex.c">
</File>
<File
RelativePath="..\src\strlcpy.c">
</File>
</Filter>
<Filter
Name="Resource Files"
+4 -67
View File
@@ -6,6 +6,9 @@
Contents: Web server program for Electronic Logbook ELOG
$Log$
Revision 1.642 2005/05/02 10:17:09 ritt
Put strlcpy/strlcat in separate source file
Revision 1.641 2005/05/02 10:06:33 ritt
Version 2.5.9-1
@@ -1147,6 +1150,7 @@ char pidfile[256]; /* Pidfile name
/* local includes */
#include "regex.h"
#include "mxml.h"
#include "strlcpy.h"
BOOL running_as_daemon; /* Running as a daemon/service? */
int elog_tcp_port = (int) DEFAULT_PORT; /* Server's TCP port */
@@ -1842,73 +1846,6 @@ void redirect_to_stderr(void)
/*------------------------------------------------------------------*/
/*---- strlcpy and strlcat to avoid buffer overflow ----------------*/
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless size == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t strlcpy(char *dst, const char *src, size_t size)
{
char *d = dst;
const char *s = src;
size_t n = size;
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0) {
do {
if ((*d++ = *s++) == 0)
break;
} while (--n != 0);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (size != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++);
}
return (s - src - 1); /* count does not include NUL */
}
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters
* will be copied. Always NUL terminates (unless size <= strlen(dst)).
* Returns strlen(src) + MIN(size, strlen(initial dst)).
* If retval >= size, truncation occurred.
*/
size_t strlcat(char *dst, const char *src, size_t size)
{
char *d = dst;
const char *s = src;
size_t n = size;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0')
d++;
dlen = d - dst;
n = size - dlen;
if (n == 0)
return (dlen + strlen(s));
while (*s != '\0') {
if (n != 1) {
*d++ = *s;
n--;
}
s++;
}
*d = '\0';
return (dlen + (s - src)); /* count does not include NUL */
}
/*-------------------------------------------------------------------*/
void strsubst(char *string, int size, char name[][NAME_LENGTH], char value[][NAME_LENGTH], int n)
/* subsitute "$name" with value corresponding to name */
{