static int __putc(int c, BPTR fh) { if (FPutC(fh, c) == EOF) { errno = IoErr2errno(IoErr()); return EOF; } return c; }
static int system_no_sh(const char *string) { struct arosc_privdata *pdata = __get_arosc_privdata(); const char *apath; char *args, *cmd, *fullcmd; fdesc *in, *out, *err; int ret; D(bug("system_no_sh(%s)\n", string)); args = strdup(string); cmd = strsep(&args, " \t\n"); if (!args) args = ""; D(bug("system(cmd=%s, args=%s)\n", cmd, args)); apath = __path_u2a(cmd); fullcmd = malloc(strlen(apath) + strlen(args) + 2); strcpy(fullcmd, apath); strcat(fullcmd, " "); strcat(fullcmd, args); free(cmd); in = pdata->acpd_fd_array[STDIN_FILENO]; out = pdata->acpd_fd_array[STDOUT_FILENO]; err = pdata->acpd_fd_array[STDERR_FILENO]; ret = (int)SystemTags ( fullcmd, SYS_Input, (IPTR)(in ? in->fcb->fh : NULL), SYS_Output, (IPTR)(out ? out->fcb->fh : NULL), SYS_Error, (IPTR)(err ? err->fcb->fh : NULL), NULL ); free(fullcmd); if (ret == -1) errno = IoErr2errno(IoErr()); return ret; } /* system */
int remove ( /* SYNOPSIS */ const char * pathname) /* FUNCTION Deletes a file or directory. INPUTS pathname - Complete path to the file or directory. RESULT 0 on success and -1 on error. In case of an error, errno is set. NOTES Identical to unlink EXAMPLE BUGS SEE ALSO unlink() INTERNALS ******************************************************************************/ { if (!DeleteFile (__path_u2a(pathname))) { errno = IoErr2errno (IoErr()); return -1; } return 0; } /* remove */
int statfs( /* SYNOPSIS */ const char *path, struct statfs *buf) /* FUNCTION Gets information about mounted filesystem. INPUTS path - path to any file in the filesystem we want to know about buf - pointer to statfs structures where information about filesystem will be stored RESULT Information about filesystem is stored in statfs structure NOTES EXAMPLE BUGS f_flags, f_files, f_ffree and f_fsid.val are always set to 0 f_mntfromname is set to an empty string SEE ALSO INTERNALS ******************************************************************************/ { BPTR lock; LONG ioerr = 0; struct InfoData data; char *apath; if (path == NULL) { errno = EINVAL; return -1; } apath = __path_u2a(path); if (!apath) { errno = EINVAL; return -1; } /* Get filesystem data from lock */ if(((lock = Lock(apath, SHARED_LOCK)))) { if(Info(lock, &data)) { /* Fill statfs structure */ buf->f_type = getnixfilesystemtype(data.id_DiskType); buf->f_flags = 0; buf->f_fsize = data.id_BytesPerBlock; buf->f_bsize = data.id_BytesPerBlock; buf->f_blocks = data.id_NumBlocks; buf->f_bfree = data.id_NumBlocks - data.id_NumBlocksUsed; buf->f_bavail = data.id_NumBlocks - data.id_NumBlocksUsed; buf->f_files = 0; buf->f_ffree = 0; buf->f_fsid.val[0] = 0; buf->f_fsid.val[1] = 0; strncpy(buf->f_mntonname, __path_a2u(((struct DeviceList *)BADDR(data.id_VolumeNode))->dl_Name), MNAMELEN); buf->f_mntfromname[0] = '\0'; } else { ioerr = IoErr(); } UnLock(lock); } else { ioerr = IoErr(); } if(ioerr != 0) { errno = IoErr2errno(ioerr); return -1; } return 0; }
int fchdir( /* SYNOPSIS */ int fd ) /* FUNCTION Change the current working directory to the directory given as an open file descriptor. INPUTS fd - File descriptor of the directory to change to. RESULT If the current directory was changed successfully, zero is returned. Otherwise, -1 is returned and errno set apropriately. NOTES At program exit, the current working directory will be changed back to the one that was current when the program first started. If you do not desire this behaviour, use dos.library/CurrentDir() instead. EXAMPLE BUGS SEE ALSO INTERNALS ******************************************************************************/ { BPTR oldlock = NULL; BPTR newlock = NULL; BPTR handle = NULL; if ( __get_default_file(fd, (long*) &handle) != 0 ) { errno = EBADF; goto error; } newlock = DupLockFromFH(handle); if( newlock == NULL ) { errno = IoErr2errno( IoErr() ); goto error; } oldlock = CurrentDir( newlock ); if( __startup_cd_changed ) { UnLock( oldlock ); } else { __startup_cd_changed = TRUE; __startup_cd_lock = oldlock; } return 0; error: if( newlock != NULL ) UnLock( newlock ); return -1; }
int access ( /* SYNOPSIS */ const char *path, int mode) /* FUNCTION Check access permissions of a file or pathname INPUTS path - the path of the file being checked mode - the bitwise inclusive OR of the access permissions to be checked: W_OK - for write permission R_OK - for readpermissions X_OK - for execute permission F_OK - Just to see whether the file exists RESULT If path cannot be found or if any of the desired access modes would not be granted, then a -1 value is returned; otherwise a 0 value is returned. NOTES EXAMPLE BUGS SEE ALSO open(), ftruncate() INTERNALS ******************************************************************************/ { BPTR lock = NULL; struct FileInfoBlock *fib = NULL; int result = -1; char vol[32]; struct DosList *dl = NULL; if (!path) /* safety check */ { errno = EFAULT; return -1; } if (!strlen(path)) /* empty path */ { errno = ENOENT; return -1; } /* Check if the volume exists. Calling Lock on non-existing volume will bring up System Requester */ if (SplitName(__path_u2a(path), ':', vol, 0, sizeof(vol)-1) != -1) { if(strcmp(vol, "PROGDIR") != 0) { dl = LockDosList(LDF_ALL | LDF_READ); dl = FindDosEntry(dl, vol, LDF_ALL); UnLockDosList(LDF_ALL | LDF_READ); /* Volume / Assign / Device not found */ if (dl == NULL) { errno = ENOENT; return -1; } } } /* Create a lock and examine a lock */ lock = Lock(__path_u2a(path), SHARED_LOCK); if (lock == NULL) { errno = IoErr2errno(IoErr()); return -1; } fib = AllocDosObject(DOS_FIB, NULL); if (!fib) { errno = IoErr2errno(IoErr()); UnLock(lock); return -1; } if (Examine(lock, fib)) { /* Notice : protection flags are 'low-active' (0 means access is granted) */ result = 0; if ((mode & R_OK) && (result == 0) && (fib->fib_Protection & (1 << FIBB_READ))) { errno = EACCES; result = -1; } if ((mode & W_OK) && (result == 0) && (fib->fib_Protection & (1 << FIBB_WRITE))) { errno = EACCES; result = -1; } if ((mode & X_OK) && (result == 0) && (fib->fib_Protection & (1 << FIBB_EXECUTE))) { errno = EACCES; result = -1; } } else { errno = EBADF; result = -1; } FreeDosObject(DOS_FIB, fib); fib = NULL; UnLock(lock); return result; }