home *** CD-ROM | disk | FTP | other *** search
-
- /* u4open.c (C)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
- */
-
- #include "d4all.h"
- #include "u4error.h"
- #include "p4misc.h"
-
- #include <fcntl.h>
- #include <stdio.h>
-
- #ifndef UNIX
- #include <io.h>
- #endif
-
- #ifdef TURBO
- #include <sys\stat.h>
- #include <share.h>
-
- extern unsigned char _osmajor;
- #else
- #ifndef UNIX
- #include <sys\types.h>
- #include <sys\stat.h>
-
- #ifndef ZORTECH
- #include <share.h>
- #endif
-
- extern unsigned char _osmajor;
- #endif
- #endif
-
-
- /* For Paramter 'open_code' */
- #define OPEN_EXIST 0
- #define SAFE_CREATE 1
- #define DO_CREATE 2
- #define OPEN_EXCL 4
-
-
- u4open( char *file_name, int open_code )
- {
- int hand, oflag, pmode, err_code, disp_err ;
-
- if ( open_code & 0x8 )
- {
- open_code -= 0x8 ;
- disp_err = 0 ;
- }
- else
- disp_err = 1 ;
-
- #ifdef TURBO
- oflag = (int) (O_BINARY | O_RDWR) ;
- pmode = (int) (S_IREAD | S_IWRITE) ;
- #else
- #ifdef UNIX
- oflag = (int) O_RDWR ;
- pmode = 0666 ; /* Allow complete read and write permissions */
- #else
- oflag = (int) (O_BINARY | O_RDWR) ;
- pmode = (int) (S_IREAD | S_IWRITE) ;
- #endif
- #endif
-
- err_code = (int) E_CREATE ;
-
- switch( open_code )
- {
- case DO_CREATE:
- u4remove( file_name ) ;
- oflag |= O_CREAT ;
- break ;
-
- case SAFE_CREATE:
- #ifdef ZORTECH
- oflag |= O_CREAT ;
- #else
- oflag |= (O_CREAT | O_EXCL) ;
- #endif
-
- #ifdef TURBO
- /* O_EXCL ignored in TURBO C 1.5 - Make sure file does not exist */
- hand = open( file_name, O_RDWR ) ;
- if ( hand >= 0 )
- {
- /* Generate Error if File Opened !! */
- close( hand ) ;
- if ( disp_err )
- u4error( E_CREATE, file_name, (char *) 0 ) ;
- return( -1 ) ;
- }
- #endif
- break ;
-
- case OPEN_EXCL:
- #ifndef ZORTECH
- oflag |= O_EXCL ;
- #endif
-
- case OPEN_EXIST:
- err_code = E_OPEN ;
- }
-
- /* try to open the file */
- #ifdef TURBO
- if (_osmajor >= 3)
- hand = open( file_name, oflag | SH_DENYNONE, pmode ) ;
- else
- hand = open( file_name, oflag, pmode ) ;
- #else
- #ifdef UNIX
- {
- char lwr_name[68] ; /* Force to lower case for SCO Foxbase Compatibility */
-
- strncpy( lwr_name, file_name, sizeof(lwr_name) ) ;
- lwr_name[sizeof(lwr_name)-1] = '\000' ;
- u4lower( lwr_name ) ;
-
- hand = open( lwr_name, oflag, pmode ) ;
- }
- #else
- #ifdef ZORTECH
- if ( open_code == SAFE_CREATE || open_code == DO_CREATE )
- {
- int rc ;
- char match[14] ;
-
- rc = 18 ;
- hand = -1 ;
-
- if ( open_code == SAFE_CREATE )
- rc = u4file_first( file_name, match ) ;
-
- if ( rc == 18 ) hand = creat( file_name, pmode ) ;
- }
- else
- hand = open( file_name, oflag ) ;
- #else
- #ifdef __WATCOMC__
- hand = sopen( file_name, oflag, SH_DENYNO, pmode ) ;
- #else
- if (_osmajor >= 3)
- hand = sopen( file_name, oflag, SH_DENYNO, pmode ) ;
- else
- hand = open( file_name, oflag, pmode ) ;
- #endif
- #endif
- #endif
- #endif
-
- if ( hand < 0)
- {
- if ( disp_err )
- u4error( err_code, file_name, (char *) 0 ) ;
-
- return( -1) ;
- }
- return ( hand ) ;
- }
-