]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add two lseek wrappers to compat.[ch]: one to return current fd position, and one...
authorNick Mathewson <nickm@torproject.org>
Tue, 2 Dec 2008 23:26:04 +0000 (23:26 +0000)
committerNick Mathewson <nickm@torproject.org>
Tue, 2 Dec 2008 23:26:04 +0000 (23:26 +0000)
svn:r17454

src/common/compat.c
src/common/compat.h

index 31fbf263e4624c260067daaa05d24f0c3bc8971a..a54fded8334403130f77413fc448795936b25f35 100644 (file)
@@ -581,6 +581,37 @@ tor_lockfile_unlock(tor_lockfile_t *lockfile)
   tor_free(lockfile);
 }
 
+/* Some old versions of unix didn't define constants for these values,
+ * and instead expect you to say 0, 1, or 2. */
+#ifndef SEEK_CUR
+#define SEEK_CUR 1
+#endif
+#ifndef SEEK_END
+#define SEEK_END 2
+#endif
+
+/** Return the position of fd with respect to the start of the file */
+off_t
+tor_fd_getpos(int fd)
+{
+#ifdef WIN32
+  return (off_t) _lseek(fd, 0, SEEK_CUR);
+#else
+  return (off_t) lseek(fd, 0, SEEK_CUR);
+#endif
+}
+
+/** Move fd to the end of the file. Return -1 on error, 0 on success. */
+int
+tor_fd_seekend(int fd)
+{
+#ifdef WIN32
+  return _lseek(fd, 0, SEEK_END) < 0 ? -1 : 0;
+#else
+  return lseek(fd, 0, SEEK_END) < 0 ? -1 : 0;
+#endif
+}
+
 #undef DEBUG_SOCKET_COUNTING
 #ifdef DEBUG_SOCKET_COUNTING
 /** A bitarray of all fds that should be passed to tor_socket_close(). Only
index aab49b208e13ac252a5f8b993dd9b833b6ed1d2f..2002c08dd442bc48dc3fb96d4b2bac31a544df76 100644 (file)
@@ -294,6 +294,9 @@ tor_lockfile_t *tor_lockfile_lock(const char *filename, int blocking,
                                   int *locked_out);
 void tor_lockfile_unlock(tor_lockfile_t *lockfile);
 
+off_t tor_fd_getpos(int fd);
+int tor_fd_seekend(int fd);
+
 #ifdef MS_WINDOWS
 #define PATH_SEPARATOR "\\"
 #else