1
/* $Id: file_access_unistd.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#include <pj/file_access.h>
21
#include <pj/assert.h>
24
#include <sys/types.h>
27
#include <stdio.h> /* rename() */
33
PJ_DEF(pj_bool_t) pj_file_exists(const char *filename)
37
PJ_ASSERT_RETURN(filename, 0);
39
if (stat(filename, &buf) != 0)
49
PJ_DEF(pj_off_t) pj_file_size(const char *filename)
53
PJ_ASSERT_RETURN(filename, -1);
55
if (stat(filename, &buf) != 0)
65
PJ_DEF(pj_status_t) pj_file_delete(const char *filename)
67
PJ_ASSERT_RETURN(filename, PJ_EINVAL);
69
if (unlink(filename)!=0) {
70
return PJ_RETURN_OS_ERROR(errno);
79
PJ_DEF(pj_status_t) pj_file_move( const char *oldname, const char *newname)
81
PJ_ASSERT_RETURN(oldname && newname, PJ_EINVAL);
83
if (rename(oldname, newname) != 0) {
84
return PJ_RETURN_OS_ERROR(errno);
93
PJ_DEF(pj_status_t) pj_file_getstat(const char *filename,
94
pj_file_stat *statbuf)
98
PJ_ASSERT_RETURN(filename && statbuf, PJ_EINVAL);
100
if (stat(filename, &buf) != 0) {
101
return PJ_RETURN_OS_ERROR(errno);
104
statbuf->size = buf.st_size;
105
statbuf->ctime.sec = buf.st_ctime;
106
statbuf->ctime.msec = 0;
107
statbuf->mtime.sec = buf.st_mtime;
108
statbuf->mtime.msec = 0;
109
statbuf->atime.sec = buf.st_atime;
110
statbuf->atime.msec = 0;