Imported from LPlib, making sure the entry name (at least on Unix) is
NUL-teminated at all times, and that we don't make unneeded calls to free().
This commit is contained in:
parent
334ef04949
commit
210a4f78ae
@ -1,4 +1,4 @@
|
|||||||
/* $LP: LPlib/source/LPdir_unix.c,v 1.6 2004/06/14 10:08:43 _cvs_levitte Exp $ */
|
/* $LP: LPlib/source/LPdir_unix.c,v 1.8 2004/07/19 16:34:39 _cvs_levitte Exp $ */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2004, Richard Levitte <richard@levitte.org>
|
* Copyright (c) 2004, Richard Levitte <richard@levitte.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@ -79,7 +79,8 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy((*ctx)->entry_name, direntry->d_name, sizeof((*ctx)->entry_name));
|
strncpy((*ctx)->entry_name, direntry->d_name, sizeof((*ctx)->entry_name) - 1);
|
||||||
|
(*ctx)->entry_name[sizeof((*ctx)->entry_name) - 1] = '\0';
|
||||||
return (*ctx)->entry_name;
|
return (*ctx)->entry_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $LP: LPlib/source/LPdir_win.c,v 1.1 2004/06/14 10:07:56 _cvs_levitte Exp $ */
|
/* $LP: LPlib/source/LPdir_win.c,v 1.3 2004/07/19 16:34:54 _cvs_levitte Exp $ */
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2004, Richard Levitte <richard@levitte.org>
|
* Copyright (c) 2004, Richard Levitte <richard@levitte.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@ -53,7 +53,6 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
|
|||||||
if (*ctx == NULL)
|
if (*ctx == NULL)
|
||||||
{
|
{
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
free(*ctx);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memset(*ctx, '\0', sizeof(LP_DIR_CTX));
|
memset(*ctx, '\0', sizeof(LP_DIR_CTX));
|
||||||
@ -68,7 +67,6 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
|
|||||||
{
|
{
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
free(*ctx);
|
free(*ctx);
|
||||||
free(wdir);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user