projects
/
platform
/
upstream
/
bash.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Imported from ../bash-2.02.tar.gz.
[platform/upstream/bash.git]
/
builtins
/
mkbuiltins.c
diff --git
a/builtins/mkbuiltins.c
b/builtins/mkbuiltins.c
index
983bada
..
8cd2703
100644
(file)
--- a/
builtins/mkbuiltins.c
+++ b/
builtins/mkbuiltins.c
@@
-22,18
+22,20
@@
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <config.h>
#if defined (HAVE_UNISTD_H)
#include <config.h>
#if defined (HAVE_UNISTD_H)
+# ifdef _MINIX
+# include <sys/types.h>
+# endif
# include <unistd.h>
#endif
# include <unistd.h>
#endif
+#ifndef _MINIX
#include "../bashtypes.h"
#include <sys/file.h>
#include "../bashtypes.h"
#include <sys/file.h>
+#endif
+
#include "../posixstat.h"
#include "../filecntl.h"
#include "../posixstat.h"
#include "../filecntl.h"
-#if defined (HAVE_UNISTD_H)
-# include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
#include "../bashansi.h"
#include <stdio.h>
#include "../bashansi.h"
#include <stdio.h>
@@
-437,8
+439,9
@@
extract_info (filename, structfile, externfile)
register int i;
DEF_FILE *defs;
struct stat finfo;
register int i;
DEF_FILE *defs;
struct stat finfo;
+ size_t file_size;
char *buffer, *line;
char *buffer, *line;
- int fd;
+ int fd
, nr
;
if (stat (filename, &finfo) == -1)
file_error (filename);
if (stat (filename, &finfo) == -1)
file_error (filename);
@@
-448,13
+451,20
@@
extract_info (filename, structfile, externfile)
if (fd == -1)
file_error (filename);
if (fd == -1)
file_error (filename);
- buffer = xmalloc (1 + (int)finfo.st_size);
+ file_size = (size_t)finfo.st_size;
+ buffer = xmalloc (1 + file_size);
- if (
read (fd, buffer, finfo.st_size) != finfo.st_size
)
+ if (
(nr = read (fd, buffer, file_size)) < 0
)
file_error (filename);
close (fd);
file_error (filename);
close (fd);
+ if (nr == 0)
+ {
+ fprintf (stderr, "mkbuiltins: %s: skipping zero-length file\n", filename);
+ return;
+ }
+
/* Create and fill in the initial structure describing this file. */
defs = (DEF_FILE *)xmalloc (sizeof (DEF_FILE));
defs->filename = filename;
/* Create and fill in the initial structure describing this file. */
defs = (DEF_FILE *)xmalloc (sizeof (DEF_FILE));
defs->filename = filename;
@@
-466,11
+476,11
@@
extract_info (filename, structfile, externfile)
/* Build the array of lines. */
i = 0;
/* Build the array of lines. */
i = 0;
- while (i < fi
nfo.st
_size)
+ while (i < fi
le
_size)
{
array_add (&buffer[i], defs->lines);
{
array_add (&buffer[i], defs->lines);
- while (buffer[i] != '\n' && i < fi
nfo.st
_size)
+ while (buffer[i] != '\n' && i < fi
le
_size)
i++;
buffer[i++] = '\0';
}
i++;
buffer[i++] = '\0';
}
@@
-676,7
+686,10
@@
current_builtin (directive, defs)
DEF_FILE *defs;
{
must_be_building (directive, defs);
DEF_FILE *defs;
{
must_be_building (directive, defs);
- return ((BUILTIN_DESC *)defs->builtins->array[defs->builtins->sindex - 1]);
+ if (defs->builtins)
+ return ((BUILTIN_DESC *)defs->builtins->array[defs->builtins->sindex - 1]);
+ else
+ return ((BUILTIN_DESC *)NULL);
}
/* Add LINE to the long documentation for the current builtin.
}
/* Add LINE to the long documentation for the current builtin.
@@
-756,6
+769,11
@@
function_handler (self, defs, arg)
builtin = current_builtin (self, defs);
builtin = current_builtin (self, defs);
+ if (builtin == 0)
+ {
+ line_error (defs, "syntax error: no current builtin for $FUNCTION directive");
+ exit (1);
+ }
if (builtin->function)
line_error (defs, "%s already has a function (%s)",
builtin->name, builtin->function);
if (builtin->function)
line_error (defs, "%s already has a function (%s)",
builtin->name, builtin->function);