FP F_Create(char* fileName, FT* pOpentype)

{

int type = 0x8000;

FP file_point;


if (pOpentype == "b")

type = 0x8000;

else if (pOpentype == "t")

type = 0x4000;


file_point = _open(fileName, _O_CREAT | _O_TRUNC | type, S_IWRITE);

if (file_point == -1)

{

cout << "파일을 생성할 수 없거나, 이미 파일이 존재합니다.\n";

return NULL;

}

return file_point;

}


FP Open(char* fileName, char* pOpentype)

{

int type = 0x8000;

FP file_point;


if (pOpentype == "b")

type = 0x8000;

else if (pOpentype == "t")

type = 0x4000;


file_point = _open(fileName, _O_RDWR | type);

if (file_point == -1)

{

cout << "파일이 없거나, 열 수가 없습니다.\n";


return NULL;

}


return file_point;

}


FP Write(FP file_point, BYTE* buffer, size_t nBufferSize)

{

if (file_point == -1)

{

cout << "파일이 없거나, 쓸 수가 없습니다.\n";


return NULL;

}


_write(file_point, buffer, nBufferSize);


return file_point;

}


BYTE* Read(FP file_point, BYTE* buffer, size_t nBufferSize)

{

int length = 0;


if (file_point == -1)

{

cout << "파일이 없거나, 읽을 수가 없습니다.\n";

_close(file_point);


return NULL;

}


length = _read(file_point, buffer, nBufferSize);


if (length == 0)

{

cout << "파일에 저장된 내용이 없습니다..\n";

return NULL;

}

buffer[length] = '\0';


return buffer;

}


void Close(FP file_point)

{

_close(file_point);

}

'[C], [ C++]' 카테고리의 다른 글

함수 오버로딩  (0) 2016.02.18
STL - map 사용 예시 예제  (0) 2015.05.28
함수 포인터 및 함수  (0) 2015.05.28
연산자 오버로딩  (0) 2015.05.28
링크드 리스트(Stack)  (0) 2015.05.28

+ Recent posts