[Anet-checkins] CVS: ANet/ANet_Daemon/Linux Files.c,NONE,1.1 FilesSpecific.h,1.1,1.2
Status: Abandoned
Brought to you by:
benad
From: Benoit N. <be...@us...> - 2001-12-18 01:16:32
|
Update of /cvsroot/anet/ANet/ANet_Daemon/Linux In directory usw-pr-cvs1:/tmp/cvs-serv15311/ANet/ANet_Daemon/Linux Modified Files: FilesSpecific.h Added Files: Files.c Log Message: "" --- NEW FILE: Files.c --- /****************************************************************** ANet_Daemon/Linux/Files.c Code for file management in the ANet deamon. This code is specific to Linux. Part of the run-time wrapper of the ANet project. Distributed under GPL: http://www.gnu.org/copyleft/gpl.html ******************************************************************/ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> #include "Files.h" /*! \addtogroup files \{ */ /*! \file \brief Linux-specific code for the File Management Wrappers. \author Chyrag */ ANetFile ANetInitFile(void) { ANetFile f; f.busy = FALSE; f.open = FALSE; f.async = TRUE; f.path = NULL; return f; } UInt32 ANetGetSetFilePath(ANetFile *f, ANetMemoryTag path, UInt8 set) { int len; if (!f) return 2; // ? if (f->busy) return 60; if (f->open) return 4; if (set) { len = strlen(path); f->path = malloc(len + 1); if (!f->path) return 5; else { FILE * fp; strncpy(f->path, path, len); fp = fopen(f->path, "w"); // is there any better way to create a file? fclose(fp); return 0; } } else { //doubts } return 0; // ?? } UInt32 ANetGetSetFileAsync(ANetFile *f, UInt8 *async, UInt8 set) { if (!async) return 1; if (f->busy) return 60; if (set) { if (f->busy) return 60; if (f->async && *async) return 0; if (!(f->async || *async)) return 0; close(f->fd); if (*async) f->fd = open(f->path, O_RDWR | O_APPEND); else f->fd = open(f->path, O_RDWR | O_APPEND | O_SYNC); if (f->fd < 0) return -1; // open failed } else *async = f->async; return 0; } UInt8 ANetIsFileBusy(ANetFile * f) { return f->busy; } UInt32 ANetGetFileSize(ANetFile *f, UInt32 *size) { struct stat statbuf; extern int errno; if (f->busy) return 60; if (!size) return 3; if (stat(f->path, &statbuf) < 0) { switch(errno) { case ENOENT: return 2; default: return 1; } } *size = statbuf.st_size; return 0; } UInt32 ANetOpenFile(ANetFile *f) { if (f->busy) return 60; if (f->open) return 2; // this is not part of the doc if (f->async) f->fd = open(f->path, O_RDWR | O_APPEND); else f->fd = open(f->path, O_RDWR | O_APPEND | O_SYNC); if (f->fd < 0) return 1; return 0; } UInt32 ANetCloseFile(ANetFile *f) { if (f->busy) return 60; if (close(f->fd) < 0) return 1; return 0; } UInt32 ANetReadFile(ANetFile *f, UInt32 startPos, UInt32 length, ANetMemoryTag buffer, UInt32 *read) { return 0; } UInt32 ANetWriteFile(ANetFile *f, ANetMemoryTag buffer); UInt32 ANetWriteFileAt(ANetFile *f, ANetMemoryTag buffer, UInt32 pos); UInt32 ANetDeleteFile(ANetFile *f); UInt32 ANetCopyFile(ANetFile *source, ANetFile *dest); /*! \} */ Index: FilesSpecific.h =================================================================== RCS file: /cvsroot/anet/ANet/ANet_Daemon/Linux/FilesSpecific.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FilesSpecific.h 2001/12/04 00:45:46 1.1 --- FilesSpecific.h 2001/12/18 01:16:29 1.2 *************** *** 14,22 **** #define ANET_FILES_SPECIFIC typedef struct { ! //... ! UInt8 busy; ! UInt8 async; } ANetFile; #endif --- 14,46 ---- #define ANET_FILES_SPECIFIC + /*! + \addtogroup files + \{ + */ + + /*! + \file + \brief Linux-specific declarations for the File Management Wrappers + \author Benad + \author Chyrag + */ + + /*! + \brief A cross-platform file identifier. + + This is an "opaque" type that represents a file. It can be changed only through the functions described by this document. The data contained in the type contains all necessary information about the file and its state. If the file is closed, you can safely save to any long-term medium (hard disk, another computer...) the data contained in <CODE>ANetFile</CODE> and re-use the data later, even after a reboot. + You can get the size of the ANetFile data structure with the sizeof operator: + \verbatim + sizeof(ANetFile)\endverbatim + */ typedef struct { ! boolean busy; //!< busy flag ! boolean open; //!< open flag ! boolean async; //!< async flag ! unsigned char * path; //!< path to the file ! int fd; //!< the file descriptor } ANetFile; #endif + + /*! \} */ |