Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/distrib/utils/sysinst Simplify code that opens file for -f o...
details: https://anonhg.NetBSD.org/src/rev/23a6003672eb
branches: trunk
changeset: 571149:23a6003672eb
user: dsl <dsl%NetBSD.org@localhost>
date: Thu Nov 11 20:17:48 2004 +0000
description:
Simplify code that opens file for -f option.
I bet no one ever uses the option anyway!
diffstat:
distrib/utils/sysinst/main.c | 45 +++++++++++++++++++------------------------
1 files changed, 20 insertions(+), 25 deletions(-)
diffs (76 lines):
diff -r fb618b21234b -r 23a6003672eb distrib/utils/sysinst/main.c
--- a/distrib/utils/sysinst/main.c Thu Nov 11 20:17:36 2004 +0000
+++ b/distrib/utils/sysinst/main.c Thu Nov 11 20:17:48 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.47 2004/07/17 10:55:03 dsl Exp $ */
+/* $NetBSD: main.c,v 1.48 2004/11/11 20:17:48 dsl Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -455,27 +455,8 @@
process_f_flag(char *f_name)
{
char *buffer;
- struct stat statinfo;
int fd;
-
- /* stat the file (error reported) */
-
- if (stat(f_name, &statinfo) < 0) {
- perror(f_name); /* XXX -- better message? */
- exit(1);
- }
-
- if ((statinfo.st_mode & S_IFMT) != S_IFREG) {
- fprintf(stderr, msg_string(MSG_not_regular_file), f_name);
- exit(1);
- }
-
- /* allocate buffer (error reported) */
- buffer = malloc((size_t)statinfo.st_size + 1);
- if (buffer == NULL) {
- fprintf(stderr, msg_string(MSG_out_of_memory));
- exit(1);
- }
+ int fsize;
/* open the file */
fd = open(f_name, O_RDONLY, 0);
@@ -484,19 +465,33 @@
exit(1);
}
+ /* get file size */
+ fsize = lseek(fd, 0, SEEK_END);
+ lseek(fd, 0, SEEK_SET);
+ if (fsize == -1) {
+ fprintf(stderr, msg_string(MSG_not_regular_file), f_name);
+ exit(1);
+ }
+
+ /* allocate buffer (error reported) */
+ buffer = malloc(fsize + 1);
+ if (buffer == NULL) {
+ fprintf(stderr, msg_string(MSG_out_of_memory));
+ exit(1);
+ }
+
/* read the file */
- if (read(fd,buffer, (size_t)statinfo.st_size)
- != (size_t)statinfo.st_size) {
+ if (read(fd,buffer, fsize) != fsize) {
fprintf(stderr, msg_string(MSG_config_read_error), f_name);
exit(1);
}
- buffer[(size_t)statinfo.st_size] = 0;
+ buffer[fsize] = 0;
/* close the file */
close(fd);
/* Walk the buffer */
- walk(buffer, (size_t)statinfo.st_size, fflagopts,
+ walk(buffer, fsize, fflagopts,
sizeof(fflagopts)/sizeof(struct lookfor));
/* free the buffer */
Home |
Main Index |
Thread Index |
Old Index