source: libcf/trunk/include/cf_file.h@ 34

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

#1 add example code for doxygen

File size: 3.0 KB
Line 
1/**
2 * @file cf_file.h
3 * @author myusgun <myusgun@gmail.com>
4 * @version 0.1
5 *
6 * @section 샘플코드
7 * @code
8
9#include "cf_file.h"
10
11int main (void) {
12 int fd = 0;
13 char *name = "file.txt";
14 char buffer[128] = {0x00,};
15
16 fd = CF_File_Create (name);
17 if (fd < 0) {
18 // error
19 }
20 if (CF_File_Write (fd, "file test", 9) < 0) {
21 // error
22 }
23 CF_File_Close (fd);
24
25 fd = CF_File_Open (name, CF_FILE_RO);
26 if (fd < 0) {
27 // error
28 }
29 printf ("file size : %d\n", CF_File_GetSize (fd));
30 if (CF_File_Read (fd, buffer, sizeof (buffer)) < 0) {
31 // error
32 }
33 CF_File_Close (fd);
34
35 return 0;
36}
37
38 * @endcode
39 */
40#ifndef __CF_FILE_H__
41#define __CF_FILE_H__
42
43#include "cf_base.h"
44#include <fcntl.h>
45
46#define CF_ERROR_FILE_OPEN CF_ERROR_FILE - 1
47#define CF_ERROR_FILE_INVALID_ARGS CF_ERROR_FILE - 2
48#define CF_ERROR_FILE_READ CF_ERROR_FILE - 3
49#define CF_ERROR_FILE_WRITE CF_ERROR_FILE - 4
50#define CF_ERROR_FILE_CREATE CF_ERROR_FILE - 5
51#define CF_ERROR_FILE_CLOSE CF_ERROR_FILE - 6
52#define CF_ERROR_FILE_GET_SIZE CF_ERROR_FILE - 7
53
54/** 파일 열기 옵션 플래그 */
55typedef enum {
56 CF_FILE_RO = O_RDONLY, /**< 읽기 전용 */
57 CF_FILE_WO = O_WRONLY, /**< 쓰기 전용 */
58 CF_FILE_WR = O_RDWR, /**< 읽기/쓰기 */
59 CF_FILE_CR = O_CREAT, /**< 파일이 존재하지 않으면 생성 */
60 CF_FILE_TR = O_TRUNC, /**< 파일이 존재하면 비우기 */
61 CF_FILE_AP = O_APPEND /**< 파일이 존재하면 이어서 쓰기 */
62} E_CF_FILE_FLAG, CF_FILE_FLAG;
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68/**
69 * 파일 열기
70 *
71 * @return 성공 시, 파일 디스크립터; 실패 시, 오류 코드
72 *
73 * @param path 파일 경로
74 * @param flag 파일 열기 플래그
75 *
76 * @see CF_FILE_FLAG
77 */
78CF_EXPORT int
79CF_File_Open (const char * path,
80 const CF_FILE_FLAG flag);
81
82/**
83 * 파일 닫기
84 *
85 * @return 성공 시, CF_OK; 실패 시, 오류 코드
86 *
87 * @param fd 파일 디스크립터
88 */
89CF_EXPORT int
90CF_File_Close (const int fd);
91
92/**
93 * 파일 생성
94 *
95 * @return 성공 시, 파일 디스크립터; 실패 시, 오류 코드
96 *
97 * @param path 파일 경로
98 */
99CF_EXPORT int
100CF_File_Create (const char * path);
101
102/**
103 * 파일 읽기
104 *
105 * @return 성공 시, 읽은 바이트 수; 실패 시, 오류 코드
106 *
107 * @param fd 파일 디스크립터
108 * @param buf 데이터를 저장할 메모리
109 * @param len 데이터를 저장할 메모리의 크기
110 */
111CF_EXPORT int
112CF_File_Read (const int fd,
113 void * buf,
114 const size_t len);
115
116/**
117 * 파일 쓰기
118 *
119 * @return 성공 시, CF_OK; 실패 시, 오류 코드
120 *
121 * @param fd 파일 디스크립터
122 * @param buf 데이터가 저장된 메모리
123 * @param len 쓸 데이터의 길이
124 */
125CF_EXPORT int
126CF_File_Write (const int fd,
127 const void * buf,
128 const size_t len);
129
130/**
131 * 파일 크기 얻기
132 *
133 * @return 성공 시, 파일 크기; 실패 시, 오류 코드
134 *
135 * @param fd 파일 디스크립터
136 */
137CF_EXPORT int
138CF_File_GetSize (const int fd);
139
140#ifdef __cplusplus
141}
142#endif
143
144#endif // #ifndef __CF_FILE_H__
Note: See TracBrowser for help on using the repository browser.