summaryrefslogtreecommitdiff
path: root/pjlib/src/pj/file_access_unistd.c
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2005-11-07 18:14:08 +0000
committerBenny Prijono <bennylp@teluu.com>2005-11-07 18:14:08 +0000
commit8b3f0c56c5c885134f3865539a7257a7ebb90387 (patch)
tree0388183e5ca1c7973c0b830bdbd0bedd58a9c315 /pjlib/src/pj/file_access_unistd.c
parente25a988d098a075f5519090c24237c3b97bc1323 (diff)
UDP echo testing in Linux
git-svn-id: http://svn.pjsip.org/repos/pjproject/main@19 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src/pj/file_access_unistd.c')
-rw-r--r--pjlib/src/pj/file_access_unistd.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/pjlib/src/pj/file_access_unistd.c b/pjlib/src/pj/file_access_unistd.c
new file mode 100644
index 00000000..8e46e0ed
--- /dev/null
+++ b/pjlib/src/pj/file_access_unistd.c
@@ -0,0 +1,96 @@
+/* $Id$ */
+#include <pj/file_access.h>
+#include <pj/assert.h>
+#include <pj/errno.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h> /* rename() */
+#include <errno.h>
+
+/*
+ * pj_file_exists()
+ */
+PJ_DEF(pj_bool_t) pj_file_exists(const char *filename)
+{
+ struct stat buf;
+
+ PJ_ASSERT_RETURN(filename, 0);
+
+ if (stat(filename, &buf) != 0)
+ return 0;
+
+ return PJ_TRUE;
+}
+
+
+/*
+ * pj_file_size()
+ */
+PJ_DEF(pj_off_t) pj_file_size(const char *filename)
+{
+ struct stat buf;
+
+ PJ_ASSERT_RETURN(filename, -1);
+
+ if (stat(filename, &buf) != 0)
+ return -1;
+
+ return buf.st_size;
+}
+
+
+/*
+ * pj_file_delete()
+ */
+PJ_DEF(pj_status_t) pj_file_delete(const char *filename)
+{
+ PJ_ASSERT_RETURN(filename, PJ_EINVAL);
+
+ if (unlink(filename)!=0) {
+ return PJ_RETURN_OS_ERROR(errno);
+ }
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * pj_file_move()
+ */
+PJ_DEF(pj_status_t) pj_file_move( const char *oldname, const char *newname)
+{
+ PJ_ASSERT_RETURN(oldname && newname, PJ_EINVAL);
+
+ if (rename(oldname, newname) != 0) {
+ return PJ_RETURN_OS_ERROR(errno);
+ }
+ return PJ_SUCCESS;
+}
+
+
+/*
+ * pj_file_getstat()
+ */
+PJ_DEF(pj_status_t) pj_file_getstat(const char *filename,
+ pj_file_stat *statbuf)
+{
+ struct stat buf;
+
+ PJ_ASSERT_RETURN(filename && statbuf, PJ_EINVAL);
+
+ if (stat(filename, &buf) != 0) {
+ return PJ_RETURN_OS_ERROR(errno);
+ }
+
+ statbuf->size = buf.st_size;
+ statbuf->ctime.sec = buf.st_ctime;
+ statbuf->ctime.msec = 0;
+ statbuf->mtime.sec = buf.st_mtime;
+ statbuf->mtime.msec = 0;
+ statbuf->atime.sec = buf.st_atime;
+ statbuf->atime.msec = 0;
+
+ return PJ_SUCCESS;
+}
+