[ANet-devel] Re: doxygen for low-level design
Status: Abandoned
Brought to you by:
benad
|
From: Chirag K. <ch...@ya...> - 2001-12-17 14:25:08
|
On Thu, Dec 13, 2001 at 12:26:01PM +0530, Chirag Kantharia wrote:
| In process of writing code for the fileI/O stuff, I've got lot of doubts
| but I'm saving it all up. I'll send in a huge mail soon, after I finish
| most of it or the mail gets very big.
Hi Benad,
I've taken liberty of defining few things which, hopefully, will not
clash with anything else.
typedef char boolean;
typedef unsigned int UInt32;
typedef unsigned char UInt8;
typedef char * ANetMemoryTag;
#define FALSE 0
#define TRUE 1
typedef struct {
/* busy flag */
boolean busy;
/* open flag */
boolean open;
/* async flag */
boolean async;
/* path to the file */
unsigned char * path;
/* file descriptor */
int fd;
} ANetFile; /* this is for time being; as I proceed with coding, I would
be adding more members */
I've got a few doubts:
1. ANetGetSetFilePath(ANetFile * f, ANetMemoryTag path, UInt8 set)
If the 'set' variable is set ie. it's non zero, then I understand that I
have to set the path of the file 'f' ie. f->path to the string pointed
to by variable path. One can malloc the memory required for storing the
string pointed to by path and copy the path. So far, so good. Now, if
the set variable is not set, ie, the function is used to get the file's
path in the memory location pointed to by path variable.
Here do I assume that the path will be pre-malloc'ed or do I malloc the
memory required for storing the path?
I need to return 3, if `path is invalid or not big enough'. This
indicates that the path is pre-allocated. There is no way to find out
size of a malloc'ed pointer in ANSI C, AFAIK. Under the circumstances, I
am not sure, how would I be able to return error, if the path is not big
enough. I suggest, that we malloc the memory required for path variable
in the function itself.
When do I actually create the file? I can't do that in ANetInitFile(),
since that time, the path of the file is not decided upon. I can do that
in ANetGetSetFilePath(). This I'm doing currently. If there are any
other thoughts on this, please let me know. There's another option of
``creating'' the file in ANetOpenFile(). To be on the safer side, I'm
opening the files in O_RDWR | O_APPEND mode (ie. read, write and append
mode). (I think that opening in O_APPEND mode, will cause the file
pointer to be at the end of the file, which would need to be reset to
the beginning so that it can read stuff correctly).
2. ANetGetSetFileAsync(ANetFile *f, UInt8 *async, UInt8 set)
I don't think ANSI C has any function call which will have this
functionality. By default, the native open() on Linux, opens the file
for asynchronous writing. For setting it to synchronous writing, ie.
subsequent writes will block the calling piece of code, until the data
is written to the disk, the file will have to be closed and reopened
with different mode. Let me know if this is ok.
Actually, I thought this might turn out to be a long mail. But the
succeeding functions (all are not done), I didn't find much problem.
The attached is file.h and file.c (and Makefile). The code isn't
documented doxygen style - I'm sorry for that. Felt very lazy to rewrite
the comments.
I haven't implemented all the functions as yet. Just thought of sending
whatever I've done so far, to keep -devel list busy.
PS: benad, can you change my homepage in CONTRIB to symonds.net/~chyrag/?
chyrag.
--
Chirag Kantharia, symonds.net/~chyrag/
|