Path: utzoo!attcan!uunet!mcvax!unido!fauern!faui44!immd3.informatik.uni-erlangen.de!rtregn From: rtregn@immd3.informatik.uni-erlangen.de (Robert Regn) Newsgroups: comp.os.minix Subject: Re: Float f'ns & system calls Message-ID: <643@faui44.informatik.uni-erlangen.de> Date: 29 Sep 88 12:21:36 GMT References: <273@gara.une.oz> Organization: IMMD III, University of Erlangen, W-Germany Lines: 212 wtoomey@gara.une.oz (Warren Toomey): > > Also, a friend of mine, Callum Gibson, is writing a tcsh-like shell for > his Honours project, and I'd love to port it to Minix but there's a few > system/library calls missing. Could anybody who has the code for the > calls below post it to me and/or the net: > A very good idea!! In the right place my answer: > closedir see below > execv (Done by Terrance Holm?) In Minix since 1.1 > execve (Done by Terrance Holm?) In Minix since 1.1 > feof (A macro somewhere?) Yes in stdio.h > fputc (Declared in 'fputs'?) A macro in stdio.h, same as putc > free (Declared in 'malloc'?) In Minix since 1.1 > getcwd (Done by Terrance Holm?) see below > getwd see below > isdigit (A macro somewhere?) Yes, In Minix since 1.1 > localtime (Declared in 'ctime'?) Yes, in 1.2 > lstat (Declared in 'stat'?) see below > opendir see below > pclose (Declared in 'popen'?) Yes, in 1.2 > readdir see below > realloc (Declared in 'malloc'?) Yes, already in 1.1 > setpgrp see below > A problem are the directory system calls opendir, closedir and readdir (standard in BSD systems). Try to get the message 581@ndsuvax.uucp:Subject: Directory(3) library calls for MINIX from a minix newsserver (I don't have it). Probably the readdir in traverse will suffer and opendir, closedir should be dummies. Look at the code of tcsh. I think, setpgrp is not existent in Minix yet. Use a dummy routine which calls signal to ignore int and quit. That works also. Lstat is only useful if we have symbolic links. Minix don't have. Use #define lstat stat getwd i have never heard. See on the code or ask Callum, what should it do. getcwd - get current working directory posted from Terrence Holm in Aug 88. Shell script below I wish you success and like to get a copy of the source. Robert Regn rtregn.faui32.uucp ------------------------------------------------------------------------- echo x - getcwd.c gres '^X' '' > getcwd.c << '/' X/* getcwd(3) X * X * Author: Terrence W. Holm Aug. 1988 X * X * Directly derived from Adri Koppes' pwd(1). X */ X X#include X#include X#include X#include X X#define NULL (char *) 0 X#define O_RDONLY 0 X#define DIRECT_SIZE (sizeof (struct direct)) X#define PATH_MAX 127 X Xextern char *rindex(); X Xextern int errno; X X Xchar *getcwd( buffer, size ) X char *buffer; X int size; X X { X static char path[ PATH_MAX + 1 ]; X struct stat current; X X if ( buffer == NULL || size == 0 ) X { X errno = EINVAL; X return( NULL ); X } X X path[0] = '\0'; X X /* Get the inode for the current directory */ X X if ( stat( ".", ¤t ) == -1 ) X return( NULL ); X X if ( (current.st_mode & S_IFMT) != S_IFDIR ) X return( NULL ); X X X /* Run backwards up the directory tree, grabbing */ X /* directory names on the way. */ X X while (1) X { X struct stat parent; X struct direct d; X int same_device = 0; X int found = 0; X int fd; X X /* Get the inode for the parent directory */ X X if ( chdir( ".." ) == -1 ) X return( NULL ); X X if ( stat( ".", &parent ) == -1 ) X return( NULL ); X X if ( (parent.st_mode & S_IFMT) != S_IFDIR ) X return( NULL ); X X if ( current.st_dev == parent.st_dev ) X same_device = 1; X X X /* At the root, "." is the same as ".." */ X X if ( same_device && current.st_ino == parent.st_ino ) X break; X X X /* Search the parent directory for the current entry */ X X if ( (fd = open( ".", O_RDONLY )) == -1 ) X return( NULL ); X X while ( ! found && read(fd, &d, DIRECT_SIZE) == DIRECT_SIZE ) X { X if ( same_device ) X { X if ( current.st_ino == d.d_ino ) X found = 1; X } X else X { X static char temp_name[ DIRSIZ + 1 ]; X static struct stat dir_entry; X X temp_name[0] = '\0'; X strncat( temp_name, d.d_name, DIRSIZ ); X X if ( stat( temp_name, &dir_entry ) == -1 ) X { X close( fd ); X return( NULL ); X } X X if ( current.st_dev == dir_entry.st_dev && X current.st_ino == dir_entry.st_ino ) X found = 1; X } X } X X close( fd ); X X if ( ! found ) X return( NULL ); X X if ( strlen(path) + DIRSIZ + 1 > PATH_MAX ) X { X errno = ERANGE; X return( NULL ); X } X X strcat( path, "/" ); X strncat( path, d.d_name, DIRSIZ ); X X current.st_dev = parent.st_dev; X current.st_ino = parent.st_ino; X } X X X /* Copy the reversed path name into */ X X if ( strlen(path) + 1 > size ) X { X errno = ERANGE; X return( NULL ); X } X X if ( strlen(path) == 0 ) X { X strcpy( buffer, "/" ); X return( buffer ); X } X X *buffer = '\0'; X X { X char *r; X X while ( (r = rindex( path, '/' )) != NULL ) X { X strcat( buffer, r ); X *r = '\0'; X } X } X X return( buffer ); X } / -------------------------------------------------------------------------