00001 /** @file include/dmlite/c/io.h 00002 * @brief C wrapper for I/O interfaces. 00003 * @author Alejandro Álvarez Ayllon <aalvarez@cern.ch> 00004 */ 00005 #ifndef DMLITE_IO_H 00006 #define DMLITE_IO_H 00007 00008 #include "any.h" 00009 #include "dmlite.h" 00010 00011 #ifdef __cplusplus 00012 extern "C" { 00013 #endif 00014 00015 /** Handle for a file descriptor. */ 00016 typedef struct dmlite_fd dmlite_fd; 00017 00018 /** 00019 * @brief Opens a file. 00020 * @param context The DM context. 00021 * @param path The path to open. 00022 * @param flags See open() 00023 * @param extra The key-value pairs. 00024 * @return An opaque handler for the file, NULL on failure. 00025 */ 00026 dmlite_fd* dmlite_fopen(dmlite_context* context, const char* path, int flags, 00027 const dmlite_any_dict* extra); 00028 00029 /** 00030 * @brief Closes a file. 00031 * @param fd The file descriptor as returned by dmlite_open. 00032 * @return 0 on sucess, error code otherwise. 00033 */ 00034 int dmlite_fclose(dmlite_fd* fd); 00035 00036 /** 00037 * @brief Sets the file position. 00038 * @param fd The file descriptor. 00039 * @param offset The offset. 00040 * @param whence See fseek() 00041 * @return 0 on sucess, error code otherwise. 00042 */ 00043 int dmlite_fseek(dmlite_fd* fd, long offset, int whence); 00044 00045 /** 00046 * @brief Returns the cursor position. 00047 * @param fd The file descriptor. 00048 * @return The cursor position, or -1 on error. 00049 */ 00050 long dmlite_ftell(dmlite_fd* fd); 00051 00052 /** 00053 * @brief Reads from a file. 00054 * @param fd The file descriptor. 00055 * @param buffer Where to put the data. 00056 * @param count Number of bytes to read. 00057 * @return Number of bytes actually read on success. -1 on failure. 00058 */ 00059 size_t dmlite_fread(dmlite_fd* fd, void* buffer, size_t count); 00060 00061 /** 00062 * @brief Writes to a file. 00063 * @param fd The file descriptor. 00064 * @param buffer A pointer to the data. 00065 * @param count Number of bytes to write. 00066 * @return Number of bytes actually written. -1 on failure. 00067 */ 00068 size_t dmlite_fwrite(dmlite_fd* fd, const void* buffer, size_t count); 00069 00070 /** 00071 * @brief Returns 1 if EOF. 00072 * @param fd The file descriptor. 00073 * @return 0 if there is more to read. 1 if EOF. 00074 */ 00075 int dmlite_feof(dmlite_fd* fd); 00076 00077 /** 00078 * @brief Finishes a PUT. 00079 * @param context The DM context. 00080 * @param pfn The replica file name. 00081 * @param extra The extra parameters as returned by dmlite_put. 00082 * @return 0 on success, error code otherwise. 00083 */ 00084 int dmlite_donewriting(dmlite_context* context, 00085 const char* pfn, 00086 const dmlite_any_dict* extra); 00087 00088 #ifdef __cplusplus 00089 } 00090 #endif 00091 00092 #endif /* DMLITE_IO_H */