A newer version of files has been put here, since the old version does not
work with strip.prg. QUESTION : Manuel can overwrite this one once you've finished testing yours ?
This commit is contained in:
@@ -1,52 +1,311 @@
|
||||
/*
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#include <extend.h>
|
||||
|
||||
#if defined(_SO_LINUX)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#if defined(__GNUC__) || defined(__DJGPP__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#include <unistd.h>
|
||||
/* This is ugly, but we are using FOPEN, etc., and those names collide
|
||||
with names in the standard C library. */
|
||||
extern int open _PARAMS ((const char *, int, ...));
|
||||
extern int creat _PARAMS ((const char *, mode_t));
|
||||
#if !defined(HAVE_POSIX_IO)
|
||||
#define HAVE_POSIX_IO
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__WATCOMC__)
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <share.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if !defined(HAVE_POSIX_IO)
|
||||
#define HAVE_POSIX_IO
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#if defined(_SO_DOS)
|
||||
|
||||
#if defined(_CC_DJGPP)
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef __WATCOMC__
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
HARBOUR BIN2I( void );
|
||||
HARBOUR I2BIN( void );
|
||||
#define IT_NUMBER (IT_INTEGER|IT_LONG|IT_DOUBLE)
|
||||
|
||||
static int last_error = 0;
|
||||
|
||||
#if !defined(PATH_MAX)
|
||||
// if PATH_MAX isn't defined, 256 bytes is a good number :)
|
||||
#define PATH_MAX 256
|
||||
#endif
|
||||
|
||||
static char cwd_buff[PATH_MAX+1];
|
||||
|
||||
#define MKLONG(_1,_2,_3,_4) (((long)_4)<<24)|(((long)_3)<<16)|(((long)_2)<<8)|_1
|
||||
#define MKINT(_1,_2) (((long)_2)<<8)|_1
|
||||
#define MKINT(_1,_2) (((long)_2)<<8)|_1
|
||||
|
||||
// FLAGS TO FOPEN
|
||||
#define FO_READ 0
|
||||
#define FO_WRITE 1
|
||||
#define FO_READWRITE 2
|
||||
#define FO_COMPAT 0
|
||||
#define FO_EXCLUSIVE 16
|
||||
#define FO_DENYWRITE 32
|
||||
#define FO_DENYREAD 48
|
||||
#define FO_DENYONE 64
|
||||
#define FO_SHARE FO_DENYONE
|
||||
|
||||
// FLAGS TO FCREATE
|
||||
#define FC_NORMAL 0
|
||||
#define FC_READONLY 1
|
||||
#define FC_HIDDEN 2
|
||||
#define FC_SYSTEM 4
|
||||
|
||||
// FLAGS TO SEEK
|
||||
#define FS_SET 0
|
||||
#define FS_RELATIVE 1
|
||||
#define FS_END 2
|
||||
|
||||
// NOTE: for avoid include stdio.h,
|
||||
// this include define as an 'struct FILE'
|
||||
// and we have a HARBOUR function named FILE() this
|
||||
// made a name conflict
|
||||
extern int rename( const char *, const char * );
|
||||
|
||||
// Convert HARBOUR flags to IO subsystem flags
|
||||
|
||||
static int convert_open_flags( int flags )
|
||||
{
|
||||
// by default FO_READ+FO_COMPAT is set
|
||||
int result_flags = 0;
|
||||
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
|
||||
result_flags |= O_BINARY;
|
||||
|
||||
if( flags == 0 )
|
||||
result_flags |= O_RDONLY|SH_COMPAT;
|
||||
|
||||
// read & write flags
|
||||
if( flags & FO_WRITE )
|
||||
result_flags |= O_WRONLY;
|
||||
|
||||
if( flags & FO_READWRITE )
|
||||
result_flags |= O_RDWR;
|
||||
|
||||
// shared flags
|
||||
if( flags & FO_EXCLUSIVE )
|
||||
result_flags |= SH_DENYRW;
|
||||
|
||||
if( flags & FO_DENYWRITE )
|
||||
result_flags |= SH_DENYWR;
|
||||
|
||||
if( flags & FO_DENYREAD )
|
||||
result_flags |= SH_DENYRD;
|
||||
|
||||
if( flags & FO_DENYONE )
|
||||
result_flags |= SH_DENYNO;
|
||||
|
||||
if( flags & FO_SHARE )
|
||||
result_flags |= SH_DENYNO;
|
||||
|
||||
#endif
|
||||
return result_flags;
|
||||
}
|
||||
|
||||
static int convert_seek_flags( int flags )
|
||||
{
|
||||
// by default FS_SET is set
|
||||
int result_flags=0;
|
||||
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
|
||||
result_flags = SEEK_SET;
|
||||
|
||||
if( flags & FS_RELATIVE )
|
||||
result_flags = SEEK_CUR;
|
||||
|
||||
if( flags & FS_END )
|
||||
result_flags = SEEK_END;
|
||||
|
||||
#endif
|
||||
|
||||
return result_flags;
|
||||
}
|
||||
|
||||
static int convert_create_flags( int flags )
|
||||
{
|
||||
// by default FC_NORMAL is set
|
||||
int result_flags=S_IWUSR;
|
||||
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
|
||||
if( flags & FC_READONLY )
|
||||
result_flags = result_flags & ~(S_IWUSR);
|
||||
|
||||
if( flags & FC_HIDDEN )
|
||||
result_flags |= 0;
|
||||
|
||||
if( flags & FC_SYSTEM )
|
||||
result_flags |= 0;
|
||||
|
||||
#endif
|
||||
|
||||
return result_flags;
|
||||
}
|
||||
|
||||
// FILESYS.API FUNCTIONS --
|
||||
// ------------------------
|
||||
|
||||
int _fsOpen( char * name, int flags )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
return open(name,convert_open_flags(flags));
|
||||
#endif
|
||||
}
|
||||
|
||||
int _fsCreate( char * name, int flags )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
return creat(name,convert_create_flags(flags));
|
||||
#endif
|
||||
}
|
||||
|
||||
void _fsClose( int handle )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
close(handle);
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
long _fsRead( int handle, char * buff, long count )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
return read(handle,buff,count);
|
||||
#endif
|
||||
}
|
||||
|
||||
long _fsWrite( int handle, char * buff, long count )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
return write(handle,buff,count);
|
||||
#endif
|
||||
}
|
||||
|
||||
long _fsSeek( int handle, long offset, int flags )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
return lseek(handle,offset,convert_seek_flags(flags));
|
||||
#endif
|
||||
}
|
||||
|
||||
int _fsError()
|
||||
{
|
||||
return last_error;
|
||||
}
|
||||
|
||||
void _fsDelete( char * name )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
unlink(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
void _fsRename( char * older, char * newer )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
rename(older,newer);
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
int _fsLock( int handle, long start, long length, long mode )
|
||||
{
|
||||
int result=0;
|
||||
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
// TODO: I'm thinking about this :)
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void _fsCommit( int handle )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
// TODO: I'm thinking about this :)
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
int _fsMkDir( char * name )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
return mkdir(name,S_IWUSR|S_IRUSR);
|
||||
#endif
|
||||
}
|
||||
|
||||
int _fsChDir( char * name )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
return chdir(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
int _fsRmDir( char * name )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
return rmdir(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
char * _fsCurDir( int driver )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
getcwd(cwd_buff,PATH_MAX);
|
||||
return cwd_buff;
|
||||
#endif
|
||||
}
|
||||
|
||||
int _fsCurDrv( void )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
long _fsChDrv( int driver )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
long _fsIsDrv( int driver )
|
||||
{
|
||||
#if defined(HAVE_POSIX_IO)
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef NOT_IMPLEMENTED_YET
|
||||
|
||||
// Unknow that it make :( if anyone can say me !!
|
||||
int _fsExtOpen(PBYTE filename, PBYTE defExt, ULONG flags,
|
||||
PBYTE paths, ERRORP error );
|
||||
|
||||
#endif
|
||||
|
||||
// -- HARBOUR FUNCTIONS --
|
||||
// -----------------------
|
||||
|
||||
HARBOUR FOPEN()
|
||||
{
|
||||
PITEM arg1_it = _param(1,IT_STRING);
|
||||
PITEM arg2_it = _param(1,IT_NUMERIC);
|
||||
PITEM arg2_it = _param(2,IT_NUMBER);
|
||||
|
||||
int open_flags;
|
||||
int file_handle = -1;
|
||||
@@ -58,10 +317,7 @@ HARBOUR FOPEN()
|
||||
else
|
||||
open_flags = 0;
|
||||
|
||||
/* TODO: Study equivalence between Clipper Flags & SO Flags
|
||||
they are very so dependent */
|
||||
|
||||
file_handle = open(_parc(1),open_flags);
|
||||
file_handle = _fsOpen(_parc(1),open_flags);
|
||||
last_error = errno;
|
||||
}
|
||||
|
||||
@@ -72,7 +328,7 @@ HARBOUR FOPEN()
|
||||
HARBOUR FCREATE()
|
||||
{
|
||||
PITEM arg1_it = _param(1,IT_STRING);
|
||||
PITEM arg2_it = _param(1,IT_NUMERIC);
|
||||
PITEM arg2_it = _param(2,IT_NUMBER);
|
||||
|
||||
int create_flags;
|
||||
int file_handle = -1;
|
||||
@@ -84,10 +340,7 @@ HARBOUR FCREATE()
|
||||
else
|
||||
create_flags = 0;
|
||||
|
||||
/* TODO: Study equivalence between Clipper Flags & SO Flags
|
||||
they are very so dependent */
|
||||
|
||||
file_handle = creat(_parc(1),create_flags);
|
||||
file_handle = _fsCreate(_parc(1),create_flags);
|
||||
last_error = errno;
|
||||
}
|
||||
|
||||
@@ -97,15 +350,15 @@ HARBOUR FCREATE()
|
||||
|
||||
HARBOUR FREAD()
|
||||
{
|
||||
PITEM arg1_it = _param(1,IT_NUMERIC);
|
||||
PITEM arg2_it = _param(1,IT_STRING+IT_BYREF);
|
||||
PITEM arg3_it = _param(1,IT_NUMERIC);
|
||||
PITEM arg1_it = _param(1,IT_NUMBER);
|
||||
PITEM arg2_it = _param(2,IT_STRING+IT_BYREF);
|
||||
PITEM arg3_it = _param(3,IT_NUMBER);
|
||||
|
||||
long bytes=0;
|
||||
|
||||
if( arg1_it && arg2_it && arg3_it )
|
||||
{
|
||||
bytes = read(_parni(1),_parc(2),_parnl(3));
|
||||
bytes = _fsRead(_parni(1),_parc(2),_parnl(3));
|
||||
last_error = errno;
|
||||
}
|
||||
|
||||
@@ -115,28 +368,31 @@ HARBOUR FREAD()
|
||||
|
||||
HARBOUR FWRITE()
|
||||
{
|
||||
PITEM arg1_it = _param( 1, IT_NUMERIC );
|
||||
PITEM arg2_it = _param( 2, IT_STRING );
|
||||
long bytes = 0;
|
||||
PITEM arg1_it = _param(1,IT_NUMBER);
|
||||
PITEM arg2_it = _param(2,IT_STRING);
|
||||
PITEM arg3_it = _param(3,IT_NUMBER);
|
||||
|
||||
if( arg1_it && arg2_it )
|
||||
{
|
||||
bytes = write( _parni( 1 ), _parc( 2 ),
|
||||
_parnl( 3 ) ? _parnl( 3 ): _parclen( 2 ) );
|
||||
last_error = errno;
|
||||
}
|
||||
_retnl( bytes );
|
||||
long bytes=0;
|
||||
|
||||
if( arg1_it && arg2_it && arg3_it )
|
||||
{
|
||||
bytes = _fsWrite(_parni(1),_parc(2),_parnl(3));
|
||||
last_error = errno;
|
||||
}
|
||||
|
||||
_retnl(bytes);
|
||||
return;
|
||||
}
|
||||
|
||||
HARBOUR FERROR()
|
||||
{
|
||||
_retni(last_error);
|
||||
_retni(_fsError());
|
||||
return;
|
||||
}
|
||||
|
||||
HARBOUR FCLOSE()
|
||||
{
|
||||
PITEM arg1_it = _param(1,IT_NUMERIC);
|
||||
PITEM arg1_it = _param(1,IT_NUMBER);
|
||||
int result=-1;
|
||||
|
||||
if( arg1_it )
|
||||
@@ -168,7 +424,7 @@ HARBOUR FERASE()
|
||||
HARBOUR FRENAME()
|
||||
{
|
||||
PITEM arg1_it = _param(1,IT_STRING);
|
||||
PITEM arg2_it = _param(1,IT_STRING);
|
||||
PITEM arg2_it = _param(2,IT_STRING);
|
||||
|
||||
int result=-1;
|
||||
|
||||
@@ -184,15 +440,15 @@ HARBOUR FRENAME()
|
||||
|
||||
HARBOUR FSEEK()
|
||||
{
|
||||
PITEM arg1_it = _param(1,IT_NUMERIC);
|
||||
PITEM arg2_it = _param(1,IT_NUMERIC);
|
||||
PITEM arg3_it = _param(1,IT_NUMERIC);
|
||||
PITEM arg1_it = _param(1,IT_NUMBER);
|
||||
PITEM arg2_it = _param(2,IT_NUMBER);
|
||||
PITEM arg3_it = _param(3,IT_NUMBER);
|
||||
|
||||
long bytes=0;
|
||||
long bytes=0;
|
||||
|
||||
if( arg1_it && arg2_it && arg3_it )
|
||||
{
|
||||
bytes = lseek(_parni(1),_parnl(2),_parni(3));
|
||||
bytes = _fsSeek(_parni(1),_parnl(2),_parni(3));
|
||||
last_error = errno;
|
||||
}
|
||||
|
||||
@@ -200,22 +456,26 @@ HARBOUR FSEEK()
|
||||
return;
|
||||
}
|
||||
|
||||
HARBOUR File()
|
||||
HARBOUR _FILE()
|
||||
{
|
||||
PITEM arg1_it = _param( 1, IT_STRING );
|
||||
|
||||
if( arg1_it )
|
||||
{
|
||||
// TODO: In this moment I'm thinking about two alternatives
|
||||
// TODO: I'm thinking about this :(
|
||||
}
|
||||
_retl(0);
|
||||
return;
|
||||
}
|
||||
|
||||
HARBOUR FREADSTR()
|
||||
{
|
||||
PITEM arg1_it = _param( 1, IT_NUMERIC );
|
||||
PITEM arg1_it = _param( 1, IT_NUMBER );
|
||||
PITEM arg2_it = _param( 2, IT_NUMBER );
|
||||
|
||||
int handle;
|
||||
long bytes;
|
||||
long nRead;
|
||||
long readed;
|
||||
char * buffer;
|
||||
char ch[1];
|
||||
@@ -223,14 +483,14 @@ HARBOUR FREADSTR()
|
||||
if( arg1_it )
|
||||
{
|
||||
handle = _parni(1);
|
||||
bytes = _parnl(2);
|
||||
bytes = (arg2_it ? _parnl(2) : 0);
|
||||
buffer = ( char * ) _xgrab(bytes);
|
||||
|
||||
readed=0; ch[0]=1;
|
||||
while( readed < bytes )
|
||||
{
|
||||
bytes = read(handle,ch,1);
|
||||
if( bytes < 1 || ch[0] == 0 )
|
||||
nRead = read(handle,ch,1);
|
||||
if( nRead < 1 || ch[0] == 0 )
|
||||
break;
|
||||
buffer[readed]=ch[0];
|
||||
readed++;
|
||||
@@ -304,7 +564,7 @@ HARBOUR I2BIN()
|
||||
_retclen(s,3);
|
||||
}
|
||||
else
|
||||
_retclen("\0\0\0",3);
|
||||
_retclen("\0\0",2);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -326,7 +586,7 @@ HARBOUR L2BIN()
|
||||
_retclen(s,5);
|
||||
}
|
||||
else
|
||||
_retclen("\0\0\0\0\0",5);
|
||||
_retclen("\0\0\0\0",4);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user