X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=osl.c;h=1d5db11ef4c65b32bca5f546596b5d1668262d5c;hb=c870a921193000e3a5123ee4037a81c18218aea5;hp=5786939088bf9ef0147694fca40be43f320d6b7e;hpb=42a43cd4cc1849658130214cb244e0c88e824471;p=osl.git diff --git a/osl.c b/osl.c index 5786939..1d5db11 100644 --- a/osl.c +++ b/osl.c @@ -104,7 +104,7 @@ __printf_2_3 void __log(int ll, const char* fmt,...) * * \sa lseek(2). */ -int para_lseek(int fd, off_t *offset, int whence) +static int __lseek(int fd, off_t *offset, int whence) { *offset = lseek(fd, *offset, whence); int ret = -E_LSEEK; @@ -128,7 +128,7 @@ int para_lseek(int fd, off_t *offset, int whence) * * \sa write(2). */ -ssize_t para_write(int fd, const void *buf, size_t size) +static ssize_t __write(int fd, const void *buf, size_t size) { ssize_t ret; @@ -155,12 +155,12 @@ ssize_t para_write(int fd, const void *buf, size_t size) * * \sa para_write(). */ -ssize_t para_write_all(int fd, const void *buf, size_t size) +static ssize_t write_all(int fd, const void *buf, size_t size) { // DEBUG_LOG("writing %zu bytes\n", size); const char *b = buf; while (size) { - ssize_t ret = para_write(fd, b, size); + ssize_t ret = __write(fd, b, size); // DEBUG_LOG("ret: %zd\n", ret); if (ret < 0) return ret; @@ -181,7 +181,7 @@ ssize_t para_write_all(int fd, const void *buf, size_t size) * * \sa para_open(), para_write(). */ -int para_write_file(const char *filename, const void *buf, size_t size) +static int write_file(const char *filename, const void *buf, size_t size) { int ret, fd; @@ -189,7 +189,7 @@ int para_write_file(const char *filename, const void *buf, size_t size) if (ret < 0) return ret; fd = ret; - ret = para_write_all(fd, buf, size); + ret = write_all(fd, buf, size); if (ret < 0) goto out; ret = 1; @@ -209,16 +209,16 @@ static int append_file(const char *filename, char *header, size_t header_size, return ret; fd = ret; if (header && header_size) { - ret = para_write_all(fd, header, header_size); + ret = write_all(fd, header, header_size); if (ret < 0) goto out; } - ret = para_write_all(fd, data, data_size); + ret = write_all(fd, data, data_size); if (ret < 0) goto out; if (new_pos) { off_t offset = 0; - ret = para_lseek(fd, &offset, SEEK_END); + ret = __lseek(fd, &offset, SEEK_END); if (ret < 0) goto out; // DEBUG_LOG("new file size: " FMT_OFF_T "\n", offset); @@ -230,71 +230,6 @@ out: return ret; } -/** - * Traverse the given directory recursively. - * - * \param dirname The directory to traverse. - * \param func The function to call for each entry. - * \param private_data Pointer to an arbitrary data structure. - * - * For each regular file under \a dirname, the supplied function \a func is - * called. The full path of the regular file and the \a private_data pointer - * are passed to \a func. Directories for which the calling process has no - * permissions to change to are silently ignored. - * - * \return Standard. - */ -int for_each_file_in_dir(const char *dirname, - int (*func)(const char *, void *), void *private_data) -{ - DIR *dir; - struct dirent *entry; - int cwd_fd, ret2, ret = para_opendir(dirname, &dir, &cwd_fd); - - if (ret < 0) - return ret == -ERRNO_TO_ERROR(EACCES)? 1 : ret; - /* scan cwd recursively */ - while ((entry = readdir(dir))) { - mode_t m; - char *tmp; - struct stat s; - - if (!strcmp(entry->d_name, ".")) - continue; - if (!strcmp(entry->d_name, "..")) - continue; - if (lstat(entry->d_name, &s) == -1) - continue; - m = s.st_mode; - if (!S_ISREG(m) && !S_ISDIR(m)) - continue; - tmp = make_message("%s/%s", dirname, entry->d_name); - ret = -ERRNO_TO_ERROR(ENOMEM); - if (!tmp) - goto out; - if (!S_ISDIR(m)) { - ret = func(tmp, private_data); - free(tmp); - if (ret < 0) - goto out; - continue; - } - /* directory */ - ret = for_each_file_in_dir(tmp, func, private_data); - free(tmp); - if (ret < 0) - goto out; - } - ret = 1; -out: - closedir(dir); - ret2 = para_fchdir(cwd_fd); - if (ret2 < 0 && ret >= 0) - ret = ret2; - close(cwd_fd); - return ret; -} - static int verify_name(const char *name) { if (!name) @@ -714,7 +649,7 @@ static int create_table_index(struct osl_table *t) assert(offset = size); filename = index_filename(t->desc); if (filename) - ret = para_write_file(filename, buf, size); + ret = write_file(filename, buf, size); else ret = -ERRNO_TO_ERROR(ENOMEM); free(buf); @@ -1368,7 +1303,7 @@ static int write_disk_storage_file(const struct osl_table *t, unsigned col_num, filename = disk_storage_path(t, col_num, ds_name); if (!filename) return -ERRNO_TO_ERROR(ENOMEM); - ret = para_write_file(filename, obj->data, obj->size); + ret = write_file(filename, obj->data, obj->size); free(filename); return ret; }