diff options
author | jkh <jkh@FreeBSD.org> | 1994-12-06 00:51:50 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1994-12-06 00:51:50 +0000 |
commit | 773a5f451d951042f1a9541533ee9b5c97430c39 (patch) | |
tree | 769d2ca49d84039a97bd74c4ce202b318da0828a /usr.sbin/pkg_install/lib/file.c | |
parent | f9dc382f6c8f8900550f2f35436613d329df120d (diff) | |
download | FreeBSD-src-773a5f451d951042f1a9541533ee9b5c97430c39.zip FreeBSD-src-773a5f451d951042f1a9541533ee9b5c97430c39.tar.gz |
Many of John T. Kohl's patches from NetBSD. Thanks, John!
Submitted by: jkohl
Diffstat (limited to 'usr.sbin/pkg_install/lib/file.c')
-rw-r--r-- | usr.sbin/pkg_install/lib/file.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c index 698fd87..e2c2668 100644 --- a/usr.sbin/pkg_install/lib/file.c +++ b/usr.sbin/pkg_install/lib/file.c @@ -1,5 +1,5 @@ #ifndef lint -static const char *rcsid = "$Id: file.c,v 1.4 1993/09/06 23:28:42 jkh Exp $"; +static const char *rcsid = "$Id: file.c,v 1.5 1993/09/18 03:39:48 jkh Exp $"; #endif /* @@ -39,8 +39,7 @@ isdir(char *fname) { struct stat sb; - if (stat(fname, &sb) != FAIL && - (sb.st_mode & S_IFDIR)) + if (stat(fname, &sb) != FAIL && S_ISDIR(sb.st_mode)) return TRUE; else return FALSE; @@ -48,7 +47,7 @@ isdir(char *fname) /* Check to see if file is a dir, and is empty */ Boolean -isempty(char *fname) +isemptydir(char *fname) { if (isdir(fname)) { DIR *dirp; @@ -69,6 +68,19 @@ isempty(char *fname) return FALSE; } +/* Check to see if file is a file and is empty. If nonexistent or not + a file, say "it's empty", otherwise return TRUE if zero sized. */ +Boolean +isemptyfile(char *fname) +{ + struct stat sb; + if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode)) { + if (sb.st_size != 0) + return FALSE; + } + return TRUE; +} + char * get_file_contents(char *fname) { @@ -84,7 +96,7 @@ get_file_contents(char *fname) if (fd == FAIL) barf("Unable to open '%s' for reading.", fname); if (read(fd, contents, sb.st_size) != sb.st_size) - barf("Short read on '%s' - did not get %d bytes.", fname, sb.st_size); + barf("Short read on '%s' - did not get %qd bytes.", fname, sb.st_size); close(fd); contents[sb.st_size] = '\0'; return contents; |