FileUtils.h

Go to the documentation of this file.
00001 
00021 #ifndef HYPERTABLE_FDUTILS_H
00022 #define HYPERTABLE_FDUTILS_H
00023 
00024 extern "C" {
00025 #include <sys/socket.h>
00026 #include <sys/types.h>
00027 }
00028 #include "Common/String.h"
00029 
00030 namespace Hypertable {
00031 
00032   class FileUtils {
00033 
00034   public:
00035     static ssize_t read(const String &fname, String &contents);
00036     static ssize_t read(int fd, void *vptr, size_t n);
00037     static ssize_t pread(int fd, void *vptr, size_t n, off_t offset);
00038     static ssize_t write(const String &fname, String &contents);
00039     static ssize_t write(int fd, const void *vptr, size_t n);
00040     static ssize_t writev(int fd, const struct iovec *vector, int count);
00041     static ssize_t sendto(int fd, const void *vptr, size_t n,
00042                           const sockaddr *to, socklen_t tolen);
00043     static ssize_t send(int fd, const void *vptr, size_t n);
00044     static ssize_t recvfrom(int fd, void *vptr, size_t n,
00045                             struct sockaddr *from, socklen_t *fromlen);
00046     static ssize_t recv(int fd, void *vptr, size_t n);
00047     static void set_flags(int fd, int flags);
00048     static char *file_to_buffer(const String &fname, off_t *lenp);
00049     static String file_to_string(const String &fname);
00050     static bool mkdirs(const String &dirname);
00051     static bool exists(const String &fname);
00052     static bool unlink(const String &fname);
00053     static bool rename(const String &oldpath, const String &newpath);
00054     static uint64_t size(const String &fname);
00055     static off_t length(const String &fname);
00056     static void add_trailing_slash(String &path);
00057     static bool expand_tilde(String &fname);
00058 #ifdef HT_XATTR_ENABLED
00059     static int
00060     getxattr(const String &path, const String &name, void *value, size_t size);
00061     static int fgetxattr(int fd, const String &name, void *value, size_t size);
00062     static int
00063     setxattr(const String &path, const String &name, const void *value,
00064              size_t size, int flags);
00065     static int
00066     fsetxattr(int fd, const String &name, const void *value, size_t size,
00067               int flags);
00068     static int removexattr(const String &path, const String &name);
00069     static int fremovexattr(int fd, const String &name);
00070 #endif
00071   };
00072 
00073 }
00074 
00075 #endif // HYPERTABLE_FDUITLS_H
00076