diff options
author | Andrew Tridgell <tridge@samba.org> | 2006-10-28 06:06:15 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:24:40 -0500 |
commit | 9cd2b012f3bf9f21f321d44c43eb5a8a781d68fc (patch) | |
tree | 6bfe7a5af735a980f8a8d120d60f3326ac8e7d5a /source4/lib | |
parent | 863bd921f26f95523674de325e520ae2523df3a9 (diff) | |
download | samba-9cd2b012f3bf9f21f321d44c43eb5a8a781d68fc.tar.gz samba-9cd2b012f3bf9f21f321d44c43eb5a8a781d68fc.tar.bz2 samba-9cd2b012f3bf9f21f321d44c43eb5a8a781d68fc.zip |
r19504: - fixed a free error in file_lines_parse
- added a function to test for large file support
- enable CAP_LARGE_FILES only if the test passes
- don't test at large offsets if the server doesn't set
CAP_LARGE_FILES
(This used to be commit c5423ea22bdaa055807d4e6f7ac4be934194fe45)
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/util/util_file.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/source4/lib/util/util_file.c b/source4/lib/util/util_file.c index 3451712053..5d7ec40b30 100644 --- a/source4/lib/util/util_file.c +++ b/source4/lib/util/util_file.c @@ -241,6 +241,7 @@ _PUBLIC_ void *map_file(const char *fname, size_t size) /** parse a buffer into lines +'p' will be freed on error, and otherwise will be made a child of the returned array **/ static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX *mem_ctx) { @@ -259,7 +260,7 @@ static char **file_lines_parse(char *p, size_t size, int *numlines, TALLOC_CTX * return NULL; } - talloc_reference(ret, p); + talloc_steal(ret, p); memset(ret, 0, sizeof(ret[0])*(i+2)); if (numlines) *numlines = i; @@ -285,17 +286,12 @@ must be freed with talloc_free(). _PUBLIC_ char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx) { char *p; - char **lines; size_t size; p = file_load(fname, &size, mem_ctx); if (!p) return NULL; - lines = file_lines_parse(p, size, numlines, mem_ctx); - - talloc_free(p); - - return lines; + return file_lines_parse(p, size, numlines, mem_ctx); } /** @@ -306,17 +302,12 @@ the list. _PUBLIC_ char **fd_lines_load(int fd, int *numlines, TALLOC_CTX *mem_ctx) { char *p; - char **lines; size_t size; p = fd_load(fd, &size, mem_ctx); if (!p) return NULL; - lines = file_lines_parse(p, size, numlines, mem_ctx); - - talloc_free(p); - - return lines; + return file_lines_parse(p, size, numlines, mem_ctx); } @@ -385,3 +376,24 @@ _PUBLIC_ int fdprintf(int fd, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) va_end(ap); return ret; } + + +/* + try to determine if the filesystem supports large files +*/ +_PUBLIC_ bool large_file_support(const char *path) +{ + int fd; + ssize_t ret; + char c; + + fd = open(path, O_RDWR|O_CREAT, 0600); + unlink(path); + if (fd == -1) { + /* have to assume large files are OK */ + return true; + } + ret = pread(fd, &c, 1, ((uint64_t)1)<<32); + close(fd); + return ret == 0; +} |