diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/ChangeLog | 15 | ||||
-rw-r--r-- | util/dotlock.c | 74 | ||||
-rw-r--r-- | util/fileutil.c | 41 | ||||
-rw-r--r-- | util/http.c | 13 | ||||
-rw-r--r-- | util/iobuf.c | 10 | ||||
-rw-r--r-- | util/logger.c | 36 | ||||
-rw-r--r-- | util/memory.c | 21 | ||||
-rw-r--r-- | util/riscos.c | 315 | ||||
-rw-r--r-- | util/secmem.c | 7 | ||||
-rw-r--r-- | util/ttyio.c | 64 |
10 files changed, 563 insertions, 33 deletions
diff --git a/util/ChangeLog b/util/ChangeLog index 92d6cecb7..3e361bcdb 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,18 @@ +2001-08-20 Werner Koch <[email protected]> + + Applied patches from Stefan Bellon <[email protected]> to support + the RISCOS. Nearly all of these patches are identified by the + __riscos__ macro. + * secmem.c [__riscos__]: Disabled secure memory stuff. + * dotlock.c, ttyio.c [__riscos__]: Adapted for RISCOS + * fileutil.c, iobuf.c: Adapted for RISCOS; mainly replaced + hardcoded path separators with EXTSEP_S like macros. + * http.c (send_request): Use macros for the env-var name. + * logger.c [__riscos__]: Do an fflush at the end of each log + function. + * memory.c [__riscos__]: Minor patches + * riscos.c (set_filetype): New. + 2001-07-03 Werner Koch <[email protected]> * strgutil.c (utf8_to_native): Fixed printing of invalid utf-8 diff --git a/util/dotlock.c b/util/dotlock.c index 6b65e62b2..fac825450 100644 --- a/util/dotlock.c +++ b/util/dotlock.c @@ -1,5 +1,5 @@ /* dotlock.c - dotfile locking - * Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -25,7 +25,7 @@ #include <ctype.h> #include <errno.h> #include <unistd.h> -#ifndef HAVE_DOSISH_SYSTEM +#if !defined (HAVE_DOSISH_SYSTEM) #include <sys/utsname.h> #endif #include <sys/types.h> @@ -80,7 +80,7 @@ create_dotlock( const char *file_to_lock ) DOTLOCK h; int fd = -1; char pidstr[16]; - #ifndef HAVE_DOSISH_SYSTEM + #if !defined (HAVE_DOSISH_SYSTEM) struct utsname utsbuf; #endif const char *nodename; @@ -106,7 +106,7 @@ create_dotlock( const char *file_to_lock ) } -#ifndef HAVE_DOSISH_SYSTEM +#if !defined (HAVE_DOSISH_SYSTEM) sprintf( pidstr, "%10d\n", (int)getpid() ); /* fixme: add the hostname to the second line (FQDN or IP addr?) */ @@ -116,8 +116,17 @@ create_dotlock( const char *file_to_lock ) else nodename = utsbuf.nodename; - if( !(dirpart = strrchr( file_to_lock, '/' )) ) { - dirpart = "."; +#ifdef __riscos__ + { + char *iter = (char *) nodename; + for (; iter[0]; iter++) + if (iter[0] == '.') + iter[0] = '/'; + } +#endif /* __riscos__ */ + + if( !(dirpart = strrchr( file_to_lock, DIRSEP_C )) ) { + dirpart = EXTSEP_S; dirpartlen = 1; } else { @@ -132,8 +141,13 @@ create_dotlock( const char *file_to_lock ) all_lockfiles = h; h->tname = m_alloc( dirpartlen + 6+30+ strlen(nodename) + 11 ); +#ifndef __riscos__ sprintf( h->tname, "%.*s/.#lk%p.%s.%d", dirpartlen, dirpart, h, nodename, (int)getpid() ); +#else /* __riscos__ */ + sprintf( h->tname, "%.*s.lk%p/%s/%d", + dirpartlen, dirpart, h, nodename, (int)getpid() ); +#endif /* __riscos__ */ do { errno = 0; @@ -175,9 +189,9 @@ create_dotlock( const char *file_to_lock ) #ifdef _REENTRANT /* release mutex */ #endif -#endif /* !HAVE_DOSISH_SYSTEM */ +#endif h->lockname = m_alloc( strlen(file_to_lock) + 6 ); - strcpy(stpcpy(h->lockname, file_to_lock), ".lock"); + strcpy(stpcpy(h->lockname, file_to_lock), EXTSEP_S "lock"); return h; } @@ -202,7 +216,7 @@ maybe_deadlock( DOTLOCK h ) int make_dotlock( DOTLOCK h, long timeout ) { -#ifdef HAVE_DOSISH_SYSTEM +#if defined (HAVE_DOSISH_SYSTEM) return 0; #else int pid; @@ -214,11 +228,14 @@ make_dotlock( DOTLOCK h, long timeout ) } if( h->locked ) { +#ifndef __riscos__ log_debug("oops, `%s' is already locked\n", h->lockname ); +#endif /* !__riscos__ */ return 0; } for(;;) { +#ifndef __riscos__ if( !link(h->tname, h->lockname) ) { /* fixme: better use stat to check the link count */ h->locked = 1; @@ -228,6 +245,16 @@ make_dotlock( DOTLOCK h, long timeout ) log_error( "lock not made: link() failed: %s\n", strerror(errno) ); return -1; } +#else /* __riscos__ */ + if( !renamefile(h->tname, h->lockname) ) { + h->locked = 1; + return 0; /* okay */ + } + if( errno != EEXIST ) { + log_error( "lock not made: rename() failed: %s\n", strerror(errno) ); + return -1; + } +#endif /* __riscos__ */ if( (pid = read_lockfile(h->lockname)) == -1 ) { if( errno != ENOENT ) { log_info("cannot read lockfile\n"); @@ -242,11 +269,18 @@ make_dotlock( DOTLOCK h, long timeout ) return 0; /* okay */ } else if( kill(pid, 0) && errno == ESRCH ) { +#ifndef __riscos__ maybe_dead = " - probably dead"; #if 0 /* we should not do this without checking the permissions */ /* and the hostname */ log_info( "removing stale lockfile (created by %d)", pid ); #endif +#else /* __riscos__ */ + /* we are *pretty* sure that the other task is dead and therefore + we remove the other lock file */ + maybe_dead = " - probably dead - removing lock"; + unlink(h->lockname); +#endif /* __riscos__ */ } if( timeout == -1 ) { struct timeval tv; @@ -265,7 +299,7 @@ make_dotlock( DOTLOCK h, long timeout ) return -1; } /*not reached */ -#endif /* !HAVE_DOSISH_SYSTEM */ +#endif } @@ -276,7 +310,7 @@ make_dotlock( DOTLOCK h, long timeout ) int release_dotlock( DOTLOCK h ) { -#ifdef HAVE_DOSISH_SYSTEM +#if defined (HAVE_DOSISH_SYSTEM) return 0; #else int pid; @@ -299,15 +333,23 @@ release_dotlock( DOTLOCK h ) log_error( "release_dotlock: not our lock (pid=%d)\n", pid); return -1; } +#ifndef __riscos__ if( unlink( h->lockname ) ) { log_error( "release_dotlock: error removing lockfile `%s'", h->lockname); return -1; } +#else /* __riscos__ */ + if( renamefile(h->lockname, h->tname) ) { + log_error( "release_dotlock: error renaming lockfile `%s' to `%s'", + h->lockname, h->tname); + return -1; + } +#endif /* __riscos__ */ /* fixme: check that the link count is now 1 */ h->locked = 0; return 0; -#endif /* !HAVE_DOSISH_SYSTEM */ +#endif } @@ -317,7 +359,7 @@ release_dotlock( DOTLOCK h ) static int read_lockfile( const char *name ) { - #ifdef HAVE_DOSISH_SYSTEM + #if defined (HAVE_DOSISH_SYSTEM) return 0; #else int fd, pid; @@ -338,7 +380,11 @@ read_lockfile( const char *name ) pidstr[10] = 0; /* terminate pid string */ close(fd); pid = atoi(pidstr); +#ifndef __riscos__ if( !pid || pid == -1 ) { +#else /* __riscos__ */ + if( (!pid && riscos_getpid()) || pid == -1 ) { +#endif /* __riscos__ */ log_error("invalid pid %d in lockfile `%s'", pid, name ); errno = 0; return -1; @@ -351,7 +397,7 @@ read_lockfile( const char *name ) void remove_lockfiles() { - #ifndef HAVE_DOSISH_SYSTEM + #if !defined (HAVE_DOSISH_SYSTEM) DOTLOCK h, h2; h = all_lockfiles; diff --git a/util/fileutil.c b/util/fileutil.c index 1e8ad75ad..30c2511b6 100644 --- a/util/fileutil.c +++ b/util/fileutil.c @@ -25,6 +25,10 @@ #include <string.h> #include <assert.h> #include <unistd.h> +#ifdef __riscos__ +#include <kernel.h> +#include <sys/swis.h> +#endif /* __riscos__ */ #include "util.h" #include "memory.h" #include "ttyio.h" @@ -39,7 +43,7 @@ make_basename(const char *filepath) { char *p; - if ( !(p=strrchr(filepath, '/')) ) + if ( !(p=strrchr(filepath, DIRSEP_C)) ) #ifdef HAVE_DRIVE_LETTERS if ( !(p=strrchr(filepath, '\\')) ) if ( !(p=strrchr(filepath, ':')) ) @@ -66,13 +70,13 @@ make_dirname(const char *filepath) int dirname_length; char *p; - if ( !(p=strrchr(filepath, '/')) ) + if ( !(p=strrchr(filepath, DIRSEP_C)) ) #ifdef HAVE_DRIVE_LETTERS if ( !(p=strrchr(filepath, '\\')) ) if ( !(p=strrchr(filepath, ':')) ) #endif { - return m_strdup("."); + return m_strdup(EXTSEP_S); } dirname_length = p-filepath; @@ -103,20 +107,30 @@ make_filename( const char *first_part, ... ) n += strlen(s) + 1; va_end(arg_ptr); +#ifndef __riscos__ home = NULL; - if( *first_part == '~' && first_part[1] == '/' + if( *first_part == '~' && first_part[1] == DIRSEP_C && (home = getenv("HOME")) && *home ) n += strlen(home); - name = m_alloc(n); p = home ? stpcpy(stpcpy(name,home), first_part+1) : stpcpy(name, first_part); +#else /* __riscos__ */ + name = m_alloc(n); + p = stpcpy(name, first_part); +#endif /* __riscos__ */ va_start( arg_ptr, first_part ) ; while( (s=va_arg(arg_ptr, const char *)) ) - p = stpcpy(stpcpy(p,"/"), s); + p = stpcpy(stpcpy(p, DIRSEP_S), s); va_end(arg_ptr); +#ifndef __riscos__ return name; +#else /* __riscos__ */ + p = gstrans(name); + m_free(name); + return p; +#endif /* __riscos__ */ } @@ -126,11 +140,26 @@ compare_filenames( const char *a, const char *b ) /* ? check whether this is an absolute filename and * resolve symlinks? */ +#ifndef __riscos__ #ifdef HAVE_DRIVE_LETTERS return ascii_strcasecmp(a,b); #else return strcmp(a,b); #endif +#else /* __riscos__ */ + int c = 0; + char *abuf, *bbuf; + + abuf = gstrans(a); + bbuf = gstrans(b); + + c = stricmp(abuf, bbuf); + + m_free(abuf); + m_free(bbuf); + + return c; +#endif /* __riscos__ */ } diff --git a/util/http.c b/util/http.c index c1ab6371c..f77472e9d 100644 --- a/util/http.c +++ b/util/http.c @@ -45,6 +45,14 @@ #include "http.h" +#ifdef __riscos__ + #define HTTP_PROXY_ENV "GnuPG$HttpProxy" + #define HTTP_PROXY_ENV_PRINTABLE "<GnuPG$HttpProxy>" +#else + #define HTTP_PROXY_ENV "http_proxy" + #define HTTP_PROXY_ENV_PRINTABLE "$http_proxy" +#endif + #ifdef __MINGW32__ #define sock_close(a) closesocket(a) #else @@ -475,12 +483,13 @@ send_request( HTTP_HD hd ) port = hd->uri->port? hd->uri->port : 80; if( (hd->flags & HTTP_FLAG_TRY_PROXY) - && (http_proxy = getenv( "http_proxy" )) ) { + && (http_proxy = getenv( HTTP_PROXY_ENV )) ) { PARSED_URI uri; rc = parse_uri( &uri, http_proxy ); if (rc) { - log_error("invalid $http_proxy: %s\n", g10_errstr(rc)); + log_error("invalid " HTTP_PROXY_ENV_PRINTABLE ": %s\n", + g10_errstr(rc)); release_parsed_uri( uri ); return G10ERR_NETWORK; } diff --git a/util/iobuf.c b/util/iobuf.c index 5013e6039..db0a31568 100644 --- a/util/iobuf.c +++ b/util/iobuf.c @@ -32,6 +32,10 @@ #ifdef HAVE_DOSISH_SYSTEM #include <windows.h> #endif +#ifdef __riscos__ +#include <kernel.h> +#include <sys/swis.h> +#endif /* __riscos__ */ #include "memory.h" #include "util.h" @@ -921,14 +925,14 @@ iobuf_cancel( IOBUF a ) const char *s; IOBUF a2; int rc; - #ifdef HAVE_DOSISH_SYSTEM + #if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) char *remove_name = NULL; #endif if( a && a->use == 2 ) { s = iobuf_get_real_fname(a); if( s && *s ) { - #ifdef HAVE_DOSISH_SYSTEM + #if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) remove_name = m_strdup ( s ); #else remove(s); @@ -945,7 +949,7 @@ iobuf_cancel( IOBUF a ) } rc = iobuf_close(a); - #ifdef HAVE_DOSISH_SYSTEM + #if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) if ( remove_name ) { /* Argg, MSDOS does not allow to remove open files. So * we have to do it here */ diff --git a/util/logger.c b/util/logger.c index 5f398aa7d..2e9fad5c6 100644 --- a/util/logger.c +++ b/util/logger.c @@ -117,6 +117,9 @@ g10_log_print_prefix(const char *text) fprintf(logfp, "%s%s: %s", pgm_name, pidstring, text ); else fprintf(logfp, "?%s: %s", pidstring, text ); +#ifdef __riscos__ + fflush( logfp ); +#endif /* __riscos__ */ } static void @@ -128,6 +131,9 @@ print_prefix_f(const char *text, const char *fname) fprintf(logfp, "%s%s:%s: %s", pgm_name, pidstring, fname, text ); else fprintf(logfp, "?%s:%s: %s", pidstring, fname, text ); +#ifdef __riscos__ + fflush( logfp ); +#endif /* __riscos__ */ } void @@ -139,6 +145,9 @@ g10_log_info( const char *fmt, ... ) va_start( arg_ptr, fmt ) ; vfprintf(logfp,fmt,arg_ptr) ; va_end(arg_ptr); +#ifdef __riscos__ + fflush( logfp ); +#endif /* __riscos__ */ } void @@ -150,6 +159,9 @@ g10_log_info_f( const char *fname, const char *fmt, ... ) va_start( arg_ptr, fmt ) ; vfprintf(logfp,fmt,arg_ptr) ; va_end(arg_ptr); +#ifdef __riscos__ + fflush( logfp ); +#endif /* __riscos__ */ } void @@ -162,6 +174,9 @@ g10_log_error( const char *fmt, ... ) vfprintf(logfp,fmt,arg_ptr) ; va_end(arg_ptr); errorcount++; +#ifdef __riscos__ + fflush( logfp ); +#endif /* __riscos__ */ } void @@ -174,6 +189,9 @@ g10_log_error_f( const char *fname, const char *fmt, ... ) vfprintf(logfp,fmt,arg_ptr) ; va_end(arg_ptr); errorcount++; +#ifdef __riscos__ + fflush( logfp ); +#endif /* __riscos__ */ } void @@ -186,6 +204,9 @@ g10_log_fatal( const char *fmt, ... ) vfprintf(logfp,fmt,arg_ptr) ; va_end(arg_ptr); secmem_dump_stats(); +#ifdef __riscos__ + fflush( logfp ); +#endif /* __riscos__ */ exit(2); } @@ -199,6 +220,9 @@ g10_log_fatal_f( const char *fname, const char *fmt, ... ) vfprintf(logfp,fmt,arg_ptr) ; va_end(arg_ptr); secmem_dump_stats(); +#ifdef __riscos__ + fflush( logfp ); +#endif /* __riscos__ */ exit(2); } @@ -217,7 +241,8 @@ g10_log_bug( const char *fmt, ... ) abort(); } -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ) +#if !defined (__riscos__) \ + && ( __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )) void g10_log_bug0( const char *file, int line, const char *func ) { @@ -240,6 +265,9 @@ g10_log_debug( const char *fmt, ... ) va_start( arg_ptr, fmt ) ; vfprintf(logfp,fmt,arg_ptr) ; va_end(arg_ptr); +#ifdef __riscos__ + fflush( logfp ); +#endif /* __riscos__ */ } void @@ -251,6 +279,9 @@ g10_log_debug_f( const char *fname, const char *fmt, ... ) va_start( arg_ptr, fmt ) ; vfprintf(logfp,fmt,arg_ptr) ; va_end(arg_ptr); +#ifdef __riscos__ + fflush( logfp ); +#endif /* __riscos__ */ } @@ -264,6 +295,9 @@ g10_log_hexdump( const char *text, const char *buf, size_t len ) for(i=0; i < len; i++ ) fprintf(logfp, " %02X", ((const byte*)buf)[i] ); fputc('\n', logfp); +#ifdef __riscos__ + fflush( logfp ); +#endif /* __riscos__ */ } diff --git a/util/memory.c b/util/memory.c index a81442d85..9822b1114 100644 --- a/util/memory.c +++ b/util/memory.c @@ -73,8 +73,13 @@ #define FNAME(a) m_debug_ ##a #define FNAMEPRT , const char *info #define FNAMEARG , info - #define store_len(p,n,m) do { add_entry(p,n,m, \ + #ifndef __riscos__ + #define store_len(p,n,m) do { add_entry(p,n,m, \ info, __FUNCTION__); } while(0) + #else + #define store_len(p,n,m) do { add_entry(p,n,m, \ + info, "[" __FILE__ ":" STR(__LINE__) "]" ); } while(0) + #endif #else #define FNAME(a) m_ ##a #define FNAMEPRT @@ -321,9 +326,15 @@ check_allmem( const char *info ) unsigned n; struct memtbl_entry *e; - for( e = memtbl, n = 0; n < memtbl_len; n++, e++ ) - if( e->inuse ) + for( e = memtbl, n = 0; n < memtbl_len; n++, e++ ) { + if( e->inuse ) { + #ifndef __riscos__ check_mem(e->user_p-4-EXTRA_ALIGN, info); + #else + check_mem((const byte *) e->user_p-4-EXTRA_ALIGN, info); + #endif + } + } } #endif /* M_DEBUG */ @@ -373,7 +384,7 @@ m_print_stats( const char *prefix ) void m_dump_table( const char *prefix ) { - #if M_DEBUG + #ifdef M_DEBUG fprintf(stderr,"Memory-Table-Dump: %s\n", prefix); dump_table(); #endif @@ -507,7 +518,7 @@ FNAME(free)( void *a FNAMEPRT ) return; #ifdef M_DEBUG free_entry(p-EXTRA_ALIGN-4, info); - #elif M_GUARD + #elif defined M_GUARD m_check(p); if( m_is_secure(a) ) secmem_free(p-EXTRA_ALIGN-4); diff --git a/util/riscos.c b/util/riscos.c new file mode 100644 index 000000000..f62cf4d1c --- /dev/null +++ b/util/riscos.c @@ -0,0 +1,315 @@ +/* riscos.c - RISC OS stuff + * Copyright (C) 2001 Free Software Foundation, Inc. + * + * This file is part of GnuPG for RISC OS. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef __RISCOS__C__ +#define __RISCOS__C__ + +#include <config.h> +#include <stdarg.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <kernel.h> +#include <sys/swis.h> +#include "util.h" +#include "memory.h" + +#define __UNIXLIB_INTERNALS +#include <sys/unix.h> +#undef __UNIXLIB_INTERNALS + + +/* RISC OS file open descriptor control list */ + +struct fds_item { + int fd; + struct fds_item *next; +}; +static struct fds_item *fds_list = NULL; + + +/* RISC OS functions */ + +pid_t +riscos_getpid(void) +{ + _kernel_swi_regs r; + + r.r[0] = 3; + if (_kernel_swi(Wimp_ReadSysInfo, &r, &r)) + log_fatal("Wimp_ReadSysInfo failed: Couldn't get WimpState (R0=3)!\n"); + + if (!r.r[0]) + return (pid_t) 0; + + r.r[0] = 5; + if (_kernel_swi(Wimp_ReadSysInfo, &r, &r)) + log_fatal("Wimp_ReadSysInfo failed: Couldn't get task handle (R0=5)!\n"); + + return (pid_t) r.r[0]; +} + +int +riscos_kill(pid_t pid, int sig) +{ + _kernel_swi_regs r; + int buf[4]; + + if (sig) + kill(pid, sig); + + r.r[0] = 0; + do { + r.r[1] = (int) buf; + r.r[2] = 16; + if (_kernel_swi(TaskManager_EnumerateTasks, &r, &r)) + log_fatal("TaskManager_EnumerateTasks failed!\n"); + if (buf[0] == pid) + return 0; + } while (r.r[0] >= 0); + + return __set_errno(ESRCH); +} + +FILE * +riscos_fopen(const char *filename, const char *mode) +{ + FILE *fp; + _kernel_swi_regs r; + _kernel_oserror *e; + int filetype; + + r.r[0] = 17; + r.r[1] = (int) filename; + if( e =_kernel_swi(OS_File, &r, &r) ) + log_fatal("can't retrieve object information for %s\n", filename); + if( r.r[0] == 2) { + errno = EISDIR; + return NULL; + } + if( r.r[0] == 3) { + /* setting file to to non-image file, after fopening, restore */ + filetype = (r.r[2] >> 8) & 0xfff; + set_filetype(filename, 0xfff); + fp = fopen(filename, mode); + set_filetype(filename, filetype); + } else { + fp = fopen(filename, mode); + } + return fp; +} + +int +riscos_open(const char *filename, int oflag, ...) +{ + va_list ap; + _kernel_swi_regs r; + _kernel_oserror *e; + int fd, mode, filetype; + + r.r[0] = 17; + r.r[1] = (int) filename; + if( e =_kernel_swi(OS_File, &r, &r) ) + log_fatal("can't retrieve object information for %s\n", filename); + if( r.r[0] == 2) { + errno = EISDIR; + return NULL; + } + + va_start(ap, oflag); + mode = va_arg(ap, int); + va_end(ap); + + if( r.r[0] == 3) { + /* setting file to to non-image file, after fopening, restore */ + filetype = (r.r[2] >> 8) & 0xfff; + set_filetype(filename, 0xfff); + if (!mode) + fd = open(filename, oflag); + else + fd = open(filename, oflag, mode); + set_filetype(filename, filetype); + } else { + if (!mode) + fd = open(filename, oflag); + else + fd = open(filename, oflag, mode); + } + return fd; +} + +int +riscos_fstat(int fildes, struct stat *buf) +{ + _kernel_swi_regs r; + _kernel_oserror *e; + char *filename; + int rc, filetype; + int handle = (int) __u->fd[fildes].handle; + + r.r[0] = 7; + r.r[1] = handle; + r.r[2] = 0; + r.r[5] = 0; + if (e = _kernel_swi(OS_Args, &r, &r)) + log_fatal("can't convert from file handle to name\n"); + + filename = m_alloc(1 - r.r[5]); + + r.r[0] = 7; + r.r[1] = handle; + r.r[2] = (int) filename; + r.r[5] = 1-r.r[5]; + if (e = _kernel_swi(OS_Args, &r, &r)) + log_fatal("can't convert from file handle to name\n"); + + r.r[0] = 17; + r.r[1] = (int) filename; + if( e =_kernel_swi(OS_File, &r, &r) ) + log_fatal("can't retrieve object information for %s\n", filename); + if( r.r[0] == 2) { + errno = EISDIR; + return NULL; + } + if( r.r[0] == 3) { + /* setting file to to non-image file, after fopening, restore */ + filetype = (r.r[2] >> 8) & 0xfff; + set_filetype(filename, 0xfff); + rc = fstat(fildes, buf); + set_filetype(filename, filetype); + } else { + rc = fstat(fildes, buf); + } + + m_free(filename); + + return rc; +} + +int +fdopenfile(const char *filename, const int allow_write) +{ + struct fds_item *h; + static int initialized; + int fd = open(filename, allow_write ? O_CREAT | O_RDWR : O_RDONLY); + if( fd == -1 ) + log_fatal("can't open file %s\n", filename); + + if( !initialized ) { + atexit( close_fds ); + initialized = 1; + } + + h = fds_list; + fds_list = (struct fds_item *) m_alloc( sizeof( struct fds_item ) ); + fds_list->fd = fd; + fds_list->next = h; + + return fd; +} + +void +close_fds(void) +{ + FILE *fp; + struct fds_item *h2, *h1 = fds_list; + while( h1 ) { + h2 = h1->next; + fp = fdopen (h2->fd, "a"); + if (fp) + fflush (fp); + close( h2->fd ); + m_free( h1 ); + h1 = h2; + } +} + +int +renamefile(const char *old, const char *new) +{ + _kernel_swi_regs r; + _kernel_oserror *e; + + r.r[0] = 25; + r.r[1] = (int) old; + r.r[2] = (int) new; + if (e = _kernel_swi(OS_FSControl, &r, &r)) { + if (e->errnum == 214) + return __set_errno(ENOENT); + if (e->errnum == 176) + return __set_errno(EEXIST); + printf("Error during renaming: %i, %s\n", e->errnum, e->errmess); + } + return 0; +} + +char * +gstrans(const char *old) +{ + _kernel_swi_regs r; + int c = 0; + int size = 256; + char *buf, *tmp; + + buf = (char *) m_alloc(size); + do { + r.r[0] = (int) old; + r.r[1] = (int) buf; + r.r[2] = size; + _kernel_swi_c(OS_GSTrans, &r, &r, &c); + if (c) { + size += 256; + tmp = (char *) m_realloc(buf, size); + if (!tmp) + log_fatal("can't claim memory for OS_GSTrans buffer!\n"); + buf = tmp; + } + } while (c); + + buf[r.r[2]] = '\0'; + tmp = (char *) m_realloc(buf, r.r[2] + 1); + if (!tmp) + log_fatal("can't realloc memory after OS_GSTrans!\n"); + + return tmp; +} + +void +set_filetype(const char *filename, const int type) +{ + _kernel_swi_regs r; + + r.r[0] = 18; + r.r[1] = (int) filename; + r.r[2] = type; + + if (_kernel_swi(OS_File, &r, &r)) + log_fatal("can't set filetype for %s\n", filename); +} + +void +not_implemented(const char *feature) +{ + log_info("%s is not implemented in the RISC OS version!\n", feature); +} + +#endif /* !__RISCOS__C__ */ diff --git a/util/secmem.c b/util/secmem.c index acf73e40f..148ea1e88 100644 --- a/util/secmem.c +++ b/util/secmem.c @@ -168,6 +168,11 @@ lock_pool( void *p, size_t n ) /* It does not make sense to print such a warning, given the fact that * this whole Windows !@#$% and their user base are inherently insecure */ + #elif defined (__riscos__) + /* no virtual memory on RISC OS, so no pages are swapped to disc, + * besides we don't have mmap, so we don't use it! ;-) + * But don't complain, as explained above. + */ #else log_info("Please note that you don't have secure memory on this system\n"); #endif @@ -267,6 +272,7 @@ void secmem_init( size_t n ) { if( !n ) { +#ifndef __riscos__ #ifdef USE_CAPABILITIES /* drop all capabilities */ cap_set_proc( cap_from_text("all-eip") ); @@ -281,6 +287,7 @@ secmem_init( size_t n ) log_fatal("failed to drop setuid\n" ); } #endif +#endif /* !__riscos__ */ } else { if( n < DEFAULT_POOLSIZE ) diff --git a/util/ttyio.c b/util/ttyio.c index 3106b5ae5..513026d43 100644 --- a/util/ttyio.c +++ b/util/ttyio.c @@ -26,6 +26,11 @@ #include <unistd.h> #ifdef HAVE_TCGETATTR #include <termios.h> + #ifdef __riscos__ + #include <kernel.h> + #include <sys/swis.h> + #undef HAVE_TCGETATTR + #endif /* __riscos__ */ #else #ifdef HAVE_TERMIO_H /* simulate termios with termio */ @@ -75,10 +80,16 @@ static int batchmode; static int no_terminal; #ifdef HAVE_TCGETATTR -static struct termios termsave; -static int restore_termios; + #ifdef __riscos__ + struct termios termsave; + int restore_termios; + #else + static struct termios termsave; + static int restore_termios; + #endif #endif + #ifdef HAVE_TCGETATTR static void cleanup(void) @@ -273,7 +284,12 @@ static char * do_get( const char *prompt, int hidden ) { char *buf; + #ifndef __riscos__ byte cbuf[1]; + #else + int carry; + _kernel_swi_regs r; + #endif int c, n, i; if( batchmode ) { @@ -328,6 +344,50 @@ do_get( const char *prompt, int hidden ) if( hidden ) SetConsoleMode(con.in, DEF_INPMODE ); + #elif defined(__riscos__) + do { + if (_kernel_swi_c(OS_ReadC, &r, &r, &carry)) + log_fatal("OS_ReadC failed: Couldn't read from keyboard!\n"); + c = r.r[0]; + if (carry != 0) + log_fatal("OS_ReadC failed: Return Code = %i!\n", c); + if (c == 0xa || c == 0xd) { /* Return || Enter */ + c = (int) '\n'; + } else if (c == 0x8 || c == 0x7f) { /* Backspace || Delete */ + if (i>0) { + i--; + if (!hidden) { + last_prompt_len--; + fputc(8, ttyfp); + fputc(32, ttyfp); + fputc(8, ttyfp); + fflush(ttyfp); + } + } else { + fputc(7, ttyfp); + fflush(ttyfp); + } + continue; + } else if (c == (int) '\t') { /* Tab */ + c = ' '; + } else if (c > 0xa0) { + ; /* we don't allow 0xa0, as this is a protected blank which may + * confuse the user */ + } else if (iscntrl(c)) { + continue; + } + if(!(i < n-1)) { + n += 50; + buf = m_realloc(buf, n); + } + buf[i++] = c; + if (!hidden) { + last_prompt_len++; + fputc(c, ttyfp); + fflush(ttyfp); + } + } while (c != '\n'); + i = (i>0) ? i-1 : 0; #else /* unix version */ if( hidden ) { #ifdef HAVE_TCGETATTR |