diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-06 09:35:14 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-06 09:35:14 +0000 |
commit | 99ba3c2b1294b890671d0d7d6e4319be70bee5a0 (patch) | |
tree | 2e9b1339869d5f115b80246b63af6c0604023e75 /src/util/disk.c | |
parent | aee28f4afd42710aba0c37d8ec86572aef092044 (diff) | |
download | gnunet-99ba3c2b1294b890671d0d7d6e4319be70bee5a0.tar.gz gnunet-99ba3c2b1294b890671d0d7d6e4319be70bee5a0.zip |
-doxygen, coding conventions
Diffstat (limited to 'src/util/disk.c')
-rw-r--r-- | src/util/disk.c | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/src/util/disk.c b/src/util/disk.c index 7729fd8ee..9390743fd 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -1107,7 +1107,7 @@ GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n, | |||
1107 | /** | 1107 | /** |
1108 | * Scan a directory for files. | 1108 | * Scan a directory for files. |
1109 | * | 1109 | * |
1110 | * @param dirName the name of the directory | 1110 | * @param dir_name the name of the directory |
1111 | * @param callback the method to call for each file, | 1111 | * @param callback the method to call for each file, |
1112 | * can be NULL, in that case, we only count | 1112 | * can be NULL, in that case, we only count |
1113 | * @param callback_cls closure for callback | 1113 | * @param callback_cls closure for callback |
@@ -1115,7 +1115,7 @@ GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n, | |||
1115 | * ieration aborted by callback returning GNUNET_SYSERR | 1115 | * ieration aborted by callback returning GNUNET_SYSERR |
1116 | */ | 1116 | */ |
1117 | int | 1117 | int |
1118 | GNUNET_DISK_directory_scan (const char *dirName, | 1118 | GNUNET_DISK_directory_scan (const char *dir_name, |
1119 | GNUNET_FileNameCallback callback, | 1119 | GNUNET_FileNameCallback callback, |
1120 | void *callback_cls) | 1120 | void *callback_cls) |
1121 | { | 1121 | { |
@@ -1129,8 +1129,8 @@ GNUNET_DISK_directory_scan (const char *dirName, | |||
1129 | unsigned int name_len; | 1129 | unsigned int name_len; |
1130 | unsigned int n_size; | 1130 | unsigned int n_size; |
1131 | 1131 | ||
1132 | GNUNET_assert (dirName != NULL); | 1132 | GNUNET_assert (dir_name != NULL); |
1133 | dname = GNUNET_STRINGS_filename_expand (dirName); | 1133 | dname = GNUNET_STRINGS_filename_expand (dir_name); |
1134 | if (dname == NULL) | 1134 | if (dname == NULL) |
1135 | return GNUNET_SYSERR; | 1135 | return GNUNET_SYSERR; |
1136 | while ((strlen (dname) > 0) && (dname[strlen (dname) - 1] == DIR_SEPARATOR)) | 1136 | while ((strlen (dname) > 0) && (dname[strlen (dname) - 1] == DIR_SEPARATOR)) |
@@ -1144,7 +1144,7 @@ GNUNET_DISK_directory_scan (const char *dirName, | |||
1144 | if (!S_ISDIR (istat.st_mode)) | 1144 | if (!S_ISDIR (istat.st_mode)) |
1145 | { | 1145 | { |
1146 | LOG (GNUNET_ERROR_TYPE_WARNING, _("Expected `%s' to be a directory!\n"), | 1146 | LOG (GNUNET_ERROR_TYPE_WARNING, _("Expected `%s' to be a directory!\n"), |
1147 | dirName); | 1147 | dir_name); |
1148 | GNUNET_free (dname); | 1148 | GNUNET_free (dname); |
1149 | return GNUNET_SYSERR; | 1149 | return GNUNET_SYSERR; |
1150 | } | 1150 | } |
@@ -1310,7 +1310,7 @@ GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter, | |||
1310 | * may provide a simpler API. | 1310 | * may provide a simpler API. |
1311 | * | 1311 | * |
1312 | * @param prio priority to use | 1312 | * @param prio priority to use |
1313 | * @param dirName the name of the directory | 1313 | * @param dir_name the name of the directory |
1314 | * @param callback the method to call for each file | 1314 | * @param callback the method to call for each file |
1315 | * @param callback_cls closure for callback | 1315 | * @param callback_cls closure for callback |
1316 | * @return GNUNET_YES if directory is not empty and 'callback' | 1316 | * @return GNUNET_YES if directory is not empty and 'callback' |
@@ -1318,7 +1318,7 @@ GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter, | |||
1318 | */ | 1318 | */ |
1319 | int | 1319 | int |
1320 | GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio, | 1320 | GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio, |
1321 | const char *dirName, | 1321 | const char *dir_name, |
1322 | GNUNET_DISK_DirectoryIteratorCallback | 1322 | GNUNET_DISK_DirectoryIteratorCallback |
1323 | callback, void *callback_cls) | 1323 | callback, void *callback_cls) |
1324 | { | 1324 | { |
@@ -1327,14 +1327,14 @@ GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio, | |||
1327 | di = GNUNET_malloc (sizeof (struct GNUNET_DISK_DirectoryIterator)); | 1327 | di = GNUNET_malloc (sizeof (struct GNUNET_DISK_DirectoryIterator)); |
1328 | di->callback = callback; | 1328 | di->callback = callback; |
1329 | di->callback_cls = callback_cls; | 1329 | di->callback_cls = callback_cls; |
1330 | di->directory = OPENDIR (dirName); | 1330 | di->directory = OPENDIR (dir_name); |
1331 | if (di->directory == NULL) | 1331 | if (di->directory == NULL) |
1332 | { | 1332 | { |
1333 | GNUNET_free (di); | 1333 | GNUNET_free (di); |
1334 | callback (callback_cls, NULL, NULL, NULL); | 1334 | callback (callback_cls, NULL, NULL, NULL); |
1335 | return GNUNET_SYSERR; | 1335 | return GNUNET_SYSERR; |
1336 | } | 1336 | } |
1337 | di->dirname = GNUNET_strdup (dirName); | 1337 | di->dirname = GNUNET_strdup (dir_name); |
1338 | di->priority = prio; | 1338 | di->priority = prio; |
1339 | return GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); | 1339 | return GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); |
1340 | } | 1340 | } |
@@ -1400,10 +1400,11 @@ GNUNET_DISK_directory_remove (const char *filename) | |||
1400 | * | 1400 | * |
1401 | * @param src file to copy | 1401 | * @param src file to copy |
1402 | * @param dst destination file name | 1402 | * @param dst destination file name |
1403 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 1403 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1404 | */ | 1404 | */ |
1405 | int | 1405 | int |
1406 | GNUNET_DISK_file_copy (const char *src, const char *dst) | 1406 | GNUNET_DISK_file_copy (const char *src, |
1407 | const char *dst) | ||
1407 | { | 1408 | { |
1408 | char *buf; | 1409 | char *buf; |
1409 | uint64_t pos; | 1410 | uint64_t pos; |
@@ -1514,14 +1515,14 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user) | |||
1514 | /** | 1515 | /** |
1515 | * Lock a part of a file | 1516 | * Lock a part of a file |
1516 | * @param fh file handle | 1517 | * @param fh file handle |
1517 | * @param lockStart absolute position from where to lock | 1518 | * @param lock_start absolute position from where to lock |
1518 | * @param lockEnd absolute position until where to lock | 1519 | * @param lock_end absolute position until where to lock |
1519 | * @param excl GNUNET_YES for an exclusive lock | 1520 | * @param excl GNUNET_YES for an exclusive lock |
1520 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 1521 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
1521 | */ | 1522 | */ |
1522 | int | 1523 | int |
1523 | GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, OFF_T lockStart, | 1524 | GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, OFF_T lock_start, |
1524 | OFF_T lockEnd, int excl) | 1525 | OFF_T lock_end, int excl) |
1525 | { | 1526 | { |
1526 | if (fh == NULL) | 1527 | if (fh == NULL) |
1527 | { | 1528 | { |
@@ -1535,20 +1536,20 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, OFF_T lockStart, | |||
1535 | memset (&fl, 0, sizeof (struct flock)); | 1536 | memset (&fl, 0, sizeof (struct flock)); |
1536 | fl.l_type = excl ? F_WRLCK : F_RDLCK; | 1537 | fl.l_type = excl ? F_WRLCK : F_RDLCK; |
1537 | fl.l_whence = SEEK_SET; | 1538 | fl.l_whence = SEEK_SET; |
1538 | fl.l_start = lockStart; | 1539 | fl.l_start = lock_start; |
1539 | fl.l_len = lockEnd; | 1540 | fl.l_len = lock_end; |
1540 | 1541 | ||
1541 | return fcntl (fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK; | 1542 | return fcntl (fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK; |
1542 | #else | 1543 | #else |
1543 | OVERLAPPED o; | 1544 | OVERLAPPED o; |
1544 | OFF_T diff = lockEnd - lockStart; | 1545 | OFF_T diff = lock_end - lock_start; |
1545 | DWORD diff_low, diff_high; | 1546 | DWORD diff_low, diff_high; |
1546 | diff_low = (DWORD) (diff & 0xFFFFFFFF); | 1547 | diff_low = (DWORD) (diff & 0xFFFFFFFF); |
1547 | diff_high = (DWORD) ((diff >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF); | 1548 | diff_high = (DWORD) ((diff >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF); |
1548 | 1549 | ||
1549 | memset (&o, 0, sizeof (OVERLAPPED)); | 1550 | memset (&o, 0, sizeof (OVERLAPPED)); |
1550 | o.Offset = (DWORD) (lockStart & 0xFFFFFFFF);; | 1551 | o.Offset = (DWORD) (lock_start & 0xFFFFFFFF);; |
1551 | o.OffsetHigh = (DWORD) (((lockStart & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF); | 1552 | o.OffsetHigh = (DWORD) (((lock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF); |
1552 | 1553 | ||
1553 | if (!LockFileEx | 1554 | if (!LockFileEx |
1554 | (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | LOCKFILE_FAIL_IMMEDIATELY, | 1555 | (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) | LOCKFILE_FAIL_IMMEDIATELY, |
@@ -1566,13 +1567,13 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, OFF_T lockStart, | |||
1566 | /** | 1567 | /** |
1567 | * Unlock a part of a file | 1568 | * Unlock a part of a file |
1568 | * @param fh file handle | 1569 | * @param fh file handle |
1569 | * @param unlockStart absolute position from where to unlock | 1570 | * @param unlock_start absolute position from where to unlock |
1570 | * @param unlockEnd absolute position until where to unlock | 1571 | * @param unlock_end absolute position until where to unlock |
1571 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 1572 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
1572 | */ | 1573 | */ |
1573 | int | 1574 | int |
1574 | GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, OFF_T unlockStart, | 1575 | GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, OFF_T unlock_start, |
1575 | OFF_T unlockEnd) | 1576 | OFF_T unlock_end) |
1576 | { | 1577 | { |
1577 | if (fh == NULL) | 1578 | if (fh == NULL) |
1578 | { | 1579 | { |
@@ -1586,20 +1587,20 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, OFF_T unlockStart, | |||
1586 | memset (&fl, 0, sizeof (struct flock)); | 1587 | memset (&fl, 0, sizeof (struct flock)); |
1587 | fl.l_type = F_UNLCK; | 1588 | fl.l_type = F_UNLCK; |
1588 | fl.l_whence = SEEK_SET; | 1589 | fl.l_whence = SEEK_SET; |
1589 | fl.l_start = unlockStart; | 1590 | fl.l_start = unlock_start; |
1590 | fl.l_len = unlockEnd; | 1591 | fl.l_len = unlock_end; |
1591 | 1592 | ||
1592 | return fcntl (fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK; | 1593 | return fcntl (fh->fd, F_SETLK, &fl) != 0 ? GNUNET_SYSERR : GNUNET_OK; |
1593 | #else | 1594 | #else |
1594 | OVERLAPPED o; | 1595 | OVERLAPPED o; |
1595 | OFF_T diff = unlockEnd - unlockStart; | 1596 | OFF_T diff = unlock_end - unlock_start; |
1596 | DWORD diff_low, diff_high; | 1597 | DWORD diff_low, diff_high; |
1597 | diff_low = (DWORD) (diff & 0xFFFFFFFF); | 1598 | diff_low = (DWORD) (diff & 0xFFFFFFFF); |
1598 | diff_high = (DWORD) ((diff >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF); | 1599 | diff_high = (DWORD) ((diff >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF); |
1599 | 1600 | ||
1600 | memset (&o, 0, sizeof (OVERLAPPED)); | 1601 | memset (&o, 0, sizeof (OVERLAPPED)); |
1601 | o.Offset = (DWORD) (unlockStart & 0xFFFFFFFF);; | 1602 | o.Offset = (DWORD) (unlock_start & 0xFFFFFFFF);; |
1602 | o.OffsetHigh = (DWORD) (((unlockStart & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF); | 1603 | o.OffsetHigh = (DWORD) (((unlock_start & ~0xFFFFFFFF) >> (sizeof (DWORD) * 8)) & 0xFFFFFFFF); |
1603 | 1604 | ||
1604 | if (!UnlockFileEx (fh->h, 0, diff_low, diff_high, &o)) | 1605 | if (!UnlockFileEx (fh->h, 0, diff_low, diff_high, &o)) |
1605 | { | 1606 | { |
@@ -1620,12 +1621,13 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, OFF_T unlockStart, | |||
1620 | * @param fn file name to be opened | 1621 | * @param fn file name to be opened |
1621 | * @param flags opening flags, a combination of GNUNET_DISK_OPEN_xxx bit flags | 1622 | * @param flags opening flags, a combination of GNUNET_DISK_OPEN_xxx bit flags |
1622 | * @param perm permissions for the newly created file, use | 1623 | * @param perm permissions for the newly created file, use |
1623 | * GNUNET_DISK_PERM_USER_NONE if a file could not be created by this | 1624 | * #GNUNET_DISK_PERM_USER_NONE if a file could not be created by this |
1624 | * call (because of flags) | 1625 | * call (because of flags) |
1625 | * @return IO handle on success, NULL on error | 1626 | * @return IO handle on success, NULL on error |
1626 | */ | 1627 | */ |
1627 | struct GNUNET_DISK_FileHandle * | 1628 | struct GNUNET_DISK_FileHandle * |
1628 | GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, | 1629 | GNUNET_DISK_file_open (const char *fn, |
1630 | enum GNUNET_DISK_OpenFlags flags, | ||
1629 | enum GNUNET_DISK_AccessPermissions perm) | 1631 | enum GNUNET_DISK_AccessPermissions perm) |
1630 | { | 1632 | { |
1631 | char *expfn; | 1633 | char *expfn; |
@@ -1925,7 +1927,7 @@ GNUNET_DISK_get_handle_from_native (FILE *fd) | |||
1925 | * DIR_SEPARATOR_STR as the last argument before NULL). | 1927 | * DIR_SEPARATOR_STR as the last argument before NULL). |
1926 | * | 1928 | * |
1927 | * @param cfg configuration to use (determines HOME) | 1929 | * @param cfg configuration to use (determines HOME) |
1928 | * @param serviceName name of the service | 1930 | * @param service_name name of the service |
1929 | * @param ... is NULL-terminated list of | 1931 | * @param ... is NULL-terminated list of |
1930 | * path components to append to the | 1932 | * path components to append to the |
1931 | * private directory name. | 1933 | * private directory name. |
@@ -1933,7 +1935,7 @@ GNUNET_DISK_get_handle_from_native (FILE *fd) | |||
1933 | */ | 1935 | */ |
1934 | char * | 1936 | char * |
1935 | GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, | 1937 | GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1936 | const char *serviceName, ...) | 1938 | const char *service_name, ...) |
1937 | { | 1939 | { |
1938 | const char *c; | 1940 | const char *c; |
1939 | char *pfx; | 1941 | char *pfx; |
@@ -1942,19 +1944,19 @@ GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1942 | unsigned int needed; | 1944 | unsigned int needed; |
1943 | 1945 | ||
1944 | if (GNUNET_OK != | 1946 | if (GNUNET_OK != |
1945 | GNUNET_CONFIGURATION_get_value_filename (cfg, serviceName, "HOME", &pfx)) | 1947 | GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "HOME", &pfx)) |
1946 | return NULL; | 1948 | return NULL; |
1947 | if (pfx == NULL) | 1949 | if (pfx == NULL) |
1948 | { | 1950 | { |
1949 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1951 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1950 | _("No `%s' specified for service `%s' in configuration.\n"), "HOME", | 1952 | _("No `%s' specified for service `%s' in configuration.\n"), "HOME", |
1951 | serviceName); | 1953 | service_name); |
1952 | return NULL; | 1954 | return NULL; |
1953 | } | 1955 | } |
1954 | needed = strlen (pfx) + 2; | 1956 | needed = strlen (pfx) + 2; |
1955 | if ((pfx[strlen (pfx) - 1] != '/') && (pfx[strlen (pfx) - 1] != '\\')) | 1957 | if ((pfx[strlen (pfx) - 1] != '/') && (pfx[strlen (pfx) - 1] != '\\')) |
1956 | needed++; | 1958 | needed++; |
1957 | va_start (ap, serviceName); | 1959 | va_start (ap, service_name); |
1958 | while (1) | 1960 | while (1) |
1959 | { | 1961 | { |
1960 | c = va_arg (ap, const char *); | 1962 | c = va_arg (ap, const char *); |
@@ -1969,7 +1971,7 @@ GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1969 | ret = GNUNET_malloc (needed); | 1971 | ret = GNUNET_malloc (needed); |
1970 | strcpy (ret, pfx); | 1972 | strcpy (ret, pfx); |
1971 | GNUNET_free (pfx); | 1973 | GNUNET_free (pfx); |
1972 | va_start (ap, serviceName); | 1974 | va_start (ap, service_name); |
1973 | while (1) | 1975 | while (1) |
1974 | { | 1976 | { |
1975 | c = va_arg (ap, const char *); | 1977 | c = va_arg (ap, const char *); |