1 /******************************************************************************
5 ** This file is part of the ABYSS Web server project.
7 ** Copyright (C) 2000 by Moez Mahfoudh <mmoez@bigfoot.com>.
8 ** All rights reserved.
10 ** Redistribution and use in source and binary forms, with or without
11 ** modification, are permitted provided that the following conditions
13 ** 1. Redistributions of source code must retain the above copyright
14 ** notice, this list of conditions and the following disclaimer.
15 ** 2. Redistributions in binary form must reproduce the above copyright
16 ** notice, this list of conditions and the following disclaimer in the
17 ** documentation and/or other materials provided with the distribution.
18 ** 3. The name of the author may not be used to endorse or promote products
19 ** derived from this software without specific prior written permission.
21 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 ******************************************************************************/
46 #include "xmlrpc-c/abyss.h"
49 /*********************************************************************
51 *********************************************************************/
53 abyss_bool FileOpen(TFile *f, const char *name,uint32_t attrib)
55 #if defined( WIN32 ) && !defined( __BORLANDC__ )
56 return ((*f=_open(name,attrib))!=(-1));
58 return ((*f=open(name,attrib))!=(-1));
62 abyss_bool FileOpenCreate(TFile *f, const char *name, uint32_t attrib)
64 #if defined( WIN32 ) && !defined( __BORLANDC__ )
65 return ((*f=_open(name,attrib | O_CREAT,_S_IWRITE | _S_IREAD))!=(-1));
67 return ((*f=open(name,attrib | O_CREAT,S_IWRITE | S_IREAD))!=(-1));
72 FileWrite(TFile * const f,
73 const void * const buffer,
75 #if defined( WIN32 ) && !defined( __BORLANDC__ )
76 return (_write(*f,buffer,len)==(int32_t)len);
78 return (write(*f,buffer,len)==(int32_t)len);
82 int32_t FileRead(TFile *f, void *buffer, uint32_t len)
84 #if defined( WIN32 ) && !defined( __BORLANDC__ )
85 return (_read(*f,buffer,len));
87 return (read(*f,buffer,len));
91 abyss_bool FileSeek(TFile *f, uint64_t pos, uint32_t attrib)
93 #if defined( WIN32 ) && !defined( __BORLANDC__ )
94 return (_lseek(*f,pos,attrib)!=(-1));
96 return (lseek(*f,pos,attrib)!=(-1));
100 uint64_t FileSize(TFile *f)
102 #if defined( WIN32 ) && !defined( __BORLANDC__ )
103 return (_filelength(*f));
112 abyss_bool FileClose(TFile *f)
114 #if defined( WIN32 ) && !defined( __BORLANDC__ )
115 return (_close(*f)!=(-1));
117 return (close(*f)!=(-1));
124 FileStat(const char * const filename,
125 TFileStat * const filestat) {
126 #if defined( WIN32 ) && !defined( __BORLANDC__ )
127 return (_stati64(filename,filestat)!=(-1));
129 return (stat(filename,filestat)!=(-1));
136 FileFindFirst(TFileFind * const filefind,
137 const char * const path,
138 TFileInfo * const fileinfo) {
141 char *p=path+strlen(path);
147 ret=(((*filefind)=_findfirst(path,fileinfo))!=(-1));
149 *filefind = FindFirstFile( path, &fileinfo->data );
150 ret = *filefind != NULL;
154 li.LowPart = fileinfo->data.nFileSizeLow;
155 li.HighPart = fileinfo->data.nFileSizeHigh;
156 strcpy( fileinfo->name, fileinfo->data.cFileName );
157 fileinfo->attrib = fileinfo->data.dwFileAttributes;
158 fileinfo->size = li.QuadPart;
159 fileinfo->time_write = fileinfo->data.ftLastWriteTime.dwLowDateTime;
165 strncpy(filefind->path,path,NAME_MAX);
166 filefind->path[NAME_MAX]='\0';
167 filefind->handle=opendir(path);
168 if (filefind->handle)
169 return FileFindNext(filefind,fileinfo);
177 abyss_bool FileFindNext(TFileFind *filefind,TFileInfo *fileinfo)
182 return (_findnext(*filefind,fileinfo)!=(-1));
184 abyss_bool ret = FindNextFile( *filefind, &fileinfo->data );
188 li.LowPart = fileinfo->data.nFileSizeLow;
189 li.HighPart = fileinfo->data.nFileSizeHigh;
190 strcpy( fileinfo->name, fileinfo->data.cFileName );
191 fileinfo->attrib = fileinfo->data.dwFileAttributes;
192 fileinfo->size = li.QuadPart;
193 fileinfo->time_write = fileinfo->data.ftLastWriteTime.dwLowDateTime;
200 /****** Must be changed ***/
203 de=readdir(filefind->handle);
208 strcpy(fileinfo->name,de->d_name);
209 strcpy(z,filefind->path);
210 strncat(z,"/",NAME_MAX);
211 strncat(z,fileinfo->name,NAME_MAX);
216 if (fs.st_mode & S_IFDIR)
217 fileinfo->attrib=A_SUBDIR;
221 fileinfo->size=fs.st_size;
222 fileinfo->time_write=fs.st_mtime;
231 void FileFindClose(TFileFind *filefind)
236 _findclose(*filefind);
238 FindClose( *filefind );
242 closedir(filefind->handle);