UNIX file locking

This is a discussion on UNIX file locking within the C Programming forums, part of the General Programming Boards category; Hello, guys! Sorry my bad english I use a small txt base in file, write there and read (strings), size ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    1

    Question UNIX file locking

    Hello, guys! Sorry my bad english
    I use a small txt base in file, write there and read (strings), size its is changed constantly, as i can install locking for reading or for writing?
    if i use
    Code:
    fcntl.h
    ssize_t read(int fd, void *buf, size_t count);
    ssize_t write(int fd, const void *buf, size_t count);
    when i will read the file, as i will know what size of *buf i will take? Or there is more flexible ways?

    Thanks...

  2. #2
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    >can install locking for reading or for writing?
    You can use locks on your file for both read as well as write mode. See help on functions like: lockf(), flock(), ...

    >what size of *buf i will take?
    You cannot do it while reading itself, instead, if you are sure there are only fixed number of bytes to be read, you can hard-code. Else, read byte-by-byte until EOF is reached, the most flexible way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21