Changeset 41 in libcf for trunk/src/cf_file.c


Ignore:
Timestamp:
02/07/13 10:18:02 (11 years ago)
Author:
cheese
Message:

#1 add function to make directory and update file test code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cf_file.c

    r40 r41  
    77#include "cf_error.h"
    88
     9#include <stdio.h>
     10#include <errno.h>
     11#include <sys/stat.h>
     12
    913#ifdef _WIN32
    10 # include <stdio.h>
    1114# include <io.h>
    12 # include <sys/stat.h>
    13 
     15# include <direct.h>
     16
     17# define DELIMITER      '\\'
     18# define mkdir(a,b)     _mkdir (a)
     19# define access(a,b)    _access (a,b)
     20
     21/*------------------------------*/
    1422# define S_IWUSR        _S_IWRITE
    1523# define S_IRUSR        _S_IREAD
    1624# define S_IXUSR        _S_IEXEC
     25/*------------------------------*/
    1726# define S_IRGRP        0x00000000
    1827# define S_IWGRP        0x00000000
    1928# define S_IXGRP        0x00000000
     29/*------------------------------*/
    2030# define S_IROTH        0x00000000
    2131# define S_IWOTH        0x00000000
    2232# define S_IXOTH        0x00000000
     33/*------------------------------*/
     34# define S_IRWXU        0x00000000
    2335#else // #ifdef _WIN32
    2436# include <unistd.h>
     37
     38# define DELIMITER      '/'
    2539# define O_BINARY       0x00000000
    2640#endif // #ifdef _WIN32
    2741
    28 #define FILE_MODE       S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH
     42#define DIRECTORY_MODE  S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH
     43#define FILE_MODE       S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH
    2944
    3045/**
     
    5570 * @return 성공 시, 파일 디스크립터; 실패 시, 오류 코드
    5671 *
    57  * @param path  파일 경로
     72 * @param path 파일 경로
    5873 */
    5974int
     
    140155 * @return 성공 시, 파일 크기; 실패 시, 오류 코드
    141156 *
    142  * @param fd    파일 디스크립터
     157 * @param fd 파일 디스크립터
    143158 */
    144159int
     
    152167    return result;
    153168}
     169
     170/**
     171 * 디렉터리 생성
     172 *
     173 * @return 성공 시, CF_OK; 실패 시, 오류 코드
     174 *
     175 * @param path 생성할 디렉터리 경로
     176 */
     177int
     178CF_File_MakeDirectory (const char * path)
     179{
     180    int     result = 0;
     181    char    fullPath[1024] = {0x00,};
     182    char    stepPath[256] = {0x00,};
     183
     184    char    * f = fullPath;
     185    char    * d = stepPath;
     186
     187    sprintf (fullPath, "%s%c", path, DELIMITER);
     188
     189    for (*d++ = *f++ ; *f ; *d++ = *f++)
     190    {
     191        if (*f != DELIMITER)
     192            continue;
     193
     194        if (access (stepPath, F_OK) == 0)
     195            continue;
     196
     197        result = mkdir (stepPath, DIRECTORY_MODE);
     198        if (result && errno != EEXIST)
     199            return CF_ERROR_FILE_MAKE_DIRECTORY;
     200    }
     201
     202    return CF_OK;
     203}
Note: See TracChangeset for help on using the changeset viewer.