Last change
on this file since 5 was 5, checked in by cheese, 11 years ago |
#1 add windows project and fix build compatibility
|
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 | # include <stdio.h>
|
---|
9 | #else // #ifdef _WIN32
|
---|
10 | # include <unistd.h>
|
---|
11 | #endif // #ifdef _WIN32
|
---|
12 |
|
---|
13 | int
|
---|
14 | CF_File_Open (const char * path,
|
---|
15 | const int flag)
|
---|
16 | {
|
---|
17 | int result = open (path, flag, 0);
|
---|
18 |
|
---|
19 | if (result < 0)
|
---|
20 | return CF_ERROR_FILE_OPEN;
|
---|
21 |
|
---|
22 | return result;
|
---|
23 | }
|
---|
24 |
|
---|
25 | int
|
---|
26 | CF_File_Create (const char * path)
|
---|
27 | {
|
---|
28 | int result = open (path, O_CREAT | O_WRONLY | O_TRUNC, 0);
|
---|
29 |
|
---|
30 | if (result < 0)
|
---|
31 | return CF_ERROR_FILE_CREATE;
|
---|
32 |
|
---|
33 | return result;
|
---|
34 | }
|
---|
35 |
|
---|
36 | int
|
---|
37 | CF_File_Close (const int fd)
|
---|
38 | {
|
---|
39 | int result = 0;
|
---|
40 |
|
---|
41 | if (fd < 0)
|
---|
42 | return CF_ERROR_FILE_INVALID_ARGS;
|
---|
43 |
|
---|
44 | result = close (fd);
|
---|
45 |
|
---|
46 | if (result < 0)
|
---|
47 | return CF_ERROR_FILE_CLOSE;
|
---|
48 |
|
---|
49 | return CF_OK;
|
---|
50 | }
|
---|
51 |
|
---|
52 | int
|
---|
53 | CF_File_Read (const int fd,
|
---|
54 | void * buf,
|
---|
55 | const size_t len)
|
---|
56 | {
|
---|
57 | int result = (int) read (fd, buf, len);
|
---|
58 |
|
---|
59 | if (result < 0)
|
---|
60 | return CF_ERROR_FILE_READ;
|
---|
61 |
|
---|
62 | return CF_OK;
|
---|
63 | }
|
---|
64 |
|
---|
65 | int
|
---|
66 | CF_File_Write (const int fd,
|
---|
67 | const void * buf,
|
---|
68 | const size_t len)
|
---|
69 | {
|
---|
70 | int result = (int) write (fd, buf, len);
|
---|
71 |
|
---|
72 | if (result != len)
|
---|
73 | return CF_ERROR_FILE_WRITE;
|
---|
74 |
|
---|
75 | return CF_OK;
|
---|
76 | }
|
---|
77 |
|
---|
78 | int
|
---|
79 | CF_File_GetSize (const int fd)
|
---|
80 | {
|
---|
81 | int result = (int) lseek (fd, 0, SEEK_END);
|
---|
82 |
|
---|
83 | if (result < 0 || lseek (fd, 0, SEEK_SET) < 0)
|
---|
84 | return CF_ERROR_FILE_GET_SIZE;
|
---|
85 |
|
---|
86 | return result;
|
---|
87 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.