source: libcf/trunk/src/cf_file.c@ 4

Last change on this file since 4 was 4, checked in by cheese, 11 years ago

#1 로깅을 제외한 기본 코드 커밋

File size: 1.2 KB
Line 
1/**
2 * cf_file.c
3 */
4#include "cf_file.h"
5
6#ifdef _WIN32
7# include <io.h>
8#else // #ifdef _WIN32
9# include <unistd.h>
10#endif // #ifdef _WIN32
11
12int
13CF_File_Open (const char * path,
14 const int flag)
15{
16 int result = open (path, flag, 0);
17
18 if (result < 0)
19 return CF_ERROR_FILE_OPEN;
20
21 return result;
22}
23
24int
25CF_File_Create (const char * path)
26{
27 int result = open (path, O_CREAT | O_WRONLY | O_TRUNC, 0);
28
29 if (result < 0)
30 return CF_ERROR_FILE_CREATE;
31
32 return result;
33}
34
35int
36CF_File_Close (const int fd)
37{
38 int result = 0;
39
40 if (fd < 0)
41 return CF_ERROR_FILE_INVALID_ARGS;
42
43 result = close (fd);
44
45 if (result < 0)
46 return CF_ERROR_FILE_CLOSE;
47
48 return CF_OK;
49}
50
51int
52CF_File_Read (const int fd,
53 void * buf,
54 const size_t len)
55{
56 int result = (int) read (fd, buf, len);
57
58 if (result < 0)
59 return CF_ERROR_FILE_READ;
60
61 return CF_OK;
62}
63
64int
65CF_File_Write (const int fd,
66 const void * buf,
67 const size_t len)
68{
69 int result = (int) write (fd, buf, len);
70
71 if (result != len)
72 return CF_ERROR_FILE_WRITE;
73
74 return CF_OK;
75}
76
77int
78CF_File_GetSize (const int fd)
79{
80 int result = (int) lseek (fd, 0, SEEK_END);
81
82 if (result < 0 || lseek (fd, 0, SEEK_SET) < 0)
83 return CF_ERROR_FILE_GET_SIZE;
84
85 return result;
86}
Note: See TracBrowser for help on using the repository browser.