ORCALib/fcntl.asm

1 line
24 KiB
NASM
Raw Normal View History

2017-10-02 00:00:58 +00:00
keep obj/fcntl mcopy fcntl.macros case on **************************************************************** * * fcntl - UNIX primitive input/output facilities * * This code implements the tables and subroutines needed to * support a subset of the UNIX library FCNTL. * * October 1989 * Mike Westerfield * * Copyright 1989 * Byte Works, Inc. * **************************************************************** * FCNTL start dummy segment copy equates.asm strSize gequ 255 max size of a GS/OS path name end **************************************************************** * * ctoosstr - convert a C string to a GS/OS input string * * Inputs: * cstr - pointer to the c string * * Outputs: * returns a pointer to the OS string * * Notes: * If the C string is longer than strSize bytes, the * string is truncated without warning. * **************************************************************** * ctoosstr private osptr equ 1 os string pointer csubroutine (4:cstr),4 phb use a local B reg phk plb short M copy over the characters ldy #0 lb1 lda [cstr],Y beq lb2 sta osstr+2,Y iny cpy #strSize bne lb1 lb2 sty osstr set the string length long M lla osptr,osstr set the address of the string plb restore caller's B creturn 4:osptr return osptr osstr ds 2+strSize GS/OS string buffer end **************************************************************** * * int chmod(char *path, int mode); * * Changes the access bits. * * Inputs: * path - name of the file * mode - zero or more flags to set: * 0x0100 - read * 0x0080 - write * 0x1000 - delete * 0x2000 - rename * 0x4000 - backup * 0x8000 - invisible * * Outputs: * returns 0 if successful; else -1 * errno - set if an error occurred * **************************************************************** * chmod start err equ 1 error return code csubroutine (4:path,2:mode),2 phb use local B phk plb stz err err = 0 {no error} lda mode convert mode to ProDOS format jsr unixtoprodos sta siAccess ph4 path set the path name jsl ctoosstr sta siPathname stx siPathname+2 OSSet_File_Info siRec set the access bits bcs lb1 lda siAccess if the backup bit is clear then and #$0020 bne lb2 move4 siPathname,cbPathname clear the backup bit OSClear_Backup cbRec bcc lb2 lb1 lda #ENOENT flag an error sta >errno dec err lb2 plb creturn 2:err cbRec dc i'1' ClearBackup record cbPathname ds 4 siRec dc i'2' SetFileInfo record siPathname ds 4 siAccess ds 2 end **************************************************************** * * int close(int filds); * * Close a file. * * Inputs: * filds - file ID of the file to close * * Outputs: * returns 0 if successful; else -1 * errno - set if an error occurred * **************************************************************** * close start err equ 1 error return code csubroutine (2:filds),2 stz err err = 0 {no error} lda filds error if there are too many open files bmi lb2 cmp #OP