david wrote:
> I've just discovered that 'open' returns a new descriptor (new_fd)
> when you open a file several times and that
> fcntl( new_fd, F_SETLK ... and fcntl( new_fd, F_GETLK ...
> won't see if the file was already locked :
> You can get several exclusive locks by opening a file
> several times and using fcntl( new_fd, F_SETLK
> ( it looks strange to me ???).
Yep. Locking a file only prevents *other* processes from obtaining a
conflicting lock. An individual process can lock the same region of a
file repeatedly.
> So how do you check if a file has already been opened by the same
> process (without maintaining a list of opened files) ?
Keep track of which files you've opened. If you want to avoid problems
with aliases due to symlinks, use fstat() on the descriptors and keep
track of the device/inode pairs which you have open.
> Just another little question :
> do the following code work everywhere :
> char *p;
> p = malloc( 10);
> p += 4;
> free( p);
No. The argument to free() should be a pointer which was previously
returned from malloc(), calloc() or realloc(). The behaviour when
passing any other value is undefined.
--
Glynn Clements <[EMAIL PROTECTED]>