home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
zip
/
mint
/
mntlib16.lzh
/
MNTLIB16
/
OPEN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-03
|
2KB
|
116 lines
/* based upon Dale Schumacher's dLibs library */
/* extensively modified by ers */
#define __SRC__
#include <osbind.h>
#include <mintbind.h>
#include <limits.h>
#include <fcntl.h>
#include <ioctl.h>
#include <errno.h>
#include <unistd.h>
#include "lib.h"
static int __umask = -1;
extern int __mint;
/*
* function to set the initial value of __umask
*/
static void
_get_umask()
{
if (__mint < 9) {
__umask = 0;
} else {
__umask = Pumask(0);
(void) Pumask(__umask);
}
}
int open(_filename, iomode, pmode)
const char *_filename;
int iomode;
unsigned pmode;
{
int rv;
int modemask; /* which bits get passed to the OS? */
char filename[PATH_MAX];
_unx2dos(_filename, filename);
/* use the umask() setting to get the right permissions */
if (__umask == -1)
_get_umask();
pmode &= ~__umask;
/* set the file access modes correctly */
iomode = iomode & ~O_SHMODE;
if (__mint >= 9) {
modemask = O_ACCMODE | O_SHMODE | O_SYNC | O_NDELAY;
iomode |= (iomode & O_EXCL) ? O_DENYRW : O_DENYNONE;
} else {
modemask = O_ACCMODE;
}
if(Fattrib(filename, 0, 0) >= 0) /* file exists */
{
if((iomode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) {
errno = EEXIST;
return -1;
}
if(iomode & O_TRUNC)
rv = Fcreate(filename, 0x00);
else
rv = Fopen(filename,iomode & modemask);
}
else /* file doesn't exist */
{
if(iomode & O_CREAT) {
rv = Fcreate(filename, 0x00);
if (rv >= 0 && __mint >= 9)
(void)Fchmod(filename, pmode);
}
else
rv = -ENOENT;
}
if((rv >= 0) && (iomode & O_APPEND))
(void)lseek(rv, 0L, SEEK_END);
if(rv < (__SMALLEST_VALID_HANDLE)) {
errno = -rv;
return __SMALLEST_VALID_HANDLE - 1;
}
(void)isatty(rv); /* sets up tty flags under TOS */
return(rv);
}
int
creat(name, mode)
const char *name;
unsigned mode;
{
return open(name, O_WRONLY|O_CREAT|O_TRUNC, mode);
}
/* umask -- change default file creation mask */
int umask(complmode)
int complmode;
{
int old_umask;
if (__umask == -1)
_get_umask();
old_umask = __umask;
__umask = complmode;
if (__mint >= 9)
return Pumask(complmode);
return old_umask;
}