Changeset 94 in libcf


Ignore:
Timestamp:
05/25/13 22:36:56 (11 years ago)
Author:
cheese
Message:

#1 change interface to get file size

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/cf_file.h

    r90 r94  
    4949
    5050CF_EXPORT int
    51 CF_File_GetSize         (const int fd);
     51CF_File_GetSize         (const char * path);
    5252
    5353CF_EXPORT int
  • trunk/src/cf_file.c

    r93 r94  
    198198 */
    199199int
    200 CF_File_GetSize (const int fd)
    201 {
    202     int result = 0;
    203 
    204     ASSERT_ARGS (fd < 0);
    205 
    206     result = (int) lseek (fd, 0, SEEK_END);
    207     if (result < 0 || lseek (fd, 0, SEEK_SET) < 0)
     200CF_File_GetSize (const char * path)
     201{
     202    int length = 0;
     203    int fd = 0;
     204
     205    ASSERT_ARGS (path == NULL);
     206
     207    fd = CF_File_Open (path, CF_FILE_READ);
     208    if (fd < 0)
     209        return CF_ERROR_FILE_OPEN;
     210
     211    length = (int) lseek (fd, 0, SEEK_END);
     212    if (length < 0)
    208213        return CF_ERROR_FILE_GET_SIZE;
    209214
    210     return result;
     215    CF_File_Close (fd);
     216
     217    return length;
    211218}
    212219
  • trunk/test/file.c

    r86 r94  
    3434        // error
    3535    }
    36     printf ("file size : %d\n", CF_File_GetSize (fd));
     36    printf ("file size : %d\n", CF_File_GetSize (name));
    3737    if (CF_File_Read (fd, buffer, sizeof (buffer)) < 0) {
    3838        // error
  • trunk/test/test.c

    r90 r94  
    185185                                    "-- %d bytes of %d bytes\n",
    186186                                    sizeof (buffer),
    187                                     CF_File_GetSize (fd));
     187                                    CF_File_GetSize (file));
    188188
    189189    CF_File_Close (fd);
Note: See TracChangeset for help on using the changeset viewer.