summaryrefslogtreecommitdiff
path: root/builtins/mkbuiltins.c
diff options
context:
space:
mode:
authorJari Aalto <jari.aalto@cante.net>1998-04-17 19:52:44 +0000
committerJari Aalto <jari.aalto@cante.net>2009-09-12 16:46:51 +0000
commitcce855bc5b117cb7ae70064131120687bc69fac0 (patch)
tree39c7a4ec8f6d22ef03df74f2684e6a04fef10399 /builtins/mkbuiltins.c
parente8ce775db824de329b81293b4e5d8fbd65624528 (diff)
downloadbash-cce855bc5b117cb7ae70064131120687bc69fac0.tar.gz
Imported from ../bash-2.02.tar.gz.
Diffstat (limited to 'builtins/mkbuiltins.c')
-rw-r--r--builtins/mkbuiltins.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/builtins/mkbuiltins.c b/builtins/mkbuiltins.c
index 983bada8..8cd27039 100644
--- 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)
+# ifdef _MINIX
+# include <sys/types.h>
+# endif
# include <unistd.h>
#endif
+#ifndef _MINIX
#include "../bashtypes.h"
#include <sys/file.h>
+#endif
+
#include "../posixstat.h"
#include "../filecntl.h"
-#if defined (HAVE_UNISTD_H)
-# include <unistd.h>
-#endif /* HAVE_UNISTD_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;
+ size_t file_size;
char *buffer, *line;
- int fd;
+ int fd, nr;
if (stat (filename, &finfo) == -1)
file_error (filename);
@@ -448,13 +451,20 @@ extract_info (filename, structfile, externfile)
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);
+ 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;
@@ -466,11 +476,11 @@ extract_info (filename, structfile, externfile)
/* Build the array of lines. */
i = 0;
- while (i < finfo.st_size)
+ while (i < file_size)
{
array_add (&buffer[i], defs->lines);
- while (buffer[i] != '\n' && i < finfo.st_size)
+ while (buffer[i] != '\n' && i < file_size)
i++;
buffer[i++] = '\0';
}
@@ -676,7 +686,10 @@ current_builtin (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.
@@ -756,6 +769,11 @@ function_handler (self, defs, arg)
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);