From 91bcdea2a21a4f0be258b80ecc8f9b5c72b46c5f Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Mon, 26 Jul 2004 16:36:55 +0000 Subject: [PATCH] Initial import into SourceForge CVS git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14685 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- documentation/README | 235 ++ library/GNUmakefile.68k | 1003 +++++++++ library/GNUmakefile.os4 | 883 ++++++++ library/amiga.lib_rev.c | 38 + library/amiga.lib_rev.h | 6 + library/amiga.lib_rev.rev | 1 + library/amiga_acrypt.c | 102 + library/amiga_addtof.c | 83 + library/amiga_argarraydone.c | 71 + library/amiga_argarrayinit.c | 99 + library/amiga_argint.c | 60 + library/amiga_argstring.c | 61 + library/amiga_beginio.c | 84 + library/amiga_callhook.c | 67 + library/amiga_callhooka.asm | 80 + library/amiga_callhooka.c | 93 + library/amiga_coercemethod.c | 93 + library/amiga_createextio.c | 62 + library/amiga_createport.c | 69 + library/amiga_createstdio.c | 62 + library/amiga_createtask.c | 194 ++ library/amiga_deleteextio.c | 54 + library/amiga_deleteport.c | 56 + library/amiga_deletestdio.c | 52 + library/amiga_deletetask.c | 48 + library/amiga_domethod.c | 100 + library/amiga_dosupermethod.c | 93 + library/amiga_dotimer.c | 113 + library/amiga_fastrand.c | 52 + library/amiga_freeievents.c | 62 + library/amiga_hookentry.asm | 51 + library/amiga_hookentry.c | 61 + library/amiga_hotkey.c | 78 + library/amiga_invertstring.c | 208 ++ library/amiga_newlist.c | 60 + library/amiga_rangerand.c | 80 + library/amiga_remtof.c | 57 + library/amiga_setsuperattrs.c | 101 + library/amiga_timedelay.c | 54 + library/amiga_waitbeam.c | 60 + library/c.lib_rev.c | 38 + library/c.lib_rev.h | 6 + library/c.lib_rev.rev | 1 + library/crt0.S | 22 + library/crtbegin.c | 138 ++ library/crtend.c | 18 + library/ctype_headers.h | 61 + library/ctype_isalnum.c | 64 + library/ctype_isalpha.c | 63 + library/ctype_isascii.c | 56 + library/ctype_iscntrl.c | 62 + library/ctype_isdigit.c | 62 + library/ctype_isgraph.c | 62 + library/ctype_islower.c | 62 + library/ctype_isprint.c | 62 + library/ctype_ispunct.c | 65 + library/ctype_isspace.c | 67 + library/ctype_isupper.c | 62 + library/ctype_isxdigit.c | 64 + library/ctype_table.c | 196 ++ library/ctype_tolower.c | 58 + library/ctype_toupper.c | 58 + library/debug.c | 342 +++ library/debug.h | 191 ++ library/debug.lib_rev.c | 38 + library/debug.lib_rev.h | 6 + library/debug.lib_rev.rev | 1 + library/debug_cmpstrexec.c | 62 + library/debug_headers.h | 151 ++ library/debug_kcmpstr.c | 46 + library/debug_kdofmt.c | 45 + library/debug_kgetc.c | 48 + library/debug_kgetch1.c | 46 + library/debug_kgetch2.c | 46 + library/debug_kgetchar1.c | 46 + library/debug_kgetchar2.c | 46 + library/debug_kgetnum1.c | 110 + library/debug_kgetnum2.c | 46 + library/debug_kmaygetch.c | 46 + library/debug_kmaygetchar.c | 55 + library/debug_kprintf1.c | 51 + library/debug_kprintf2.c | 51 + library/debug_kputc.c | 51 + library/debug_kputch1.c | 42 + library/debug_kputch2.c | 42 + library/debug_kputchar1.c | 42 + library/debug_kputchar2.c | 42 + library/debug_kputfmt.c | 194 ++ library/debug_kputs1.c | 44 + library/debug_kputs2.c | 44 + library/debug_kputstr1.c | 50 + library/debug_kputstr2.c | 44 + library/debug_kvprintf1.c | 45 + library/debug_kvprintf2.c | 45 + library/debug_level.c | 37 + library/dirent_closedir.c | 112 + library/dirent_data.c | 72 + library/dirent_headers.h | 63 + library/dirent_opendir.c | 269 +++ library/dirent_readdir.c | 227 ++ library/dirent_rewinddir.c | 87 + library/errno_data.c | 40 + library/fcntl_close.c | 179 ++ library/fcntl_creat.c | 81 + library/fcntl_fcntl.c | 247 +++ library/fcntl_headers.h | 45 + library/fcntl_lseek.c | 125 ++ library/fcntl_open.c | 475 ++++ library/fcntl_read.c | 146 ++ library/fcntl_write.c | 146 ++ library/include/assert.h | 70 + library/include/ctype.h | 122 ++ library/include/dirent.h | 88 + library/include/dos.h | 243 +++ library/include/errno.h | 170 ++ library/include/fcntl.h | 122 ++ library/include/float.h | 77 + library/include/grp.h | 71 + library/include/iso646.h | 53 + library/include/libgen.h | 60 + library/include/limits.h | 65 + library/include/locale.h | 115 + library/include/math.h | 90 + library/include/pwd.h | 74 + library/include/setjmp.h | 85 + library/include/signal.h | 105 + library/include/stdarg.h | 76 + library/include/stddef.h | 71 + library/include/stdio.h | 347 +++ library/include/stdlib.h | 185 ++ library/include/string.h | 121 + library/include/strings.h | 77 + library/include/sys/amigaos-va.h | 81 + library/include/sys/mount.h | 121 + library/include/sys/stat.h | 135 ++ library/include/sys/time.h | 133 ++ library/include/sys/types.h | 70 + library/include/time.h | 104 + library/include/unistd.h | 275 +++ library/include/utime.h | 73 + library/include/wchar.h | 171 ++ library/include/wctype.h | 93 + library/libgen_basename.c | 97 + library/libgen_dirname.c | 98 + library/locale_data.c | 45 + library/locale_headers.h | 85 + library/locale_init_exit.c | 149 ++ library/locale_localeconv.c | 76 + library/locale_setlocale.c | 160 ++ library/m.lib_rev.c | 38 + library/m.lib_rev.h | 6 + library/m.lib_rev.rev | 1 + library/m881.lib_rev.c | 38 + library/m881.lib_rev.h | 6 + library/m881.lib_rev.rev | 1 + library/macros.h | 198 ++ library/make_ctype_table.c | 297 +++ library/math_acos.c | 238 ++ library/math_adddf3.c | 75 + library/math_addsf3.c | 56 + library/math_asin.c | 249 +++ library/math_atan.c | 273 +++ library/math_atan2.c | 344 +++ library/math_ceil.c | 250 +++ library/math_cos.c | 191 ++ library/math_cosh.c | 207 ++ library/math_data.c | 50 + library/math_divdf3.c | 75 + library/math_divsf3.c | 56 + library/math_eqdf2.c | 75 + library/math_eqsf2.c | 56 + library/math_exp.c | 252 +++ library/math_extendsfdf2.c | 75 + library/math_fabs.c | 160 ++ library/math_fixdfsi.c | 75 + library/math_fixsfsi.c | 56 + library/math_fixunsdfsi.c | 61 + library/math_fixunssfsi.c | 61 + library/math_floatsidf.c | 75 + library/math_floatsisf.c | 56 + library/math_floor.c | 250 +++ library/math_fmod.c | 296 +++ library/math_fp_support.h | 45 + library/math_frexp.c | 217 ++ library/math_gedf2.c | 75 + library/math_gesf2.c | 56 + library/math_gtdf2.c | 75 + library/math_gtsf2.c | 56 + library/math_headers.h | 167 ++ library/math_init_exit.c | 169 ++ library/math_kernel_cos.c | 90 + library/math_kernel_expm1.c | 162 ++ library/math_kernel_rem_pio2.c | 351 +++ library/math_kernel_scalbn.c | 99 + library/math_kernel_sin.c | 82 + library/math_kernel_tan.c | 127 ++ library/math_ldexp.c | 175 ++ library/math_ledf2.c | 75 + library/math_lesf2.c | 56 + library/math_log.c | 267 +++ library/math_log10.c | 209 ++ library/math_ltdf2.c | 75 + library/math_ltsf2.c | 56 + library/math_modf.c | 169 ++ library/math_muldf3.c | 75 + library/math_mulsf3.c | 56 + library/math_nedf2.c | 75 + library/math_negdf2.c | 75 + library/math_negsf2.c | 56 + library/math_nesf2.c | 56 + library/math_pow.c | 468 ++++ library/math_sin.c | 186 ++ library/math_sinh.c | 198 ++ library/math_sqrt.c | 263 +++ library/math_subdf3.c | 75 + library/math_subsf3.c | 56 + library/math_tan.c | 179 ++ library/math_tanh.c | 192 ++ library/math_truncdfsf2.c | 75 + library/mount_convertinfo.c | 101 + library/mount_fstatfs.c | 115 + library/mount_headers.h | 53 + library/mount_statfs.c | 156 ++ library/ncrt0.S | 116 + library/net.lib_rev.c | 38 + library/net.lib_rev.h | 6 + library/net.lib_rev.rev | 1 + library/nrcrt0.S | 182 ++ library/profile__mcount.c | 103 + library/profile_gmon.c | 281 +++ library/profile_gmon.h | 81 + library/profile_mcount.S | 35 + library/profile_profil.c | 122 ++ library/releasenotes | 3036 ++++++++++++++++++++++++++ library/sas_cxamemcpy.asm | 46 + library/sas_cxamemset.asm | 89 + library/sas_cxferr.c | 19 + library/sas_cxv.asm | 141 ++ library/sas_cxv45.asm | 143 ++ library/sas_cxv54.asm | 114 + library/sas_profile.c | 319 +++ library/signal_checkabort.c | 49 + library/signal_data.c | 61 + library/signal_headers.h | 94 + library/signal_kill.c | 120 + library/signal_raise.c | 105 + library/signal_sigaddset.c | 77 + library/signal_sigblock.c | 59 + library/signal_sigemptyset.c | 77 + library/signal_sigmask.c | 62 + library/signal_signal.c | 66 + library/signal_sigprocmask.c | 101 + library/signal_sigsetmask.c | 59 + library/smakefile | 783 +++++++ library/socket_accept.c | 129 ++ library/socket_bind.c | 101 + library/socket_connect.c | 101 + library/socket_data.c | 56 + library/socket_get_descriptor.c | 72 + library/socket_gethostbyaddr.c | 91 + library/socket_gethostbyname.c | 89 + library/socket_gethostid.c | 66 + library/socket_gethostname.c | 90 + library/socket_getnetbyaddr.c | 68 + library/socket_getnetbyname.c | 89 + library/socket_getpeername.c | 101 + library/socket_getprotobyname.c | 87 + library/socket_getprotobynumber.c | 66 + library/socket_getservbyname.c | 87 + library/socket_getservbyport.c | 87 + library/socket_getsockname.c | 101 + library/socket_getsockopt.c | 103 + library/socket_headers.h | 1065 +++++++++ library/socket_hook_entry.c | 168 ++ library/socket_inet_addr.c | 89 + library/socket_inet_aton.c | 201 ++ library/socket_inet_lnaof.c | 66 + library/socket_inet_makeaddr.c | 66 + library/socket_inet_netof.c | 66 + library/socket_inet_network.c | 87 + library/socket_inet_ntoa.c | 72 + library/socket_init_exit.c | 313 +++ library/socket_ioctl.c | 97 + library/socket_isdaemon.c | 48 + library/socket_listen.c | 81 + library/socket_recv.c | 103 + library/socket_recvfrom.c | 104 + library/socket_recvmsg.c | 101 + library/socket_select.c | 1018 +++++++++ library/socket_send.c | 103 + library/socket_sendmsg.c | 101 + library/socket_sendto.c | 104 + library/socket_setsockopt.c | 103 + library/socket_shutdown.c | 81 + library/socket_socket.c | 98 + library/stack.lib_rev.c | 38 + library/stack.lib_rev.h | 6 + library/stack.lib_rev.rev | 1 + library/startup.c | 48 + library/stat_chmod.c | 155 ++ library/stat_convertfileinfo.c | 155 ++ library/stat_data.c | 40 + library/stat_fchmod.c | 128 ++ library/stat_fstat.c | 116 + library/stat_headers.h | 53 + library/stat_lstat.c | 83 + library/stat_mkdir.c | 167 ++ library/stat_rmdir.c | 162 ++ library/stat_stat.c | 169 ++ library/stat_umask.c | 100 + library/stdio_asprintf.c | 84 + library/stdio_clearerr.c | 82 + library/stdio_data.c | 48 + library/stdio_dropiobreadbuffer.c | 113 + library/stdio_duplicate_fd.c | 73 + library/stdio_fclose.c | 152 ++ library/stdio_fdhookentry.c | 2204 +++++++++++++++++++ library/stdio_feof.c | 87 + library/stdio_ferror.c | 86 + library/stdio_fflush.c | 119 + library/stdio_fgetc.c | 159 ++ library/stdio_fgetpos.c | 90 + library/stdio_fgets.c | 135 ++ library/stdio_filliobreadbuffer.c | 133 ++ library/stdio_findvacantfdentry.c | 90 + library/stdio_findvacantiobentry.c | 87 + library/stdio_flush.c | 100 + library/stdio_flushiobwritebuffer.c | 118 + library/stdio_fopen.c | 99 + library/stdio_fprintf.c | 80 + library/stdio_fputc.c | 159 ++ library/stdio_fputs.c | 110 + library/stdio_fread.c | 144 ++ library/stdio_freopen.c | 98 + library/stdio_fscanf.c | 82 + library/stdio_fseek.c | 195 ++ library/stdio_fsetpos.c | 85 + library/stdio_ftell.c | 128 ++ library/stdio_fwrite.c | 156 ++ library/stdio_get_file_descriptor.c | 70 + library/stdio_getc.c | 72 + library/stdio_getchar.c | 52 + library/stdio_gets.c | 122 ++ library/stdio_growfdtable.c | 100 + library/stdio_growiobtable.c | 100 + library/stdio_headers.h | 415 ++++ library/stdio_init_exit.c | 241 ++ library/stdio_initializefd.c | 65 + library/stdio_initializeiob.c | 73 + library/stdio_iobhookentry.c | 122 ++ library/stdio_isinfinity.c | 81 + library/stdio_isnotanumber.c | 85 + library/stdio_locksemaphorename.c | 40 + library/stdio_nostdio.c | 40 + library/stdio_openiob.c | 214 ++ library/stdio_perror.c | 57 + library/stdio_popen.c | 362 +++ library/stdio_printf.c | 79 + library/stdio_protos.h | 221 ++ library/stdio_putc.c | 72 + library/stdio_putchar.c | 52 + library/stdio_puts.c | 112 + library/stdio_remove.c | 100 + library/stdio_rename.c | 149 ++ library/stdio_rewind.c | 51 + library/stdio_scanf.c | 81 + library/stdio_setbuf.c | 79 + library/stdio_setvbuf.c | 195 ++ library/stdio_snprintf.c | 84 + library/stdio_sprintf.c | 80 + library/stdio_sscanf.c | 94 + library/stdio_sscanf_hook_entry.c | 94 + library/stdio_tmpfile.c | 119 + library/stdio_tmpnam.c | 122 ++ library/stdio_translateioerror.c | 118 + library/stdio_ungetc.c | 140 ++ library/stdio_vasprintf.c | 132 ++ library/stdio_vasprintf_hook_entry.c | 117 + library/stdio_vfprintf.c | 1534 +++++++++++++ library/stdio_vfscanf.c | 1579 ++++++++++++++ library/stdio_vprintf.c | 77 + library/stdio_vsnprintf.c | 120 + library/stdio_vsnprintf_hook_entry.c | 93 + library/stdio_vsprintf.c | 82 + library/stdio_vsprintf_hook_entry.c | 77 + library/stdlib_abort.c | 61 + library/stdlib_abs.c | 48 + library/stdlib_alloca.c | 160 ++ library/stdlib_assertion_failure.c | 166 ++ library/stdlib_atexit.c | 144 ++ library/stdlib_atof.c | 76 + library/stdlib_atoi.c | 68 + library/stdlib_atol.c | 68 + library/stdlib_bsearch.c | 105 + library/stdlib_calloc.c | 93 + library/stdlib_checkdetach.c | 38 + library/stdlib_constructor.c | 48 + library/stdlib_constructor_begin.c | 255 +++ library/stdlib_constructor_end.c | 44 + library/stdlib_data.c | 105 + library/stdlib_default_pool_size.c | 40 + library/stdlib_default_puddle_size.c | 40 + library/stdlib_destructor.c | 48 + library/stdlib_detach.c | 38 + library/stdlib_disablerequesters.c | 38 + library/stdlib_div.c | 51 + library/stdlib_divmodsi3.c | 79 + library/stdlib_divsi3.c | 69 + library/stdlib_divsi4.c | 77 + library/stdlib_dosbase.c | 47 + library/stdlib_exit.c | 66 + library/stdlib_free.c | 512 +++++ library/stdlib_gcc_help.h | 50 + library/stdlib_getdefstacksize.c | 40 + library/stdlib_getenv.c | 89 + library/stdlib_getsp.asm | 45 + library/stdlib_getsp.c | 88 + library/stdlib_headers.h | 248 +++ library/stdlib_init_exit.c | 157 ++ library/stdlib_isresident.c | 38 + library/stdlib_labs.c | 48 + library/stdlib_ldiv.c | 51 + library/stdlib_locale_utility.h | 92 + library/stdlib_machine_test.c | 89 + library/stdlib_main.c | 579 +++++ library/stdlib_malloc.c | 252 +++ library/stdlib_math.c | 55 + library/stdlib_mblen.c | 45 + library/stdlib_mbstowcs.c | 45 + library/stdlib_mbtowc.c | 45 + library/stdlib_mem_debug.h | 90 + library/stdlib_mkdtemp.c | 95 + library/stdlib_mkstemp.c | 91 + library/stdlib_mktemp.c | 226 ++ library/stdlib_modsi3.c | 76 + library/stdlib_mulsi3.c | 79 + library/stdlib_never_free.c | 40 + library/stdlib_null_pointer_check.h | 47 + library/stdlib_protos.h | 224 ++ library/stdlib_putenv.c | 82 + library/stdlib_qsort.c | 291 +++ library/stdlib_rand.c | 65 + library/stdlib_realloc.c | 210 ++ library/stdlib_red_black.c | 424 ++++ library/stdlib_setenv.c | 220 ++ library/stdlib_setjmp.asm | 98 + library/stdlib_setjmp.c | 370 ++++ library/stdlib_setjmp.i | 70 + library/stdlib_shell_escape.c | 61 + library/stdlib_showerror.c | 163 ++ library/stdlib_socket.c | 51 + library/stdlib_srand.c | 45 + library/stdlib_stack_usage.c | 117 + library/stdlib_stackargbytes.c | 38 + library/stdlib_stackcheck.c | 130 ++ library/stdlib_stackextension.c | 612 ++++++ library/stdlib_stackminframe.c | 38 + library/stdlib_stackoverflow.c | 80 + library/stdlib_stacksafezone.c | 38 + library/stdlib_stacksize.c | 80 + library/stdlib_startup.c | 464 ++++ library/stdlib_strtod.c | 307 +++ library/stdlib_strtol.c | 196 ++ library/stdlib_strtoul.c | 193 ++ library/stdlib_swapstack.asm | 67 + library/stdlib_swapstack.c | 149 ++ library/stdlib_sysbase.c | 47 + library/stdlib_system.c | 185 ++ library/stdlib_termination_message.c | 62 + library/stdlib_threshold.c | 40 + library/stdlib_udivmodsi3.c | 79 + library/stdlib_udivsi3.c | 68 + library/stdlib_udivsi4.c | 76 + library/stdlib_umodsi3.c | 74 + library/stdlib_unsetenv.c | 101 + library/stdlib_usergroup.c | 51 + library/stdlib_wcstombs.c | 45 + library/stdlib_wctomb.c | 45 + library/stdlib_wildcard_expand.c | 65 + library/string_bcmp.c | 55 + library/string_bcopy.c | 50 + library/string_bzero.c | 50 + library/string_headers.h | 60 + library/string_index.c | 52 + library/string_memchr.c | 225 ++ library/string_memcmp.c | 205 ++ library/string_memcpy.c | 370 ++++ library/string_memmove.c | 623 ++++++ library/string_memset.c | 167 ++ library/string_rindex.c | 52 + library/string_strcat.c | 72 + library/string_strchr.c | 84 + library/string_strcmp.c | 80 + library/string_strcoll.c | 82 + library/string_strcpy.c | 72 + library/string_strcspn.c | 79 + library/string_strdup.c | 99 + library/string_strerror.c | 198 ++ library/string_strlen.c | 72 + library/string_strncat.c | 91 + library/string_strncmp.c | 90 + library/string_strncpy.c | 85 + library/string_strpbrk.c | 80 + library/string_strrchr.c | 89 + library/string_strspn.c | 79 + library/string_strstr.c | 102 + library/string_strtok.c | 105 + library/string_strxfrm.c | 114 + library/strings_headers.h | 52 + library/strings_strcasecmp.c | 85 + library/strings_strncasecmp.c | 94 + library/time_asctime.c | 192 ++ library/time_clock.c | 88 + library/time_converttime.c | 87 + library/time_ctime.c | 73 + library/time_data.c | 96 + library/time_difftime.c | 56 + library/time_gettimeofday.c | 94 + library/time_gmtime.c | 74 + library/time_headers.h | 103 + library/time_localtime.c | 89 + library/time_mktime.c | 201 ++ library/time_numbertostring.c | 96 + library/time_strftime.c | 626 ++++++ library/time_time.c | 69 + library/unistd_access.c | 231 ++ library/unistd_chdir.c | 184 ++ library/unistd_chown.c | 169 ++ library/unistd_currentpathname.c | 40 + library/unistd_data.c | 60 + library/unistd_dup.c | 48 + library/unistd_dup2.c | 149 ++ library/unistd_fchown.c | 91 + library/unistd_fdopen.c | 107 + library/unistd_fileno.c | 96 + library/unistd_ftruncate.c | 122 ++ library/unistd_getcwd.c | 224 ++ library/unistd_getopt.c | 163 ++ library/unistd_getpid.c | 85 + library/unistd_headers.h | 78 + library/unistd_init_exit.c | 122 ++ library/unistd_isatty.c | 87 + library/unistd_lchown.c | 84 + library/unistd_link.c | 140 ++ library/unistd_readlink.c | 180 ++ library/unistd_realpath.c | 151 ++ library/unistd_restorepathname.c | 47 + library/unistd_setcurrentpath.c | 71 + library/unistd_sleep.c | 176 ++ library/unistd_strip_double_slash.c | 87 + library/unistd_symlink.c | 101 + library/unistd_translatea2u.c | 284 +++ library/unistd_translaterel.c | 103 + library/unistd_translateu2a.c | 504 +++++ library/unistd_truncate.c | 101 + library/unistd_unix_path_semantics.c | 40 + library/unistd_unlink.c | 191 ++ library/unistd_wildcard_expand.c | 381 ++++ library/unix.lib_rev.c | 38 + library/unix.lib_rev.h | 6 + library/unix.lib_rev.rev | 1 + library/usergroup_crypt.c | 97 + library/usergroup_data.c | 63 + library/usergroup_endgrent.c | 69 + library/usergroup_endpwent.c | 69 + library/usergroup_getegid.c | 79 + library/usergroup_geteuid.c | 79 + library/usergroup_getgid.c | 79 + library/usergroup_getgrent.c | 72 + library/usergroup_getgrgid.c | 66 + library/usergroup_getgrnam.c | 89 + library/usergroup_getgroups.c | 97 + library/usergroup_getpass.c | 91 + library/usergroup_getpwent.c | 66 + library/usergroup_getpwnam.c | 89 + library/usergroup_getpwuid.c | 68 + library/usergroup_getuid.c | 73 + library/usergroup_headers.h | 778 +++++++ library/usergroup_init_exit.c | 147 ++ library/usergroup_initgroups.c | 90 + library/usergroup_rootmode.c | 48 + library/usergroup_setegid.c | 66 + library/usergroup_seteuid.c | 66 + library/usergroup_setgid.c | 77 + library/usergroup_setgrent.c | 63 + library/usergroup_setgroups.c | 97 + library/usergroup_setpwent.c | 63 + library/usergroup_setregid.c | 82 + library/usergroup_setreuid.c | 82 + library/usergroup_setsid.c | 66 + library/usergroup_setuid.c | 77 + library/utime_headers.h | 45 + library/utime_utime.c | 136 ++ library/wchar_btowc.c | 45 + library/wchar_fgetwc.c | 45 + library/wchar_fgetws.c | 45 + library/wchar_fputwc.c | 45 + library/wchar_fputws.c | 45 + library/wchar_fwide.c | 45 + library/wchar_fwprintf.c | 45 + library/wchar_fwscanf.c | 45 + library/wchar_getwc.c | 45 + library/wchar_getwchar.c | 45 + library/wchar_headers.h | 49 + library/wchar_mbrlen.c | 45 + library/wchar_mbsinit.c | 45 + library/wchar_mbsrtowcs.c | 45 + library/wchar_putwc.c | 45 + library/wchar_putwchar.c | 45 + library/wchar_swprintf.c | 45 + library/wchar_swscanf.c | 45 + library/wchar_ungetwc.c | 45 + library/wchar_vfwprintf.c | 45 + library/wchar_vswprintf.c | 45 + library/wchar_vwprintf.c | 45 + library/wchar_wcrtomb.c | 45 + library/wchar_wcscat.c | 45 + library/wchar_wcschr.c | 45 + library/wchar_wcscmp.c | 45 + library/wchar_wcscpy.c | 45 + library/wchar_wcsftime.c | 45 + library/wchar_wcslen.c | 45 + library/wchar_wcsncat.c | 45 + library/wchar_wcsncmp.c | 45 + library/wchar_wcsncpy.c | 45 + library/wchar_wcspbrk.c | 45 + library/wchar_wcsrtombs.c | 45 + library/wchar_wcsspn.c | 45 + library/wchar_wcstod.c | 49 + library/wchar_wcstok.c | 45 + library/wchar_wcstol.c | 45 + library/wchar_wcstoul.c | 45 + library/wchar_wcsxfrm.c | 45 + library/wchar_wmemchr.c | 45 + library/wchar_wmemcmp.c | 45 + library/wchar_wmemcpy.c | 45 + library/wchar_wmemmove.c | 45 + library/wchar_wmemset.c | 45 + library/wchar_wprintf.c | 45 + library/wchar_wscanf.c | 45 + library/wchar_wscoll.c | 45 + library/wctype_headers.h | 43 + library/wctype_iswalnum.c | 45 + library/wctype_iswalpha.c | 45 + library/wctype_iswcntrl.c | 45 + library/wctype_iswctype.c | 45 + library/wctype_iswdigit.c | 45 + library/wctype_iswgraph.c | 45 + library/wctype_iswlower.c | 45 + library/wctype_iswprint.c | 45 + library/wctype_iswpunc.c | 45 + library/wctype_iswspace.c | 45 + library/wctype_iswupper.c | 45 + library/wctype_iswxdigit.c | 45 + library/wctype_towctrans.c | 45 + library/wctype_towlower.c | 45 + library/wctype_towupper.c | 45 + library/wctype_wctrans.c | 45 + library/wctype_wctype.c | 45 + test_programs/clib-bug.c | 74 + test_programs/fgets_test.c | 41 + test_programs/iotest.c | 44 + test_programs/printf_g_test.c | 12 + test_programs/printf_test.c | 195 ++ test_programs/sscanf_test.c | 84 + test_programs/stack_extension_test.c | 31 + test_programs/stack_size_test.c | 15 + test_programs/test.c | 241 ++ test_programs/translate_test.c | 39 + 669 files changed, 80825 insertions(+) create mode 100644 documentation/README create mode 100644 library/GNUmakefile.68k create mode 100644 library/GNUmakefile.os4 create mode 100644 library/amiga.lib_rev.c create mode 100644 library/amiga.lib_rev.h create mode 100644 library/amiga.lib_rev.rev create mode 100644 library/amiga_acrypt.c create mode 100644 library/amiga_addtof.c create mode 100644 library/amiga_argarraydone.c create mode 100644 library/amiga_argarrayinit.c create mode 100644 library/amiga_argint.c create mode 100644 library/amiga_argstring.c create mode 100644 library/amiga_beginio.c create mode 100644 library/amiga_callhook.c create mode 100644 library/amiga_callhooka.asm create mode 100644 library/amiga_callhooka.c create mode 100644 library/amiga_coercemethod.c create mode 100644 library/amiga_createextio.c create mode 100644 library/amiga_createport.c create mode 100644 library/amiga_createstdio.c create mode 100644 library/amiga_createtask.c create mode 100644 library/amiga_deleteextio.c create mode 100644 library/amiga_deleteport.c create mode 100644 library/amiga_deletestdio.c create mode 100644 library/amiga_deletetask.c create mode 100644 library/amiga_domethod.c create mode 100644 library/amiga_dosupermethod.c create mode 100644 library/amiga_dotimer.c create mode 100644 library/amiga_fastrand.c create mode 100644 library/amiga_freeievents.c create mode 100644 library/amiga_hookentry.asm create mode 100644 library/amiga_hookentry.c create mode 100644 library/amiga_hotkey.c create mode 100644 library/amiga_invertstring.c create mode 100644 library/amiga_newlist.c create mode 100644 library/amiga_rangerand.c create mode 100644 library/amiga_remtof.c create mode 100644 library/amiga_setsuperattrs.c create mode 100644 library/amiga_timedelay.c create mode 100644 library/amiga_waitbeam.c create mode 100644 library/c.lib_rev.c create mode 100644 library/c.lib_rev.h create mode 100644 library/c.lib_rev.rev create mode 100644 library/crt0.S create mode 100644 library/crtbegin.c create mode 100644 library/crtend.c create mode 100644 library/ctype_headers.h create mode 100644 library/ctype_isalnum.c create mode 100644 library/ctype_isalpha.c create mode 100644 library/ctype_isascii.c create mode 100644 library/ctype_iscntrl.c create mode 100644 library/ctype_isdigit.c create mode 100644 library/ctype_isgraph.c create mode 100644 library/ctype_islower.c create mode 100644 library/ctype_isprint.c create mode 100644 library/ctype_ispunct.c create mode 100644 library/ctype_isspace.c create mode 100644 library/ctype_isupper.c create mode 100644 library/ctype_isxdigit.c create mode 100644 library/ctype_table.c create mode 100644 library/ctype_tolower.c create mode 100644 library/ctype_toupper.c create mode 100644 library/debug.c create mode 100644 library/debug.h create mode 100644 library/debug.lib_rev.c create mode 100644 library/debug.lib_rev.h create mode 100644 library/debug.lib_rev.rev create mode 100644 library/debug_cmpstrexec.c create mode 100644 library/debug_headers.h create mode 100644 library/debug_kcmpstr.c create mode 100644 library/debug_kdofmt.c create mode 100644 library/debug_kgetc.c create mode 100644 library/debug_kgetch1.c create mode 100644 library/debug_kgetch2.c create mode 100644 library/debug_kgetchar1.c create mode 100644 library/debug_kgetchar2.c create mode 100644 library/debug_kgetnum1.c create mode 100644 library/debug_kgetnum2.c create mode 100644 library/debug_kmaygetch.c create mode 100644 library/debug_kmaygetchar.c create mode 100644 library/debug_kprintf1.c create mode 100644 library/debug_kprintf2.c create mode 100644 library/debug_kputc.c create mode 100644 library/debug_kputch1.c create mode 100644 library/debug_kputch2.c create mode 100644 library/debug_kputchar1.c create mode 100644 library/debug_kputchar2.c create mode 100644 library/debug_kputfmt.c create mode 100644 library/debug_kputs1.c create mode 100644 library/debug_kputs2.c create mode 100644 library/debug_kputstr1.c create mode 100644 library/debug_kputstr2.c create mode 100644 library/debug_kvprintf1.c create mode 100644 library/debug_kvprintf2.c create mode 100644 library/debug_level.c create mode 100644 library/dirent_closedir.c create mode 100644 library/dirent_data.c create mode 100644 library/dirent_headers.h create mode 100644 library/dirent_opendir.c create mode 100644 library/dirent_readdir.c create mode 100644 library/dirent_rewinddir.c create mode 100644 library/errno_data.c create mode 100644 library/fcntl_close.c create mode 100644 library/fcntl_creat.c create mode 100644 library/fcntl_fcntl.c create mode 100644 library/fcntl_headers.h create mode 100644 library/fcntl_lseek.c create mode 100644 library/fcntl_open.c create mode 100644 library/fcntl_read.c create mode 100644 library/fcntl_write.c create mode 100644 library/include/assert.h create mode 100644 library/include/ctype.h create mode 100644 library/include/dirent.h create mode 100644 library/include/dos.h create mode 100644 library/include/errno.h create mode 100644 library/include/fcntl.h create mode 100644 library/include/float.h create mode 100644 library/include/grp.h create mode 100644 library/include/iso646.h create mode 100644 library/include/libgen.h create mode 100644 library/include/limits.h create mode 100644 library/include/locale.h create mode 100644 library/include/math.h create mode 100644 library/include/pwd.h create mode 100644 library/include/setjmp.h create mode 100644 library/include/signal.h create mode 100644 library/include/stdarg.h create mode 100644 library/include/stddef.h create mode 100644 library/include/stdio.h create mode 100644 library/include/stdlib.h create mode 100644 library/include/string.h create mode 100644 library/include/strings.h create mode 100644 library/include/sys/amigaos-va.h create mode 100644 library/include/sys/mount.h create mode 100644 library/include/sys/stat.h create mode 100644 library/include/sys/time.h create mode 100644 library/include/sys/types.h create mode 100644 library/include/time.h create mode 100644 library/include/unistd.h create mode 100644 library/include/utime.h create mode 100644 library/include/wchar.h create mode 100644 library/include/wctype.h create mode 100644 library/libgen_basename.c create mode 100644 library/libgen_dirname.c create mode 100644 library/locale_data.c create mode 100644 library/locale_headers.h create mode 100644 library/locale_init_exit.c create mode 100644 library/locale_localeconv.c create mode 100644 library/locale_setlocale.c create mode 100644 library/m.lib_rev.c create mode 100644 library/m.lib_rev.h create mode 100644 library/m.lib_rev.rev create mode 100644 library/m881.lib_rev.c create mode 100644 library/m881.lib_rev.h create mode 100644 library/m881.lib_rev.rev create mode 100644 library/macros.h create mode 100644 library/make_ctype_table.c create mode 100644 library/math_acos.c create mode 100644 library/math_adddf3.c create mode 100644 library/math_addsf3.c create mode 100644 library/math_asin.c create mode 100644 library/math_atan.c create mode 100644 library/math_atan2.c create mode 100644 library/math_ceil.c create mode 100644 library/math_cos.c create mode 100644 library/math_cosh.c create mode 100644 library/math_data.c create mode 100644 library/math_divdf3.c create mode 100644 library/math_divsf3.c create mode 100644 library/math_eqdf2.c create mode 100644 library/math_eqsf2.c create mode 100644 library/math_exp.c create mode 100644 library/math_extendsfdf2.c create mode 100644 library/math_fabs.c create mode 100644 library/math_fixdfsi.c create mode 100644 library/math_fixsfsi.c create mode 100644 library/math_fixunsdfsi.c create mode 100644 library/math_fixunssfsi.c create mode 100644 library/math_floatsidf.c create mode 100644 library/math_floatsisf.c create mode 100644 library/math_floor.c create mode 100644 library/math_fmod.c create mode 100644 library/math_fp_support.h create mode 100644 library/math_frexp.c create mode 100644 library/math_gedf2.c create mode 100644 library/math_gesf2.c create mode 100644 library/math_gtdf2.c create mode 100644 library/math_gtsf2.c create mode 100644 library/math_headers.h create mode 100644 library/math_init_exit.c create mode 100644 library/math_kernel_cos.c create mode 100644 library/math_kernel_expm1.c create mode 100644 library/math_kernel_rem_pio2.c create mode 100644 library/math_kernel_scalbn.c create mode 100644 library/math_kernel_sin.c create mode 100644 library/math_kernel_tan.c create mode 100644 library/math_ldexp.c create mode 100644 library/math_ledf2.c create mode 100644 library/math_lesf2.c create mode 100644 library/math_log.c create mode 100644 library/math_log10.c create mode 100644 library/math_ltdf2.c create mode 100644 library/math_ltsf2.c create mode 100644 library/math_modf.c create mode 100644 library/math_muldf3.c create mode 100644 library/math_mulsf3.c create mode 100644 library/math_nedf2.c create mode 100644 library/math_negdf2.c create mode 100644 library/math_negsf2.c create mode 100644 library/math_nesf2.c create mode 100644 library/math_pow.c create mode 100644 library/math_sin.c create mode 100644 library/math_sinh.c create mode 100644 library/math_sqrt.c create mode 100644 library/math_subdf3.c create mode 100644 library/math_subsf3.c create mode 100644 library/math_tan.c create mode 100644 library/math_tanh.c create mode 100644 library/math_truncdfsf2.c create mode 100644 library/mount_convertinfo.c create mode 100644 library/mount_fstatfs.c create mode 100644 library/mount_headers.h create mode 100644 library/mount_statfs.c create mode 100644 library/ncrt0.S create mode 100644 library/net.lib_rev.c create mode 100644 library/net.lib_rev.h create mode 100644 library/net.lib_rev.rev create mode 100644 library/nrcrt0.S create mode 100644 library/profile__mcount.c create mode 100644 library/profile_gmon.c create mode 100644 library/profile_gmon.h create mode 100644 library/profile_mcount.S create mode 100644 library/profile_profil.c create mode 100644 library/releasenotes create mode 100644 library/sas_cxamemcpy.asm create mode 100644 library/sas_cxamemset.asm create mode 100644 library/sas_cxferr.c create mode 100644 library/sas_cxv.asm create mode 100644 library/sas_cxv45.asm create mode 100644 library/sas_cxv54.asm create mode 100644 library/sas_profile.c create mode 100644 library/signal_checkabort.c create mode 100644 library/signal_data.c create mode 100644 library/signal_headers.h create mode 100644 library/signal_kill.c create mode 100644 library/signal_raise.c create mode 100644 library/signal_sigaddset.c create mode 100644 library/signal_sigblock.c create mode 100644 library/signal_sigemptyset.c create mode 100644 library/signal_sigmask.c create mode 100644 library/signal_signal.c create mode 100644 library/signal_sigprocmask.c create mode 100644 library/signal_sigsetmask.c create mode 100644 library/smakefile create mode 100644 library/socket_accept.c create mode 100644 library/socket_bind.c create mode 100644 library/socket_connect.c create mode 100644 library/socket_data.c create mode 100644 library/socket_get_descriptor.c create mode 100644 library/socket_gethostbyaddr.c create mode 100644 library/socket_gethostbyname.c create mode 100644 library/socket_gethostid.c create mode 100644 library/socket_gethostname.c create mode 100644 library/socket_getnetbyaddr.c create mode 100644 library/socket_getnetbyname.c create mode 100644 library/socket_getpeername.c create mode 100644 library/socket_getprotobyname.c create mode 100644 library/socket_getprotobynumber.c create mode 100644 library/socket_getservbyname.c create mode 100644 library/socket_getservbyport.c create mode 100644 library/socket_getsockname.c create mode 100644 library/socket_getsockopt.c create mode 100644 library/socket_headers.h create mode 100644 library/socket_hook_entry.c create mode 100644 library/socket_inet_addr.c create mode 100644 library/socket_inet_aton.c create mode 100644 library/socket_inet_lnaof.c create mode 100644 library/socket_inet_makeaddr.c create mode 100644 library/socket_inet_netof.c create mode 100644 library/socket_inet_network.c create mode 100644 library/socket_inet_ntoa.c create mode 100644 library/socket_init_exit.c create mode 100644 library/socket_ioctl.c create mode 100644 library/socket_isdaemon.c create mode 100644 library/socket_listen.c create mode 100644 library/socket_recv.c create mode 100644 library/socket_recvfrom.c create mode 100644 library/socket_recvmsg.c create mode 100644 library/socket_select.c create mode 100644 library/socket_send.c create mode 100644 library/socket_sendmsg.c create mode 100644 library/socket_sendto.c create mode 100644 library/socket_setsockopt.c create mode 100644 library/socket_shutdown.c create mode 100644 library/socket_socket.c create mode 100644 library/stack.lib_rev.c create mode 100644 library/stack.lib_rev.h create mode 100644 library/stack.lib_rev.rev create mode 100644 library/startup.c create mode 100644 library/stat_chmod.c create mode 100644 library/stat_convertfileinfo.c create mode 100644 library/stat_data.c create mode 100644 library/stat_fchmod.c create mode 100644 library/stat_fstat.c create mode 100644 library/stat_headers.h create mode 100644 library/stat_lstat.c create mode 100644 library/stat_mkdir.c create mode 100644 library/stat_rmdir.c create mode 100644 library/stat_stat.c create mode 100644 library/stat_umask.c create mode 100644 library/stdio_asprintf.c create mode 100644 library/stdio_clearerr.c create mode 100644 library/stdio_data.c create mode 100644 library/stdio_dropiobreadbuffer.c create mode 100644 library/stdio_duplicate_fd.c create mode 100644 library/stdio_fclose.c create mode 100644 library/stdio_fdhookentry.c create mode 100644 library/stdio_feof.c create mode 100644 library/stdio_ferror.c create mode 100644 library/stdio_fflush.c create mode 100644 library/stdio_fgetc.c create mode 100644 library/stdio_fgetpos.c create mode 100644 library/stdio_fgets.c create mode 100644 library/stdio_filliobreadbuffer.c create mode 100644 library/stdio_findvacantfdentry.c create mode 100644 library/stdio_findvacantiobentry.c create mode 100644 library/stdio_flush.c create mode 100644 library/stdio_flushiobwritebuffer.c create mode 100644 library/stdio_fopen.c create mode 100644 library/stdio_fprintf.c create mode 100644 library/stdio_fputc.c create mode 100644 library/stdio_fputs.c create mode 100644 library/stdio_fread.c create mode 100644 library/stdio_freopen.c create mode 100644 library/stdio_fscanf.c create mode 100644 library/stdio_fseek.c create mode 100644 library/stdio_fsetpos.c create mode 100644 library/stdio_ftell.c create mode 100644 library/stdio_fwrite.c create mode 100644 library/stdio_get_file_descriptor.c create mode 100644 library/stdio_getc.c create mode 100644 library/stdio_getchar.c create mode 100644 library/stdio_gets.c create mode 100644 library/stdio_growfdtable.c create mode 100644 library/stdio_growiobtable.c create mode 100644 library/stdio_headers.h create mode 100644 library/stdio_init_exit.c create mode 100644 library/stdio_initializefd.c create mode 100644 library/stdio_initializeiob.c create mode 100644 library/stdio_iobhookentry.c create mode 100644 library/stdio_isinfinity.c create mode 100644 library/stdio_isnotanumber.c create mode 100644 library/stdio_locksemaphorename.c create mode 100644 library/stdio_nostdio.c create mode 100644 library/stdio_openiob.c create mode 100644 library/stdio_perror.c create mode 100644 library/stdio_popen.c create mode 100644 library/stdio_printf.c create mode 100644 library/stdio_protos.h create mode 100644 library/stdio_putc.c create mode 100644 library/stdio_putchar.c create mode 100644 library/stdio_puts.c create mode 100644 library/stdio_remove.c create mode 100644 library/stdio_rename.c create mode 100644 library/stdio_rewind.c create mode 100644 library/stdio_scanf.c create mode 100644 library/stdio_setbuf.c create mode 100644 library/stdio_setvbuf.c create mode 100644 library/stdio_snprintf.c create mode 100644 library/stdio_sprintf.c create mode 100644 library/stdio_sscanf.c create mode 100644 library/stdio_sscanf_hook_entry.c create mode 100644 library/stdio_tmpfile.c create mode 100644 library/stdio_tmpnam.c create mode 100644 library/stdio_translateioerror.c create mode 100644 library/stdio_ungetc.c create mode 100644 library/stdio_vasprintf.c create mode 100644 library/stdio_vasprintf_hook_entry.c create mode 100644 library/stdio_vfprintf.c create mode 100644 library/stdio_vfscanf.c create mode 100644 library/stdio_vprintf.c create mode 100644 library/stdio_vsnprintf.c create mode 100644 library/stdio_vsnprintf_hook_entry.c create mode 100644 library/stdio_vsprintf.c create mode 100644 library/stdio_vsprintf_hook_entry.c create mode 100644 library/stdlib_abort.c create mode 100644 library/stdlib_abs.c create mode 100644 library/stdlib_alloca.c create mode 100644 library/stdlib_assertion_failure.c create mode 100644 library/stdlib_atexit.c create mode 100644 library/stdlib_atof.c create mode 100644 library/stdlib_atoi.c create mode 100644 library/stdlib_atol.c create mode 100644 library/stdlib_bsearch.c create mode 100644 library/stdlib_calloc.c create mode 100644 library/stdlib_checkdetach.c create mode 100644 library/stdlib_constructor.c create mode 100644 library/stdlib_constructor_begin.c create mode 100644 library/stdlib_constructor_end.c create mode 100644 library/stdlib_data.c create mode 100644 library/stdlib_default_pool_size.c create mode 100644 library/stdlib_default_puddle_size.c create mode 100644 library/stdlib_destructor.c create mode 100644 library/stdlib_detach.c create mode 100644 library/stdlib_disablerequesters.c create mode 100644 library/stdlib_div.c create mode 100644 library/stdlib_divmodsi3.c create mode 100644 library/stdlib_divsi3.c create mode 100644 library/stdlib_divsi4.c create mode 100644 library/stdlib_dosbase.c create mode 100644 library/stdlib_exit.c create mode 100644 library/stdlib_free.c create mode 100644 library/stdlib_gcc_help.h create mode 100644 library/stdlib_getdefstacksize.c create mode 100644 library/stdlib_getenv.c create mode 100644 library/stdlib_getsp.asm create mode 100644 library/stdlib_getsp.c create mode 100644 library/stdlib_headers.h create mode 100644 library/stdlib_init_exit.c create mode 100644 library/stdlib_isresident.c create mode 100644 library/stdlib_labs.c create mode 100644 library/stdlib_ldiv.c create mode 100644 library/stdlib_locale_utility.h create mode 100644 library/stdlib_machine_test.c create mode 100644 library/stdlib_main.c create mode 100644 library/stdlib_malloc.c create mode 100644 library/stdlib_math.c create mode 100644 library/stdlib_mblen.c create mode 100644 library/stdlib_mbstowcs.c create mode 100644 library/stdlib_mbtowc.c create mode 100644 library/stdlib_mem_debug.h create mode 100644 library/stdlib_mkdtemp.c create mode 100644 library/stdlib_mkstemp.c create mode 100644 library/stdlib_mktemp.c create mode 100644 library/stdlib_modsi3.c create mode 100644 library/stdlib_mulsi3.c create mode 100644 library/stdlib_never_free.c create mode 100644 library/stdlib_null_pointer_check.h create mode 100644 library/stdlib_protos.h create mode 100644 library/stdlib_putenv.c create mode 100644 library/stdlib_qsort.c create mode 100644 library/stdlib_rand.c create mode 100644 library/stdlib_realloc.c create mode 100644 library/stdlib_red_black.c create mode 100644 library/stdlib_setenv.c create mode 100644 library/stdlib_setjmp.asm create mode 100644 library/stdlib_setjmp.c create mode 100644 library/stdlib_setjmp.i create mode 100644 library/stdlib_shell_escape.c create mode 100644 library/stdlib_showerror.c create mode 100644 library/stdlib_socket.c create mode 100644 library/stdlib_srand.c create mode 100644 library/stdlib_stack_usage.c create mode 100644 library/stdlib_stackargbytes.c create mode 100644 library/stdlib_stackcheck.c create mode 100644 library/stdlib_stackextension.c create mode 100644 library/stdlib_stackminframe.c create mode 100644 library/stdlib_stackoverflow.c create mode 100644 library/stdlib_stacksafezone.c create mode 100644 library/stdlib_stacksize.c create mode 100644 library/stdlib_startup.c create mode 100644 library/stdlib_strtod.c create mode 100644 library/stdlib_strtol.c create mode 100644 library/stdlib_strtoul.c create mode 100644 library/stdlib_swapstack.asm create mode 100644 library/stdlib_swapstack.c create mode 100644 library/stdlib_sysbase.c create mode 100644 library/stdlib_system.c create mode 100644 library/stdlib_termination_message.c create mode 100644 library/stdlib_threshold.c create mode 100644 library/stdlib_udivmodsi3.c create mode 100644 library/stdlib_udivsi3.c create mode 100644 library/stdlib_udivsi4.c create mode 100644 library/stdlib_umodsi3.c create mode 100644 library/stdlib_unsetenv.c create mode 100644 library/stdlib_usergroup.c create mode 100644 library/stdlib_wcstombs.c create mode 100644 library/stdlib_wctomb.c create mode 100644 library/stdlib_wildcard_expand.c create mode 100644 library/string_bcmp.c create mode 100644 library/string_bcopy.c create mode 100644 library/string_bzero.c create mode 100644 library/string_headers.h create mode 100644 library/string_index.c create mode 100644 library/string_memchr.c create mode 100644 library/string_memcmp.c create mode 100644 library/string_memcpy.c create mode 100644 library/string_memmove.c create mode 100644 library/string_memset.c create mode 100644 library/string_rindex.c create mode 100644 library/string_strcat.c create mode 100644 library/string_strchr.c create mode 100644 library/string_strcmp.c create mode 100644 library/string_strcoll.c create mode 100644 library/string_strcpy.c create mode 100644 library/string_strcspn.c create mode 100644 library/string_strdup.c create mode 100644 library/string_strerror.c create mode 100644 library/string_strlen.c create mode 100644 library/string_strncat.c create mode 100644 library/string_strncmp.c create mode 100644 library/string_strncpy.c create mode 100644 library/string_strpbrk.c create mode 100644 library/string_strrchr.c create mode 100644 library/string_strspn.c create mode 100644 library/string_strstr.c create mode 100644 library/string_strtok.c create mode 100644 library/string_strxfrm.c create mode 100644 library/strings_headers.h create mode 100644 library/strings_strcasecmp.c create mode 100644 library/strings_strncasecmp.c create mode 100644 library/time_asctime.c create mode 100644 library/time_clock.c create mode 100644 library/time_converttime.c create mode 100644 library/time_ctime.c create mode 100644 library/time_data.c create mode 100644 library/time_difftime.c create mode 100644 library/time_gettimeofday.c create mode 100644 library/time_gmtime.c create mode 100644 library/time_headers.h create mode 100644 library/time_localtime.c create mode 100644 library/time_mktime.c create mode 100644 library/time_numbertostring.c create mode 100644 library/time_strftime.c create mode 100644 library/time_time.c create mode 100644 library/unistd_access.c create mode 100644 library/unistd_chdir.c create mode 100644 library/unistd_chown.c create mode 100644 library/unistd_currentpathname.c create mode 100644 library/unistd_data.c create mode 100644 library/unistd_dup.c create mode 100644 library/unistd_dup2.c create mode 100644 library/unistd_fchown.c create mode 100644 library/unistd_fdopen.c create mode 100644 library/unistd_fileno.c create mode 100644 library/unistd_ftruncate.c create mode 100644 library/unistd_getcwd.c create mode 100644 library/unistd_getopt.c create mode 100644 library/unistd_getpid.c create mode 100644 library/unistd_headers.h create mode 100644 library/unistd_init_exit.c create mode 100644 library/unistd_isatty.c create mode 100644 library/unistd_lchown.c create mode 100644 library/unistd_link.c create mode 100644 library/unistd_readlink.c create mode 100644 library/unistd_realpath.c create mode 100644 library/unistd_restorepathname.c create mode 100644 library/unistd_setcurrentpath.c create mode 100644 library/unistd_sleep.c create mode 100644 library/unistd_strip_double_slash.c create mode 100644 library/unistd_symlink.c create mode 100644 library/unistd_translatea2u.c create mode 100644 library/unistd_translaterel.c create mode 100644 library/unistd_translateu2a.c create mode 100644 library/unistd_truncate.c create mode 100644 library/unistd_unix_path_semantics.c create mode 100644 library/unistd_unlink.c create mode 100644 library/unistd_wildcard_expand.c create mode 100644 library/unix.lib_rev.c create mode 100644 library/unix.lib_rev.h create mode 100644 library/unix.lib_rev.rev create mode 100644 library/usergroup_crypt.c create mode 100644 library/usergroup_data.c create mode 100644 library/usergroup_endgrent.c create mode 100644 library/usergroup_endpwent.c create mode 100644 library/usergroup_getegid.c create mode 100644 library/usergroup_geteuid.c create mode 100644 library/usergroup_getgid.c create mode 100644 library/usergroup_getgrent.c create mode 100644 library/usergroup_getgrgid.c create mode 100644 library/usergroup_getgrnam.c create mode 100644 library/usergroup_getgroups.c create mode 100644 library/usergroup_getpass.c create mode 100644 library/usergroup_getpwent.c create mode 100644 library/usergroup_getpwnam.c create mode 100644 library/usergroup_getpwuid.c create mode 100644 library/usergroup_getuid.c create mode 100644 library/usergroup_headers.h create mode 100644 library/usergroup_init_exit.c create mode 100644 library/usergroup_initgroups.c create mode 100644 library/usergroup_rootmode.c create mode 100644 library/usergroup_setegid.c create mode 100644 library/usergroup_seteuid.c create mode 100644 library/usergroup_setgid.c create mode 100644 library/usergroup_setgrent.c create mode 100644 library/usergroup_setgroups.c create mode 100644 library/usergroup_setpwent.c create mode 100644 library/usergroup_setregid.c create mode 100644 library/usergroup_setreuid.c create mode 100644 library/usergroup_setsid.c create mode 100644 library/usergroup_setuid.c create mode 100644 library/utime_headers.h create mode 100644 library/utime_utime.c create mode 100644 library/wchar_btowc.c create mode 100644 library/wchar_fgetwc.c create mode 100644 library/wchar_fgetws.c create mode 100644 library/wchar_fputwc.c create mode 100644 library/wchar_fputws.c create mode 100644 library/wchar_fwide.c create mode 100644 library/wchar_fwprintf.c create mode 100644 library/wchar_fwscanf.c create mode 100644 library/wchar_getwc.c create mode 100644 library/wchar_getwchar.c create mode 100644 library/wchar_headers.h create mode 100644 library/wchar_mbrlen.c create mode 100644 library/wchar_mbsinit.c create mode 100644 library/wchar_mbsrtowcs.c create mode 100644 library/wchar_putwc.c create mode 100644 library/wchar_putwchar.c create mode 100644 library/wchar_swprintf.c create mode 100644 library/wchar_swscanf.c create mode 100644 library/wchar_ungetwc.c create mode 100644 library/wchar_vfwprintf.c create mode 100644 library/wchar_vswprintf.c create mode 100644 library/wchar_vwprintf.c create mode 100644 library/wchar_wcrtomb.c create mode 100644 library/wchar_wcscat.c create mode 100644 library/wchar_wcschr.c create mode 100644 library/wchar_wcscmp.c create mode 100644 library/wchar_wcscpy.c create mode 100644 library/wchar_wcsftime.c create mode 100644 library/wchar_wcslen.c create mode 100644 library/wchar_wcsncat.c create mode 100644 library/wchar_wcsncmp.c create mode 100644 library/wchar_wcsncpy.c create mode 100644 library/wchar_wcspbrk.c create mode 100644 library/wchar_wcsrtombs.c create mode 100644 library/wchar_wcsspn.c create mode 100644 library/wchar_wcstod.c create mode 100644 library/wchar_wcstok.c create mode 100644 library/wchar_wcstol.c create mode 100644 library/wchar_wcstoul.c create mode 100644 library/wchar_wcsxfrm.c create mode 100644 library/wchar_wmemchr.c create mode 100644 library/wchar_wmemcmp.c create mode 100644 library/wchar_wmemcpy.c create mode 100644 library/wchar_wmemmove.c create mode 100644 library/wchar_wmemset.c create mode 100644 library/wchar_wprintf.c create mode 100644 library/wchar_wscanf.c create mode 100644 library/wchar_wscoll.c create mode 100644 library/wctype_headers.h create mode 100644 library/wctype_iswalnum.c create mode 100644 library/wctype_iswalpha.c create mode 100644 library/wctype_iswcntrl.c create mode 100644 library/wctype_iswctype.c create mode 100644 library/wctype_iswdigit.c create mode 100644 library/wctype_iswgraph.c create mode 100644 library/wctype_iswlower.c create mode 100644 library/wctype_iswprint.c create mode 100644 library/wctype_iswpunc.c create mode 100644 library/wctype_iswspace.c create mode 100644 library/wctype_iswupper.c create mode 100644 library/wctype_iswxdigit.c create mode 100644 library/wctype_towctrans.c create mode 100644 library/wctype_towlower.c create mode 100644 library/wctype_towupper.c create mode 100644 library/wctype_wctrans.c create mode 100644 library/wctype_wctype.c create mode 100644 test_programs/clib-bug.c create mode 100644 test_programs/fgets_test.c create mode 100644 test_programs/iotest.c create mode 100644 test_programs/printf_g_test.c create mode 100644 test_programs/printf_test.c create mode 100644 test_programs/sscanf_test.c create mode 100644 test_programs/stack_extension_test.c create mode 100644 test_programs/stack_size_test.c create mode 100644 test_programs/test.c create mode 100644 test_programs/translate_test.c diff --git a/documentation/README b/documentation/README new file mode 100644 index 0000000..c324c32 --- /dev/null +++ b/documentation/README @@ -0,0 +1,235 @@ +An ISO 'C' (1994) compliant runtime library for the Amiga +========================================================= + +1. What is this? + +This is my attempt to get Samba 2.2.x ported to the Amiga. My first Amiga +port required SAS/C and a number of strange tricks had to be pulled to get +it to support the kind of environment Samba needed. But with the +introduction of Samba 2.2.x many of those tricks did not work any more, +which is why I decided to attack the problem at the root, namely the +runtime library. + +Because it was no longer possible to build Samba with SAS/C on the new +Amiga platform, the idea came up to move development to the GNU 'C' +compiler. This turned out to be a challenge due to its somewhat +underdeveloped runtime library and header files. Eventually, I decided to +rewrite that library from scratch. + + +2. What does it do? + +Using "'C' - A reference manual" as a reference I wrote a set of header +files, then proceeded to implement each single function referenced in them. +With few exceptions in the area of wide character support, the result +should be a feature complete implementation of the ISO 'C' (1994) runtime +library. + +Because Samba needs a few POSIX-like routines to be supported, the library +functionality is complemented by a set of routines described in "Advanced +programming in the Unix environent". This set is not complete, however. It +will have to grow even further to accomodate for Samba's needs, but this is +a good start. I specifically added hooks for integrating socket I/O at a +later point of time. + +This is not a portable implementation of the library in the sense that you +could move it from one 'C' compiler on one operating system to another. +This is an Amiga specific implementation. + +The library supports floating point math, which is limited to IEEE single +and double precision or M68881 inline math. There is no support for the +fast floating point (FFP) format or exclusive IEEE single precision. You +either get double precision (IEEE math) or extended precision (M68881 +inline math). What it is that you get is determined at compile time. Use +the IEEE_FLOATING_POINT_SUPPORT preprocessor symbol to activate IEEE math +code and the M68881_FLOATING_POINT_SUPPORT symbol for M68881 inline math. + +Not unlike SAS/C, you can configure a minimum stack size the program is to +use when it starts up. This is controlled via the '__stack_size' variable +(see "stdlib_main.c"). + +I added some amiga.lib and debug.lib functionality to the library, but +don't count on it to be complete. + + +3. What does it not do? + +This library is a departure from the typical 'C' runtime environments of +the past which had to run on all AmigaOS releases, down to Kickstart 1.1. +This very library was designed to take advantage of the routines available +since Kickstart 2.04 was introduced and virtually nobody ever put to use. +This helps to cut the code size, and it also helps to keep bugs out of the +library by falling back onto well-tested implementations. However, the +catch is that the code won't run under Kickstart 1.3 and below. But then +these operating system releases have been obsolete for more than a decade, +and you can always go back to a compiler environment which supports them. + +Practically all library routines are implemented in a sort of naïve +fashion. That is, they contain virtually no optimizations whatsoever. This +is particularly apparent in workhorses such as memset() or memmove(). But +then, the issue is easy testability and Amiga platform portability. + +There is very little support for amiga.lib functionality. There is +NewList(), HookEntry(), CallHook(), CallHookA(), the DoMethod() family, the +RexxVars family, but that's all. If you need more, you would have to +implement it yourself. Put another way, if you absolutely need +functionality that is only found in amiga.lib, you really shouldn't need in +in the first place. + + +4. Where does the source code come from? + +I originally thought that it might be helpful to piece this library +together from various sources, such as the BSD libc. Turned out that this +code was so 'portable' that it became much more complex than it ought to +be. Also, some side-effects were present which considerably changed the +behaviour of the library. For example, the BSD libc uses bcopy() as an +alias for memcpy(), and unlike memcpy() is documented to, bcopy() supports +overlapping copies. + +Eventually, I wrote virtually all the code myself, borrowing algorithmic +ideas from the BSD libc and the Manx Aztec 'C' runtime library. Because I +don't know much about the environment GCC expects, I borrowed code snippets +from libnix, which was written by Matthias Fleischer and Gunther Nikl. This +in particular concerns the integer and floating point math support, the +setjmp/longjmp routines and the startup code. The M68881 inline math code +comes from the file written by Matthew Self +(self@bayes.arc.nasa.gov). + + +5. Limitations and caveats + +There is hardly any documentation on the code I wrote. In part this is due +to the fact that the code itself is very simple in design. It should speak +for itself. However, to make a usable runtime library you have to have a +user documentation as in man pages or autodocs. We will eventually have to +have autodocs for this library. + +The code is currently plastered with assertions and debug code. It is +therefore much larger than it ought to be and runs much slower than it +ought to be. For example, the malloc() routine will set the contents of the +memory allocated to a 'dirty' bit pattern which is likely to break software +which makes assumptions about its contents. Likewise, the free() routine +will trash the memory to deallocate with a different 'dirty' bit pattern to +turn up reuse of memory after deallocation. All these debugging features +can be disabled by defining the NDEBUG preprocessor symbol at compile time +(see ). + +The exception handling in the math code is not particularly effective. For +one part this is due to the fact that there is no exception handler +installed by the runtime library when it starts up which could catch and +process the error conditions the CPU or FPU generates. The idea was to +provide for a portable runtime library with little to no assembly language +involved. To make the exception handling complete, such code would be +necessary. + +The library currently builds under SAS/C, but because the 'normal' program +startup code is not utilized, the base relative (A4) addressing does not +work. If you are going to test it, use the data=faronly option to compile +the library and the programs. + +If you are going to rebuild the library with SAS/C you will need to +reassign INCLUDE: to point to the local 'include' directory or things won't +work. + + +6. Conventions and design issues + +You will have noticed the 330+ files in this directory. This is not the +best way to organize a runtime library, but at least all the bits and +pieces are in plain sight. Each file stands for the one or two routines it +contains. The name indicates what routine(s) that might be. Each file name +is prefixed by the name of the header file in which the corresponding +routine is defined. So, for example, you will find that "unistd_lchown.c" +contains the definition of the lchown() routine, which has its prototype +defined in the header file. + +Internal function and variable names are prefixed with two underscores, as +in '__stdio_init()'. + +All routines attempt to do error checking on their parameters. They will +either drop into an assert() or set an errno value and refuse to go any +further. This cuts performance but should help to catch the simple bugs +quite easily (NULL pointers). + +Just like any halfway sane Amiga 'C' runtime library, this one performs its +^C checking in the I/O routines. Typically once upon entry and in every +iteration of the loop there might be it will quickly poll the ^C signal and +drop into raise(SIGINT) in case the signal is set. This is just about the +safest method to solve the problem and should be much more robust than the +ixemul approach of 'interrupt anywhere - crash anywhere' using the task +switch/launch hooks to test for signals. + +By default all library routines follow the ISO 'C' conventions in that +where implementation defined behaviour is permitted, the AmigaOS rules are +followed. For example, unlink() will by default operate like DeleteFile() +and rename() will return with an error code set if the name of the +file/directory to be renamed would collide with an existing directory +entry. However, your program can set a global variable '__unix_semantics' +which will cause some routines to perform like their Unix counterparts. +This is necessary for Samba to work but not a generally desirable feature. +You have some Unix-like behaviour, but the environment itself is not +completely Unix- or POSIX-compliant. And it shouldn't be. Don't make the +mistake of trying to mold the environment into a POSIX emulation. It +doesn't work; AmigaOS is not Unix. + + +7. The startup code + +There are three program startup files provided. The most simplistic is in +'startup.c' which I use for SAS/C. It just invokes the setup routine which +eventually calls main() and drops straight into exit(). + +The ncrt0.S file was adapted from the libnix startup code which sets up the +base relative data area, if necessary (the SMALL_DATA preprocessor symbol +must be defined). + +The nrcrt0.S file was adapted from libnix startup code, too, and sets up +the base relative data area for programs to be made resident. Note that the +geta4() stub is missing here; it wouldn't work in a resident program +anyway. + +The ncrt0.S and nrcrt0.S files are considerably smaller and less complex +than the libnix code they are based on. This is because in this library +design all the more complex tasks are performed in the stdlib_main.c file +rather than in assembly language. + + +8. Documentation + +Well, you're reading it. There isn't anything much yet. You can consult the book +"'C' - A reference manual" and you could look at the Open Group's Single Unix +Specification at . + + +9. Legal status + +Because this library is in part based upon free software it would be uncourteous +not to make it free software itself. The BSD license would probably be +appropriate here. + +The PowerPC math library is based in part on work by Sun Microsystems: + +==================================================== +Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. +==================================================== + + + +10. Contacting the author + +The basic work was done by Olaf Barthel during two weeks in July 2002. You +can reach me at: + + Olaf Barthel + Gneisenaustr. 43 + D-31275 Lehrte + +Or via e-mail: + + olsen@sourcery.han.de diff --git a/library/GNUmakefile.68k b/library/GNUmakefile.68k new file mode 100644 index 0000000..0deeea4 --- /dev/null +++ b/library/GNUmakefile.68k @@ -0,0 +1,1003 @@ +# +# $Id: GNUmakefile.68k,v 1.1.1.1 2004-07-26 16:30:14 obarthel Exp $ +# +# :ts=8 +# + +############################################################################## + +CC = gcc +AR = ar -q +RANLIB = ranlib +COPY = copy clone +DELETE = delete all quiet +MAKEDIR = makedir +MAKE = make -f GNUmakefile.68k + +############################################################################## + +ifeq (,$(TYPE)) +LIBC_OBJS = libc_objs +LIBUNIX_OBJS = libunix_objs +LIBM_OBJS = libm_objs +LIBM881_OBJS = libm881_objs +LIBSTACK_OBJS = libstack_objs +LIBNET_OBJS = libnet_objs +LIBDEBUG_OBJS = libdebug_objs +LIBAMIGA_OBJS = libamiga_objs +else +LIBC_OBJS = $(TYPE)/libc_objs +LIBUNIX_OBJS = $(TYPE)/libunix_objs +LIBM_OBJS = $(TYPE)/libm_objs +LIBM881_OBJS = $(TYPE)/libm881_objs +LIBSTACK_OBJS = $(TYPE)/libstack_objs +LIBNET_OBJS = $(TYPE)/libnet_objs +LIBDEBUG_OBJS = $(TYPE)/libdebug_objs +LIBAMIGA_OBJS = $(TYPE)/libamiga_objs +endif + +############################################################################## + +.c.o: + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -DIEEE_FLOATING_POINT_SUPPORT $< + +$(LIBC_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):c]" + @$(CC) -o $(LIBC_OBJS)/$*.o -c $(CFLAGS) $< + +$(LIBUNIX_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):unix]" + @$(CC) -o $(LIBUNIX_OBJS)/$*.o -c $(CFLAGS) -DUNIX_PATH_SEMANTICS $< + +$(LIBM_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):m]" + @$(CC) -o $(LIBM_OBJS)/$*.o -c $(CFLAGS) -DIEEE_FLOATING_POINT_SUPPORT $< + +$(LIBM881_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):m881]" + @$(CC) -o $(LIBM881_OBJS)/$*.o -c $(CFLAGS) -DM68881_FLOATING_POINT_SUPPORT -m68881 $< + +$(LIBSTACK_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):stack]" + @$(CC) -o $(LIBSTACK_OBJS)/$*.o -c $(CFLAGS) -DSTACK_EXTENSION $< + +$(LIBNET_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):net]" + @$(CC) -o $(LIBNET_OBJS)/$*.o -c $(CFLAGS) -DSOCKET_SUPPORT -DUSERGROUP_SUPPORT $< + +$(LIBDEBUG_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):debug]" + @$(CC) -o $(LIBDEBUG_OBJS)/$*.o -c $(CFLAGS) $< + +$(LIBAMIGA_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):amiga]" + @$(CC) -o $(LIBAMIGA_OBJS)/$*.o -c $(CFLAGS) $< + +############################################################################## + +ifeq (small_data_020,$(TYPE)) +CODE_TYPE := -fbaserel -DSMALL_DATA -m68020-60 -DM68020 +endif + +ifeq (small_data,$(TYPE)) +CODE_TYPE := -fbaserel -DSMALL_DATA -m68000 +endif + +ifeq (small_data32,$(TYPE)) +CODE_TYPE := -fbaserel32 -DSMALL_DATA32 -m68020-60 -DM68020 +endif + +ifeq (large_data_020,$(TYPE)) +CODE_TYPE := -m68020-60 -DM68020 +endif + +ifeq (large_data,$(TYPE)) +CODE_TYPE := -m68000 +endif + +############################################################################## + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations -Wconversion + +INCLUDES = -Iinclude -I. -Inetinclude + OPTIONS = -DNDEBUG -fno-builtin -DNO_INLINE_STDARG +#OPTIONS = -D__MEM_DEBUG -fno-builtin +#OPTIONS = -DDEBUG -D__MEM_DEBUG -DNO_INLINE_STDARG -fno-builtin + OPTIMIZE = -O +#OPTIMIZE = -O2 -fomit-frame-pointer +#DEBUG = -g2 + +CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(CODE_TYPE) $(INCLUDES) + +############################################################################## + +C_LIB = \ + c.lib_rev.o \ + ctype_isalnum.o \ + ctype_isalpha.o \ + ctype_isascii.o \ + ctype_iscntrl.o \ + ctype_isdigit.o \ + ctype_isgraph.o \ + ctype_islower.o \ + ctype_isprint.o \ + ctype_ispunct.o \ + ctype_isspace.o \ + ctype_isupper.o \ + ctype_isxdigit.o \ + ctype_tolower.o \ + ctype_toupper.o \ + ctype_table.o \ + dirent_closedir.o \ + dirent_data.o \ + dirent_rewinddir.o \ + dirent_opendir.o \ + dirent_readdir.o \ + errno_data.o \ + fcntl_close.o \ + fcntl_creat.o \ + fcntl_fcntl.o \ + fcntl_lseek.o \ + fcntl_open.o \ + fcntl_read.o \ + fcntl_write.o \ + libgen_basename.o \ + libgen_dirname.o \ + locale_data.o \ + locale_init_exit.o \ + locale_localeconv.o \ + locale_setlocale.o \ + mount_convertinfo.o \ + mount_fstatfs.o \ + mount_statfs.o \ + signal_checkabort.o \ + signal_data.o \ + signal_kill.o \ + signal_raise.o \ + signal_sigaddset.o \ + signal_sigblock.o \ + signal_sigemptyset.o \ + signal_sigmask.o \ + signal_signal.o \ + signal_sigprocmask.o \ + signal_sigsetmask.o \ + stat_chmod.o \ + stat_convertfileinfo.o \ + stat_data.o \ + stat_fchmod.o \ + stat_fstat.o \ + stat_lstat.o \ + stat_mkdir.o \ + stat_rmdir.o \ + stat_stat.o \ + stat_umask.o \ + stdio_asprintf.o \ + stdio_clearerr.o \ + stdio_data.o \ + stdio_dropiobreadbuffer.o \ + stdio_duplicate_fd.o \ + stdio_fclose.o \ + stdio_fdhookentry.o \ + stdio_feof.o \ + stdio_ferror.o \ + stdio_fflush.o \ + stdio_flush.o \ + stdio_fgetc.o \ + stdio_fgetpos.o \ + stdio_fgets.o \ + stdio_filliobreadbuffer.o \ + stdio_findvacantfdentry.o \ + stdio_findvacantiobentry.o \ + stdio_flushiobwritebuffer.o \ + stdio_fopen.o \ + stdio_fprintf.o \ + stdio_fputc.o \ + stdio_fputs.o \ + stdio_fread.o \ + stdio_freopen.o \ + stdio_fscanf.o \ + stdio_fseek.o \ + stdio_fsetpos.o \ + stdio_ftell.o \ + stdio_fwrite.o \ + stdio_getc.o \ + stdio_getchar.o \ + stdio_get_file_descriptor.o \ + stdio_gets.o \ + stdio_growfdtable.o \ + stdio_growiobtable.o \ + stdio_initializefd.o \ + stdio_initializeiob.o \ + stdio_init_exit.o \ + stdio_iobhookentry.o \ + stdio_locksemaphorename.o \ + stdio_nostdio.o \ + stdio_openiob.o \ + stdio_perror.o \ + stdio_popen.o \ + stdio_printf.o \ + stdio_putc.o \ + stdio_putchar.o \ + stdio_puts.o \ + stdio_remove.o \ + stdio_rename.o \ + stdio_rewind.o \ + stdio_scanf.o \ + stdio_setbuf.o \ + stdio_setvbuf.o \ + stdio_snprintf.o \ + stdio_sprintf.o \ + stdio_sscanf.o \ + stdio_sscanf_hook_entry.o \ + stdio_tmpfile.o \ + stdio_tmpnam.o \ + stdio_translateioerror.o \ + stdio_ungetc.o \ + stdio_vasprintf.o \ + stdio_vasprintf_hook_entry.o \ + stdio_vfprintf.o \ + stdio_vfscanf.o \ + stdio_vprintf.o \ + stdio_vsnprintf.o \ + stdio_vsnprintf_hook_entry.o \ + stdio_vsprintf.o \ + stdio_vsprintf_hook_entry.o \ + stdlib_abort.o \ + stdlib_abs.o \ + stdlib_alloca.o \ + stdlib_assertion_failure.o \ + stdlib_atexit.o \ + stdlib_atoi.o \ + stdlib_atol.o \ + stdlib_bsearch.o \ + stdlib_calloc.o \ + stdlib_checkdetach.o \ + stdlib_constructor.o \ + stdlib_constructor_begin.o \ + stdlib_constructor_end.o \ + stdlib_data.o \ + stdlib_default_pool_size.o \ + stdlib_default_puddle_size.o \ + stdlib_destructor.o \ + stdlib_detach.o \ + stdlib_disablerequesters.o \ + stdlib_div.o \ + stdlib_divsi3.o \ + stdlib_divsi4.o \ + stdlib_dosbase.o \ + stdlib_exit.o \ + stdlib_free.o \ + stdlib_getdefstacksize.o \ + stdlib_getenv.o \ + stdlib_getsp.o \ + stdlib_init_exit.o \ + stdlib_isresident.o \ + stdlib_labs.o \ + stdlib_ldiv.o \ + stdlib_machine_test.o \ + stdlib_malloc.o \ + stdlib_math.o \ + stdlib_mkdtemp.o \ + stdlib_mkstemp.o \ + stdlib_mktemp.o \ + stdlib_modsi3.o \ + stdlib_mulsi3.o \ + stdlib_never_free.o \ + stdlib_putenv.o \ + stdlib_qsort.o \ + stdlib_rand.o \ + stdlib_realloc.o \ + stdlib_red_black.o \ + stdlib_setenv.o \ + stdlib_setjmp.o \ + stdlib_shell_escape.o \ + stdlib_showerror.o \ + stdlib_socket.o \ + stdlib_srand.o \ + stdlib_stackargbytes.o \ + stdlib_stackcheck.o \ + stdlib_stackoverflow.o \ + stdlib_stacksafezone.o \ + stdlib_stacksize.o \ + stdlib_stack_usage.o \ + stdlib_startup.o \ + stdlib_strtol.o \ + stdlib_strtoul.o \ + stdlib_swapstack.o \ + stdlib_sysbase.o \ + stdlib_system.o \ + stdlib_termination_message.o \ + stdlib_threshold.o \ + stdlib_udivsi3.o \ + stdlib_udivsi4.o \ + stdlib_umodsi3.o \ + stdlib_unsetenv.o \ + stdlib_usergroup.o \ + stdlib_wildcard_expand.o \ + strings_strcasecmp.o \ + strings_strncasecmp.o \ + string_bcmp.o \ + string_bcopy.o \ + string_bzero.o \ + string_index.o \ + string_memchr.o \ + string_memcmp.o \ + string_memcpy.o \ + string_memmove.o \ + string_memset.o \ + string_rindex.o \ + string_strcat.o \ + string_strchr.o \ + string_strcmp.o \ + string_strcoll.o \ + string_strcpy.o \ + string_strcspn.o \ + string_strdup.o \ + string_strerror.o \ + string_strlen.o \ + string_strncat.o \ + string_strncmp.o \ + string_strncpy.o \ + string_strpbrk.o \ + string_strrchr.o \ + string_strspn.o \ + string_strstr.o \ + string_strtok.o \ + string_strxfrm.o \ + time_asctime.o \ + time_clock.o \ + time_converttime.o \ + time_ctime.o \ + time_data.o \ + time_gettimeofday.o \ + time_gmtime.o \ + time_localtime.o \ + time_mktime.o \ + time_numbertostring.o \ + time_strftime.o \ + time_time.o \ + unistd_access.o \ + unistd_chdir.o \ + unistd_chown.o \ + unistd_currentpathname.o \ + unistd_data.o \ + unistd_dup.o \ + unistd_dup2.o \ + unistd_fchown.o \ + unistd_fdopen.o \ + unistd_fileno.o \ + unistd_ftruncate.o \ + unistd_getcwd.o \ + unistd_getopt.o \ + unistd_getpid.o \ + unistd_init_exit.o \ + unistd_isatty.o \ + unistd_lchown.o \ + unistd_link.o \ + unistd_readlink.o \ + unistd_realpath.o \ + unistd_sleep.o \ + unistd_symlink.o \ + unistd_truncate.o \ + unistd_unlink.o \ + utime_utime.o + +UNIX_LIB = \ + unix.lib_rev.o \ + dirent_closedir.o \ + dirent_data.o \ + dirent_rewinddir.o \ + dirent_opendir.o \ + dirent_readdir.o \ + fcntl_creat.o \ + fcntl_fcntl.o \ + fcntl_open.o \ + mount_convertinfo.o \ + mount_statfs.o \ + stat_chmod.o \ + stat_fstat.o \ + stat_lstat.o \ + stat_mkdir.o \ + stat_rmdir.o \ + stat_stat.o \ + stdio_fdhookentry.o \ + stdio_fflush.o \ + stdio_fopen.o \ + stdio_fopen.o \ + stdio_init_exit.o \ + stdio_locksemaphorename.o \ + stdio_openiob.o \ + stdio_popen.o \ + stdio_remove.o \ + stdio_rename.o \ + stdlib_mkdtemp.o \ + stdlib_mkstemp.o \ + stdlib_mkstemp.o \ + stdlib_mktemp.o \ + stdlib_system.o \ + unistd_access.o \ + unistd_chdir.o \ + unistd_chown.o \ + unistd_getcwd.o \ + unistd_lchown.o \ + unistd_link.o \ + unistd_readlink.o \ + unistd_realpath.o \ + unistd_restorepathname.o \ + unistd_setcurrentpath.o \ + unistd_strip_double_slash.o \ + unistd_translatea2u.o \ + unistd_translaterel.o \ + unistd_translateu2a.o \ + unistd_truncate.o \ + unistd_unix_path_semantics.o \ + unistd_unlink.o \ + unistd_wildcard_expand.o \ + utime_utime.o + +MATH_LIB = \ + math_acos.o \ + math_asin.o \ + math_atan.o \ + math_atan2.o \ + math_ceil.o \ + math_cos.o \ + math_cosh.o \ + math_data.o \ + math_exp.o \ + math_fabs.o \ + math_floor.o \ + math_fmod.o \ + math_frexp.o \ + math_init_exit.o \ + math_ldexp.o \ + math_log.o \ + math_log10.o \ + math_modf.o \ + math_pow.o \ + math_sin.o \ + math_sinh.o \ + math_sqrt.o \ + math_tan.o \ + math_tanh.o \ + stdio_asprintf.o \ + stdio_flush.o \ + stdio_fprintf.o \ + stdio_fscanf.o \ + stdio_isinfinity.o \ + stdio_isnotanumber.o \ + stdio_printf.o \ + stdio_scanf.o \ + stdio_snprintf.o \ + stdio_sprintf.o \ + stdio_sscanf.o \ + stdio_vasprintf.o \ + stdio_vfprintf.o \ + stdio_vfscanf.o \ + stdio_vfscanf.o \ + stdio_vprintf.o \ + stdio_vsnprintf.o \ + stdio_vsprintf.o \ + stdlib_atof.o \ + stdlib_machine_test.o \ + stdlib_strtod.o \ + time_difftime.o + +MATH_LIB_881 = \ + m881.lib_rev.o \ + $(MATH_LIB) + +MATH_LIB_IEEE = \ + m.lib_rev.o \ + $(MATH_LIB) \ + math_adddf3.o \ + math_addsf3.o \ + math_divdf3.o \ + math_divsf3.o \ + math_eqdf2.o \ + math_eqsf2.o \ + math_extendsfdf2.o \ + math_fixdfsi.o \ + math_fixsfsi.o \ + math_fixunsdfsi.o \ + math_fixunssfsi.o \ + math_floatsidf.o \ + math_floatsisf.o \ + math_gedf2.o \ + math_gesf2.o \ + math_gtdf2.o \ + math_gtsf2.o \ + math_ledf2.o \ + math_lesf2.o \ + math_ltdf2.o \ + math_ltsf2.o \ + math_muldf3.o \ + math_mulsf3.o \ + math_nedf2.o \ + math_negdf2.o \ + math_negsf2.o \ + math_nesf2.o \ + math_subdf3.o \ + math_subsf3.o \ + math_truncdfsf2.o + +STACK_LIB = \ + stack.lib_rev.o \ + stdlib_setjmp.o \ + stdlib_stackextension.o \ + stdlib_stackminframe.o \ + stdlib_stackoverflow.o \ + stdlib_stacksafezone.o + +NET_LIB = \ + net.lib_rev.o \ + socket_accept.o \ + socket_bind.o \ + socket_connect.o \ + socket_data.o \ + socket_gethostbyaddr.o \ + socket_gethostbyname.o \ + socket_gethostid.o \ + socket_gethostname.o \ + socket_getnetbyaddr.o \ + socket_getnetbyname.o \ + socket_getpeername.o \ + socket_getprotobyname.o \ + socket_getprotobynumber.o \ + socket_getservbyname.o \ + socket_getservbyport.o \ + socket_getsockname.o \ + socket_getsockopt.o \ + socket_get_descriptor.o \ + socket_inet_addr.o \ + socket_inet_aton.o \ + socket_inet_lnaof.o \ + socket_inet_makeaddr.o \ + socket_inet_netof.o \ + socket_inet_network.o \ + socket_inet_ntoa.o \ + socket_init_exit.o \ + socket_ioctl.o \ + socket_isdaemon.o \ + socket_listen.o \ + socket_recv.o \ + socket_recvfrom.o \ + socket_recvmsg.o \ + socket_select.o \ + socket_send.o \ + socket_sendmsg.o \ + socket_sendto.o \ + socket_setsockopt.o \ + socket_shutdown.o \ + socket_socket.o \ + socket_hook_entry.o \ + stat_umask.o \ + usergroup_crypt.o \ + usergroup_data.o \ + usergroup_endgrent.o \ + usergroup_endpwent.o \ + usergroup_getegid.o \ + usergroup_geteuid.o \ + usergroup_getgid.o \ + usergroup_getgrent.o \ + usergroup_getgrgid.o \ + usergroup_getgrnam.o \ + usergroup_getgroups.o \ + usergroup_getpass.o \ + usergroup_getpwent.o \ + usergroup_getpwnam.o \ + usergroup_getpwuid.o \ + usergroup_getuid.o \ + usergroup_initgroups.o \ + usergroup_init_exit.o \ + usergroup_rootmode.o \ + usergroup_setegid.o \ + usergroup_seteuid.o \ + usergroup_setgid.o \ + usergroup_setgrent.o \ + usergroup_setgroups.o \ + usergroup_setpwent.o \ + usergroup_setregid.o \ + usergroup_setreuid.o \ + usergroup_setsid.o \ + usergroup_setuid.o + +DEBUG_LIB = \ + debug.lib_rev.o \ + debug.o \ + debug_cmpstrexec.o \ + debug_kcmpstr.o \ + debug_kdofmt.o \ + debug_kgetc.o \ + debug_kgetch1.o \ + debug_kgetch2.o \ + debug_kgetchar1.o \ + debug_kgetchar2.o \ + debug_kgetnum1.o \ + debug_kgetnum2.o \ + debug_kmaygetch.o \ + debug_kmaygetchar.o \ + debug_kprintf1.o \ + debug_kprintf2.o \ + debug_kputc.o \ + debug_kputch1.o \ + debug_kputch2.o \ + debug_kputchar1.o \ + debug_kputchar2.o \ + debug_kputfmt.o \ + debug_kputs1.o \ + debug_kputs2.o \ + debug_kputstr1.o \ + debug_kputstr2.o \ + debug_kvprintf1.o \ + debug_kvprintf2.o \ + debug_level.o + +AMIGA_LIB = \ + amiga.lib_rev.o \ + amiga_acrypt.o \ + amiga_addtof.o \ + amiga_argarraydone.o \ + amiga_argarrayinit.o \ + amiga_argint.o \ + amiga_argstring.o \ + amiga_beginio.o \ + amiga_callhook.o \ + amiga_callhooka.o \ + amiga_coercemethod.o \ + amiga_createextio.o \ + amiga_createport.o \ + amiga_createstdio.o \ + amiga_createtask.o \ + amiga_deleteextio.o \ + amiga_deleteport.o \ + amiga_deletestdio.o \ + amiga_deletetask.o \ + amiga_domethod.o \ + amiga_dosupermethod.o \ + amiga_dotimer.o \ + amiga_fastrand.o \ + amiga_freeievents.o \ + amiga_hookentry.o \ + amiga_hotkey.o \ + amiga_invertstring.o \ + amiga_newlist.o \ + amiga_rangerand.o \ + amiga_remtof.o \ + amiga_setsuperattrs.o \ + amiga_timedelay.o \ + amiga_waitbeam.o + +############################################################################## + +LIBS_68K := $(LIBC_OBJS)/libc.a $(LIBSTACK_OBJS)/libstack.a $(LIBUNIX_OBJS)/libunix.a \ + $(LIBNET_OBJS)/libnet.a $(LIBDEBUG_OBJS)/libdebug.a $(LIBAMIGA_OBJS)/libamiga.a \ + $(LIBM_OBJS)/libm.a + LIBS_020 := $(LIBM881_OBJS)/libm881.a $(LIBS_68K) +#LIBS_020 := $(LIBS_68K) + +############################################################################## + +# The 881 math library won't build in plain 68k mode +ifneq (,$(findstring 68020,$(CODE_TYPE))) +LIBS := $(LIBS_020) +else +LIBS := $(LIBS_68K) +endif + +############################################################################## + +STARTUPS := nrcrt0.o nbcrt0.o nr32crt0.o nb32crt0.o ncrt0.o mainnb.o mainb.o mainb32.o + +############################################################################## + +all: \ + lib/libm020/libm.a \ + lib/libm.a \ + lib/libb/libm020/libm.a \ + lib/libb/libm.a \ + lib/libb32/libm020/libm.a \ + lib/nrcrt0.o \ + lib/nbcrt0.o \ + lib/ncrt0.o \ + lib/n32bcrt0.o \ + lib/n32rcrt0.o \ + lib/mainnb.o \ + lib/mainb.o \ + lib/mainb32.o + +############################################################################## + +clean: + -$(DELETE) $(TYPE) $(LIBS_020) $(STARTUPS) \ + $(LIBC_OBJS) $(LIBUNIX_OBJS) $(LIBM_OBJS) \ + $(LIBM881_OBJS) $(LIBSTACK_OBJS) $(LIBNET_OBJS) $(LIBDEBUG_OBJS) \ + $(LIBAMIGA_OBJS) + +realclean: + $(MAKE) clean + -$(DELETE) lib small_data_020 small_data small_data32 large_data_020 \ + large_data + +############################################################################## + +version: + copy clone c.lib_rev.rev amiga.lib_rev.rev + copy clone c.lib_rev.rev debug.lib_rev.rev + copy clone c.lib_rev.rev m.lib_rev.rev + copy clone c.lib_rev.rev m881.lib_rev.rev + copy clone c.lib_rev.rev net.lib_rev.rev + copy clone c.lib_rev.rev stack.lib_rev.rev + copy clone c.lib_rev.rev unix.lib_rev.rev + bumprev 1 amiga.lib + bumprev 1 c.lib + bumprev 1 debug.lib + bumprev 1 m.lib + bumprev 1 m881.lib + bumprev 1 net.lib + bumprev 1 stack.lib + bumprev 1 unix.lib + +############################################################################## + +cvs-tag: + cvs -q tag V1_`type c.lib_rev.rev` + +############################################################################## + +kitchen_sink: $(TYPE) $(LIBS) $(STARTUPS) + +############################################################################## + +ifneq (,$(TYPE)) +$(TYPE): + $(MAKEDIR) $@ +endif + +############################################################################## + +lib: + -$(MAKEDIR) $@ + +lib/libb : lib + -$(MAKEDIR) $@ + +lib/libb/libm020 : lib lib/libb + -$(MAKEDIR) $@ + +lib/libb32/libm020 : lib lib/libb32 + -$(MAKEDIR) $@ + +lib/libb32 : lib + -$(MAKEDIR) $@ + +lib/libm020 : lib + -$(MAKEDIR) $@ + +lib/libb/libm020/libm.a: lib lib/libb/libm020 + $(MAKE) TYPE=small_data_020 kitchen_sink + $(COPY) $(foreach file,$(LIBS_020),small_data_020/$(file)) lib/libb/libm020 + +lib/libb/libm.a: lib lib/libb + $(MAKE) TYPE=small_data kitchen_sink + $(COPY) $(foreach file,$(LIBS_68K),small_data/$(file)) lib/libb + +lib/libb32/libm020/libm.a: lib lib/libb32 lib/libb32/libm020 + $(MAKE) TYPE=small_data32 kitchen_sink + $(COPY) $(foreach file,$(LIBS_020),small_data32/$(file)) lib/libb32/libm020 + +lib/libm020/libm.a: lib lib/libm020 + $(MAKE) TYPE=large_data_020 kitchen_sink + $(COPY) $(foreach file,$(LIBS_020),large_data_020/$(file)) lib/libm020 + +lib/libm.a: lib + $(MAKE) TYPE=large_data kitchen_sink + $(COPY) $(foreach file,$(LIBS_68K),large_data/$(file)) lib + +lib/nrcrt0.o : lib nrcrt0.o + $(COPY) nrcrt0.o lib + +lib/nbcrt0.o : lib nbcrt0.o + $(COPY) nbcrt0.o lib + +lib/ncrt0.o : lib ncrt0.o + $(COPY) ncrt0.o lib + +lib/n32bcrt0.o : lib nb32crt0.o + $(COPY) nb32crt0.o lib + +lib/n32rcrt0.o : lib nr32crt0.o + $(COPY) nr32crt0.o lib + +lib/mainnb.o : lib mainnb.o + $(COPY) mainnb.o lib + +lib/mainb.o : lib mainb.o + $(COPY) mainb.o lib + +lib/mainb32.o : lib mainb32.o + $(COPY) mainb32.o lib + +############################################################################## + +$(LIBAMIGA_OBJS)/amiga_hookentry.o : amiga_hookentry.c + +$(LIBC_OBJS)/stdlib_getsp.o : stdlib_getsp.c + +$(LIBC_OBJS)/stdlib_swapstack.o : stdlib_swapstack.c + +$(LIBC_OBJS)/stdlib_setjmp.o : stdlib_setjmp.c + +$(LIBSTACK_OBJS)/stdlib_setjmp.o : stdlib_setjmp.c + +############################################################################## + +$(LIBC_OBJS)/c.lib_rev.o : c.lib_rev.c c.lib_rev.h + +$(LIBUNIX_OBJS)/unix.lib_rev.o : unix.lib_rev.c unix.lib_rev.h + +$(LIBM_OBJS)/m.lib_rev.o : m.lib_rev.c m.lib_rev.h + +$(LIBM881_OBJS)/m881.lib_rev.o : m881.lib_rev.c m881.lib_rev.h + +$(LIBSTACK_OBJS)/stack.lib_rev.o : stack.lib_rev.c stack.lib_rev.h + +$(LIBNET_OBJS)/net.lib_rev.o : net.lib_rev.c net.lib_rev.h + +$(LIBDEBUG_OBJS)/debug.lib_rev.o : debug.lib_rev.c debug.lib_rev.h + +$(LIBAMIGA_OBJS)/amiga.lib_rev.o : amiga.lib_rev.c amiga.lib_rev.h + +############################################################################## + +$(LIBC_OBJS)/stdlib_stacksize.o : stdlib_stacksize.c stdlib_gcc_help.h + +$(LIBC_OBJS)/stdlib_shell_escape.o : stdlib_shell_escape.c stdlib_gcc_help.h + +$(LIBC_OBJS)/stdlib_alloca.o : stdlib_alloca.c stdlib_mem_debug.h + +$(LIBC_OBJS)/stdlib_calloc.o : stdlib_calloc.c stdlib_mem_debug.h + +$(LIBC_OBJS)/stdlib_free.o : stdlib_free.c stdlib_mem_debug.h + +$(LIBC_OBJS)/stdlib_init_exit.o : stdlib_init_exit.c stdlib_mem_debug.h + +$(LIBC_OBJS)/stdlib_malloc.o : stdlib_malloc.c stdlib_mem_debug.h + +$(LIBC_OBJS)/stdlib_realloc.o : stdlib_realloc.c stdlib_mem_debug.h + +$(LIBC_OBJS)/stdlib_red_black.o : stdlib_red_black.c stdlib_mem_debug.h + +############################################################################## + +$(LIBC_OBJS) : + $(MAKEDIR) $@ + +$(LIBC_OBJS)/libc.a : $(LIBC_OBJS) $(foreach file,$(C_LIB),$(LIBC_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(C_LIB),$(LIBC_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +$(LIBUNIX_OBJS) : + $(MAKEDIR) $@ + +$(LIBUNIX_OBJS)/libunix.a : $(LIBUNIX_OBJS) $(foreach file,$(UNIX_LIB),$(LIBUNIX_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(UNIX_LIB),$(LIBUNIX_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +$(LIBM_OBJS) : + $(MAKEDIR) $@ + +$(LIBM_OBJS)/libm.a : $(LIBM_OBJS) $(foreach file,$(MATH_LIB_IEEE),$(LIBM_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(MATH_LIB_IEEE),$(LIBM_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +$(LIBM881_OBJS) : + $(MAKEDIR) $@ + +$(LIBM881_OBJS)/libm881.a : $(LIBM881_OBJS) $(foreach file,$(MATH_LIB_881),$(LIBM881_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(MATH_LIB_881),$(LIBM881_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +$(LIBSTACK_OBJS) : + $(MAKEDIR) $@ + +$(LIBSTACK_OBJS)/libstack.a : $(LIBSTACK_OBJS) $(foreach file,$(STACK_LIB),$(LIBSTACK_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(STACK_LIB),$(LIBSTACK_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +$(LIBNET_OBJS) : + $(MAKEDIR) $@ + +$(LIBNET_OBJS)/libnet.a : $(LIBNET_OBJS) $(foreach file,$(NET_LIB),$(LIBNET_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(NET_LIB),$(LIBNET_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +$(LIBDEBUG_OBJS) : + $(MAKEDIR) $@ + +$(LIBDEBUG_OBJS)/libdebug.a : $(LIBDEBUG_OBJS) $(foreach file,$(DEBUG_LIB),$(LIBDEBUG_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(DEBUG_LIB),$(LIBDEBUG_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +$(LIBAMIGA_OBJS) : + $(MAKEDIR) $@ + +$(LIBAMIGA_OBJS)/libamiga.a : $(LIBAMIGA_OBJS) $(foreach file,$(AMIGA_LIB),$(LIBAMIGA_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(AMIGA_LIB),$(LIBAMIGA_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +nrcrt0.o : nrcrt0.S + $(CC) -traditional -o $@ -c nrcrt0.S + +nr32crt0.o : nrcrt0.S + $(CC) -traditional -m68020 -DSMALL_DATA32 -o $@ -c nrcrt0.S + +nbcrt0.o : ncrt0.S + $(CC) -traditional -DSMALL_DATA -o $@ -c ncrt0.S + +nb32crt0.o : ncrt0.S + $(CC) -traditional -m68020 -DSMALL_DATA32 -o $@ -c ncrt0.S + +ncrt0.o : ncrt0.S + $(CC) -traditional -o $@ -c ncrt0.S + +mainb32.o : stdlib_main.c + $(CC) -o mainb32.o -c $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(INCLUDES) -fbaserel32 -DSMALL_DATA32 -m68020-60 -DM68020 stdlib_main.c + +mainb.o : stdlib_main.c + $(CC) -o mainb.o -c $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(INCLUDES) -fbaserel -DSMALL_DATA -m68000 stdlib_main.c + +mainnb.o : stdlib_main.c + $(CC) -o mainnb.o -c $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(INCLUDES) -m68000 stdlib_main.c + +############################################################################## + +#test: test.o ncrt0.o libc.a libunix.a libm.a libdebug.a libamiga.a +# $(CC) -Wl,--verbose $(CFLAGS) -DIEEE_FLOATING_POINT_SUPPORT \ +# -o $@ -nostdlib ncrt0.o test.o -L. -lm -lunix -ldebug -lc -lamiga + +#test: test.o ncrt0.o nbcrt0.o nrcrt0.o libc.a libunix.a libm.a libdebug.a libamiga.a +# $(CC) -resident -Wl,--verbose $(CFLAGS) -DIEEE_FLOATING_POINT_SUPPORT -fbaserel32 -DSMALL_DATA \ +# -o $@ -nostdlib nbcrt0.o test.o -L. -lm -lunix -ldebug -lc -lamiga + +test : test.c + gcc -o test test.c -D__MEM_DEBUG -DFLOATING_POINT_SUPPORT -Llib -lunix -lm + +#test: test.o ncrt0.o nbcrt0.o nrcrt0.o libc.a libunix.a libm.a libdebug.a libamiga.a +# $(CC) -resident -Wl,--verbose $(CFLAGS) -DIEEE_FLOATING_POINT_SUPPORT -fbaserel -DSMALL_DATA \ +# -o $@ -nostdlib nrcrt0.o test.o -L. -lm -lunix -ldebug -lc -lamiga + +############################################################################## + +mkid: + mkid -v #?.(c|h|asm|i) include/#?.(c|h|asm|i) include/sys/#?.(c|h|asm|i) + +update: + mkid -v -u diff --git a/library/GNUmakefile.os4 b/library/GNUmakefile.os4 new file mode 100644 index 0000000..4643daa --- /dev/null +++ b/library/GNUmakefile.os4 @@ -0,0 +1,883 @@ +# +# $Id: GNUmakefile.os4,v 1.1.1.1 2004-07-26 16:30:15 obarthel Exp $ +# +# :ts=8 +# +# -*- mode: makefile; -*- + +############################################################################## + +# You may have to tweak this for the native OS4 compiler +SDK_INCLUDE = $(V)/include +NET_INCLUDE = netinclude + +# These are for the cross compiler +CC = ppc-amigaos-gcc +AR = ppc-amigaos-ar -q +RANLIB = ppc-amigaos-ranlib +COPY = cp +DELETE = rm -r +MAKEDIR = mkdir + +# The following are for the native OS4 compiler +# CC = gcc +# AR = ar -q +# RANLIB = ranlib +# COPY = copy +# DELETE = delete all quiet +# MAKEDIR = makedir + +MAKE = make -f GNUmakefile.os4 + +############################################################################## + +ifeq (,$(TYPE)) +LIBC_OBJS = libc_objs +LIBUNIX_OBJS = libunix_objs +LIBM_OBJS = libm_objs +LIBSTACK_OBJS = libstack_objs +LIBNET_OBJS = libnet_objs +LIBDEBUG_OBJS = libdebug_objs +LIBAMIGA_OBJS = libamiga_objs +else +LIBC_OBJS = $(TYPE)/libc_objs +LIBUNIX_OBJS = $(TYPE)/libunix_objs +LIBM_OBJS = $(TYPE)/libm_objs +LIBSTACK_OBJS = $(TYPE)/libstack_objs +LIBNET_OBJS = $(TYPE)/libnet_objs +LIBDEBUG_OBJS = $(TYPE)/libdebug_objs +LIBAMIGA_OBJS = $(TYPE)/libamiga_objs +endif + +############################################################################## + +%.o : %.c + @echo "Compiling $<" + @$(CC) -c $(CFLAGS) -DPPC_FLOATING_POINT_SUPPORT $< + +$(LIBC_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):c]" + @$(CC) -o $(LIBC_OBJS)/$*.o -c $(CFLAGS) $< + +$(LIBUNIX_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):unix]" + @$(CC) -o $(LIBUNIX_OBJS)/$*.o -c $(CFLAGS) -DUNIX_PATH_SEMANTICS $< + +$(LIBM_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):m]" + @$(CC) -o $(LIBM_OBJS)/$*.o -c $(CFLAGS) -DPPC_FLOATING_POINT_SUPPORT $< + +$(LIBSTACK_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):stack]" + @$(CC) -o $(LIBSTACK_OBJS)/$*.o -c $(CFLAGS) $< + +$(LIBNET_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):net]" + @$(CC) -o $(LIBNET_OBJS)/$*.o -c $(CFLAGS) -I$(NET_INCLUDE) -DSOCKET_SUPPORT -DUSERGROUP_SUPPORT $< + +$(LIBDEBUG_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):debug]" + @$(CC) -o $(LIBDEBUG_OBJS)/$*.o -c $(CFLAGS) $< + +$(LIBAMIGA_OBJS)/%.o : %.c + @echo "Compiling $< [$(TYPE):amiga]" + @$(CC) -o $(LIBAMIGA_OBJS)/$*.o -c $(CFLAGS) $< + +############################################################################## + +ifeq (small_data,$(TYPE)) +CODE_TYPE := -msdata=sysv -DSMALL_DATA +endif + +ifeq (large_data,$(TYPE)) +CODE_TYPE := -msdata=data +endif + +############################################################################## + +WARNINGS = \ + -Wall -W -Wshadow -Wpointer-arith -Wsign-compare -Wmissing-prototypes \ + -Wundef -Wbad-function-cast -Wmissing-declarations -Wconversion + +INCLUDES = -Iinclude -I. -I$(SDK_INCLUDE) +OPTIONS = -DNDEBUG -DUSE_64_BIT_INTS -fno-builtin -D__USE_INLINE__ -Wa,-mregnames +OPTIMIZE = -O3 -fomit-frame-pointer -funroll-loops +#DEBUG = -g + +CFLAGS = $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(CODE_TYPE) $(INCLUDES) + +############################################################################## + +C_LIB = \ + c.lib_rev.o \ + ctype_isalnum.o \ + ctype_isalpha.o \ + ctype_isascii.o \ + ctype_iscntrl.o \ + ctype_isdigit.o \ + ctype_isgraph.o \ + ctype_islower.o \ + ctype_isprint.o \ + ctype_ispunct.o \ + ctype_isspace.o \ + ctype_isupper.o \ + ctype_isxdigit.o \ + ctype_tolower.o \ + ctype_toupper.o \ + ctype_table.o \ + dirent_closedir.o \ + dirent_data.o \ + dirent_opendir.o \ + dirent_readdir.o \ + dirent_rewinddir.o \ + errno_data.o \ + fcntl_close.o \ + fcntl_creat.o \ + fcntl_fcntl.o \ + fcntl_lseek.o \ + fcntl_open.o \ + fcntl_read.o \ + fcntl_write.o \ + libgen_basename.o \ + libgen_dirname.o \ + locale_data.o \ + locale_init_exit.o \ + locale_localeconv.o \ + locale_setlocale.o \ + mount_convertinfo.o \ + mount_fstatfs.o \ + mount_statfs.o \ + signal_checkabort.o \ + signal_data.o \ + signal_kill.o \ + signal_raise.o \ + signal_sigaddset.o \ + signal_sigblock.o \ + signal_sigemptyset.o \ + signal_sigmask.o \ + signal_signal.o \ + signal_sigprocmask.o \ + signal_sigsetmask.o \ + stat_chmod.o \ + stat_convertfileinfo.o \ + stat_data.o \ + stat_fchmod.o \ + stat_fstat.o \ + stat_lstat.o \ + stat_mkdir.o \ + stat_rmdir.o \ + stat_stat.o \ + stat_umask.o \ + stdio_asprintf.o \ + stdio_clearerr.o \ + stdio_data.o \ + stdio_dropiobreadbuffer.o \ + stdio_duplicate_fd.o \ + stdio_fclose.o \ + stdio_fdhookentry.o \ + stdio_feof.o \ + stdio_ferror.o \ + stdio_fflush.o \ + stdio_flush.o \ + stdio_fgetc.o \ + stdio_fgetpos.o \ + stdio_fgets.o \ + stdio_filliobreadbuffer.o \ + stdio_findvacantfdentry.o \ + stdio_findvacantiobentry.o \ + stdio_flushiobwritebuffer.o \ + stdio_fopen.o \ + stdio_fprintf.o \ + stdio_fputc.o \ + stdio_fputs.o \ + stdio_fread.o \ + stdio_freopen.o \ + stdio_fscanf.o \ + stdio_fseek.o \ + stdio_fsetpos.o \ + stdio_ftell.o \ + stdio_fwrite.o \ + stdio_getc.o \ + stdio_getchar.o \ + stdio_get_file_descriptor.o \ + stdio_gets.o \ + stdio_growfdtable.o \ + stdio_growiobtable.o \ + stdio_initializefd.o \ + stdio_initializeiob.o \ + stdio_init_exit.o \ + stdio_iobhookentry.o \ + stdio_locksemaphorename.o \ + stdio_nostdio.o \ + stdio_openiob.o \ + stdio_perror.o \ + stdio_popen.o \ + stdio_printf.o \ + stdio_putc.o \ + stdio_putchar.o \ + stdio_puts.o \ + stdio_remove.o \ + stdio_rename.o \ + stdio_rewind.o \ + stdio_scanf.o \ + stdio_setbuf.o \ + stdio_setvbuf.o \ + stdio_snprintf.o \ + stdio_sprintf.o \ + stdio_sscanf.o \ + stdio_sscanf_hook_entry.o \ + stdio_tmpfile.o \ + stdio_tmpnam.o \ + stdio_translateioerror.o \ + stdio_ungetc.o \ + stdio_vasprintf.o \ + stdio_vasprintf_hook_entry.o \ + stdio_vfprintf.o \ + stdio_vfscanf.o \ + stdio_vprintf.o \ + stdio_vsnprintf.o \ + stdio_vsnprintf_hook_entry.o \ + stdio_vsprintf.o \ + stdio_vsprintf_hook_entry.o \ + stdlib_abort.o \ + stdlib_abs.o \ + stdlib_alloca.o \ + stdlib_assertion_failure.o \ + stdlib_atexit.o \ + stdlib_atoi.o \ + stdlib_atol.o \ + stdlib_bsearch.o \ + stdlib_calloc.o \ + stdlib_data.o \ + stdlib_default_pool_size.o \ + stdlib_default_puddle_size.o \ + stdlib_destructor.o \ + stdlib_disablerequesters.o \ + stdlib_div.o \ + stdlib_modsi3.o \ + stdlib_divsi3.o \ + stdlib_divsi4.o \ + stdlib_umodsi3.o \ + stdlib_udivsi3.o \ + stdlib_udivsi4.o \ + stdlib_exit.o \ + stdlib_free.o \ + stdlib_getenv.o \ + stdlib_getsp.o \ + stdlib_init_exit.o \ + stdlib_labs.o \ + stdlib_ldiv.o \ + stdlib_getdefstacksize.o \ + stdlib_stackargbytes.o \ + stdlib_stack_usage.o \ + stdlib_checkdetach.o \ + stdlib_detach.o \ + stdlib_isresident.o \ + stdlib_sysbase.o \ + stdlib_dosbase.o \ + stdlib_machine_test.o \ + stdlib_malloc.o \ + stdlib_math.o \ + stdlib_mkdtemp.o \ + stdlib_mkstemp.o \ + stdlib_mktemp.o \ + stdlib_mulsi3.o \ + stdlib_never_free.o \ + stdlib_putenv.o \ + stdlib_qsort.o \ + stdlib_rand.o \ + stdlib_realloc.o \ + stdlib_red_black.o \ + stdlib_setenv.o \ + stdlib_setjmp.o \ + stdlib_shell_escape.o \ + stdlib_showerror.o \ + stdlib_socket.o \ + stdlib_srand.o \ + stdlib_stackcheck.o \ + stdlib_stackoverflow.o \ + stdlib_stacksafezone.o \ + stdlib_stacksize.o \ + stdlib_startup.o \ + stdlib_strtol.o \ + stdlib_strtoul.o \ + stdlib_swapstack.o \ + stdlib_system.o \ + stdlib_termination_message.o \ + stdlib_threshold.o \ + stdlib_unsetenv.o \ + stdlib_usergroup.o \ + stdlib_wildcard_expand.o \ + strings_strcasecmp.o \ + strings_strncasecmp.o \ + string_bcmp.o \ + string_bcopy.o \ + string_bzero.o \ + string_index.o \ + string_memchr.o \ + string_memcmp.o \ + string_memcpy.o \ + string_memmove.o \ + string_memset.o \ + string_rindex.o \ + string_strcat.o \ + string_strchr.o \ + string_strcmp.o \ + string_strcoll.o \ + string_strcpy.o \ + string_strcspn.o \ + string_strdup.o \ + string_strerror.o \ + string_strlen.o \ + string_strncat.o \ + string_strncmp.o \ + string_strncpy.o \ + string_strpbrk.o \ + string_strrchr.o \ + string_strspn.o \ + string_strstr.o \ + string_strtok.o \ + string_strxfrm.o \ + time_asctime.o \ + time_clock.o \ + time_converttime.o \ + time_ctime.o \ + time_data.o \ + time_gettimeofday.o \ + time_gmtime.o \ + time_localtime.o \ + time_mktime.o \ + time_numbertostring.o \ + time_strftime.o \ + time_time.o \ + unistd_access.o \ + unistd_chdir.o \ + unistd_chown.o \ + unistd_currentpathname.o \ + unistd_data.o \ + unistd_dup.o \ + unistd_dup2.o \ + unistd_fchown.o \ + unistd_fdopen.o \ + unistd_fileno.o \ + unistd_ftruncate.o \ + unistd_getcwd.o \ + unistd_getopt.o \ + unistd_getpid.o \ + unistd_init_exit.o \ + unistd_isatty.o \ + unistd_lchown.o \ + unistd_link.o \ + unistd_readlink.o \ + unistd_realpath.o \ + unistd_sleep.o \ + unistd_symlink.o \ + unistd_truncate.o \ + unistd_unlink.o \ + utime_utime.o + + +UNIX_LIB = \ + unix.lib_rev.o \ + dirent_closedir.o \ + dirent_data.o \ + dirent_opendir.o \ + dirent_readdir.o \ + dirent_rewinddir.o \ + fcntl_creat.o \ + fcntl_fcntl.o \ + fcntl_open.o \ + mount_convertinfo.o \ + mount_statfs.o \ + stat_chmod.o \ + stat_fstat.o \ + stat_lstat.o \ + stat_mkdir.o \ + stat_rmdir.o \ + stat_stat.o \ + stdio_fdhookentry.o \ + stdio_init_exit.o \ + stdio_locksemaphorename.o \ + stdio_openiob.o \ + stdio_fflush.o \ + stdio_fopen.o \ + stdio_fopen.o \ + stdio_popen.o \ + stdio_remove.o \ + stdio_rename.o \ + stdlib_mkdtemp.o \ + stdlib_mkstemp.o \ + stdlib_mkstemp.o \ + stdlib_mktemp.o \ + stdlib_system.o \ + unistd_access.o \ + unistd_chdir.o \ + unistd_chown.o \ + unistd_getcwd.o \ + unistd_lchown.o \ + unistd_link.o \ + unistd_readlink.o \ + unistd_realpath.o \ + unistd_restorepathname.o \ + unistd_setcurrentpath.o \ + unistd_strip_double_slash.o \ + unistd_translatea2u.o \ + unistd_translaterel.o \ + unistd_translateu2a.o \ + unistd_truncate.o \ + unistd_unix_path_semantics.o \ + unistd_unlink.o \ + unistd_wildcard_expand.o \ + utime_utime.o + +MATH_LIB = \ + math_acos.o \ + math_asin.o \ + math_atan.o \ + math_atan2.o \ + math_ceil.o \ + math_cos.o \ + math_cosh.o \ + math_data.o \ + math_exp.o \ + math_fabs.o \ + math_floor.o \ + math_fmod.o \ + math_frexp.o \ + math_init_exit.o \ + math_ldexp.o \ + math_log.o \ + math_log10.o \ + math_modf.o \ + math_pow.o \ + math_sin.o \ + math_sinh.o \ + math_sqrt.o \ + math_tan.o \ + math_tanh.o \ + math_kernel_expm1.o \ + math_kernel_scalbn.o \ + math_kernel_tan.o \ + math_kernel_cos.o \ + math_kernel_rem_pio2.o \ + math_kernel_sin.o \ + stdio_asprintf.o \ + stdio_flush.o \ + stdio_fprintf.o \ + stdio_fscanf.o \ + stdio_isinfinity.o \ + stdio_isnotanumber.o \ + stdio_printf.o \ + stdio_scanf.o \ + stdio_snprintf.o \ + stdio_sprintf.o \ + stdio_sscanf.o \ + stdio_vasprintf.o \ + stdio_vfprintf.o \ + stdio_vfscanf.o \ + stdio_vfscanf.o \ + stdio_vprintf.o \ + stdio_vsnprintf.o \ + stdio_vsprintf.o \ + stdlib_atof.o \ + stdlib_machine_test.o \ + stdlib_strtod.o \ + time_difftime.o + +MATH_LIB_IEEE = \ + m.lib_rev.o \ + $(MATH_LIB) \ + math_adddf3.o \ + math_addsf3.o \ + math_divdf3.o \ + math_divsf3.o \ + math_eqdf2.o \ + math_eqsf2.o \ + math_extendsfdf2.o \ + math_fixdfsi.o \ + math_fixsfsi.o \ + math_fixunsdfsi.o \ + math_fixunssfsi.o \ + math_floatsidf.o \ + math_floatsisf.o \ + math_gedf2.o \ + math_gesf2.o \ + math_gtdf2.o \ + math_gtsf2.o \ + math_ledf2.o \ + math_lesf2.o \ + math_ltdf2.o \ + math_ltsf2.o \ + math_muldf3.o \ + math_mulsf3.o \ + math_nedf2.o \ + math_negdf2.o \ + math_negsf2.o \ + math_nesf2.o \ + math_subdf3.o \ + math_subsf3.o \ + math_truncdfsf2.o + +STACK_LIB = \ + stack.lib_rev.o \ + stdlib_setjmp.o \ + stdlib_stackextension.o \ + stdlib_stackminframe.o \ + stdlib_stackoverflow.o \ + stdlib_stacksafezone.o + +NET_LIB = \ + net.lib_rev.o \ + socket_accept.o \ + socket_bind.o \ + socket_connect.o \ + socket_data.o \ + socket_gethostbyaddr.o \ + socket_gethostbyname.o \ + socket_gethostid.o \ + socket_gethostname.o \ + socket_getnetbyaddr.o \ + socket_getnetbyname.o \ + socket_getpeername.o \ + socket_getprotobyname.o \ + socket_getprotobynumber.o \ + socket_getservbyname.o \ + socket_getservbyport.o \ + socket_getsockname.o \ + socket_getsockopt.o \ + socket_get_descriptor.o \ + socket_inet_addr.o \ + socket_inet_aton.o \ + socket_inet_lnaof.o \ + socket_inet_makeaddr.o \ + socket_inet_netof.o \ + socket_inet_network.o \ + socket_inet_ntoa.o \ + socket_init_exit.o \ + socket_ioctl.o \ + socket_isdaemon.o \ + socket_listen.o \ + socket_recv.o \ + socket_recvfrom.o \ + socket_recvmsg.o \ + socket_select.o \ + socket_send.o \ + socket_sendmsg.o \ + socket_sendto.o \ + socket_setsockopt.o \ + socket_shutdown.o \ + socket_socket.o \ + socket_hook_entry.o \ + usergroup_crypt.o \ + usergroup_data.o \ + usergroup_endgrent.o \ + usergroup_endpwent.o \ + usergroup_getegid.o \ + usergroup_geteuid.o \ + usergroup_getgid.o \ + usergroup_getgrent.o \ + usergroup_getgrgid.o \ + usergroup_getgrnam.o \ + usergroup_getgroups.o \ + usergroup_getpass.o \ + usergroup_getpwent.o \ + usergroup_getpwnam.o \ + usergroup_getpwuid.o \ + usergroup_getuid.o \ + usergroup_initgroups.o \ + usergroup_init_exit.o \ + usergroup_rootmode.o \ + usergroup_setegid.o \ + usergroup_seteuid.o \ + usergroup_setgid.o \ + usergroup_setgrent.o \ + usergroup_setgroups.o \ + usergroup_setpwent.o \ + usergroup_setregid.o \ + usergroup_setreuid.o \ + usergroup_setsid.o \ + usergroup_setuid.o \ + stat_umask.o + +DEBUG_LIB = \ + debug.lib_rev.o \ + debug.o \ + debug_level.o \ + debug_cmpstrexec.o \ + debug_kcmpstr.o \ + debug_kdofmt.o \ + debug_kgetc.o \ + debug_kgetch1.o \ + debug_kgetch2.o \ + debug_kgetchar1.o \ + debug_kgetchar2.o \ + debug_kgetnum1.o \ + debug_kgetnum2.o \ + debug_kmaygetch.o \ + debug_kmaygetchar.o \ + debug_kprintf1.o \ + debug_kprintf2.o \ + debug_kputc.o \ + debug_kputch1.o \ + debug_kputch2.o \ + debug_kputchar1.o \ + debug_kputchar2.o \ + debug_kputfmt.o \ + debug_kputs1.o \ + debug_kputs2.o \ + debug_kputstr1.o \ + debug_kputstr2.o \ + debug_kvprintf1.o \ + debug_kvprintf2.o + +AMIGA_LIB = \ + amiga.lib_rev.o \ + amiga_acrypt.o \ + amiga_addtof.o \ + amiga_argarraydone.o \ + amiga_argarrayinit.o \ + amiga_argint.o \ + amiga_argstring.o \ + amiga_callhooka.o \ + amiga_coercemethod.o \ + amiga_createstdio.o \ + amiga_deletestdio.o \ + amiga_domethod.o \ + amiga_dosupermethod.o \ + amiga_dotimer.o \ + amiga_fastrand.o \ + amiga_freeievents.o \ + amiga_hotkey.o \ + amiga_invertstring.o \ + amiga_rangerand.o \ + amiga_remtof.o \ + amiga_setsuperattrs.o \ + amiga_timedelay.o \ + amiga_waitbeam.o + +############################################################################## + +LIBS := $(LIBC_OBJS)/libc.a $(LIBSTACK_OBJS)/libstack.a $(LIBUNIX_OBJS)/libunix.a \ + $(LIBDEBUG_OBJS)/libdebug.a $(LIBAMIGA_OBJS)/libamiga.a \ + $(LIBM_OBJS)/libm.a $(LIBNET_OBJS)/libnet.a + +############################################################################## + + +############################################################################## + +STARTUPS := crt0.o crtbegin.o crtend.o mainnb.o + +############################################################################## + +all: \ + lib/crt0.o \ + lib/crtbegin.o \ + lib/crtend.o \ + lib/mainnb.o \ + lib/libm.a + +copy: + $(COPY) $(foreach file,$(LIBS),large_data/$(file)) lib + +############################################################################## + +clean: + -$(DELETE) $(TYPE) $(STARTUPS) \ + $(LIBC_OBJS) $(LIBUNIX_OBJS) $(LIBM_OBJS) $(LIBSTACK_OBJS) $(LIBNET_OBJS) $(LIBDEBUG_OBJS) $(LIBAMIGA_OBJS) + +realclean: + $(MAKE) clean + -$(DELETE) lib small_data large_data + +############################################################################## + +version: + cp c.lib_rev.rev amiga.lib_rev.rev + cp c.lib_rev.rev debug.lib_rev.rev + cp c.lib_rev.rev m.lib_rev.rev + cp c.lib_rev.rev m881.lib_rev.rev + cp c.lib_rev.rev net.lib_rev.rev + cp c.lib_rev.rev stack.lib_rev.rev + cp c.lib_rev.rev unix.lib_rev.rev + bumprev 1 amiga.lib + bumprev 1 c.lib + bumprev 1 debug.lib + bumprev 1 m.lib + bumprev 1 m881.lib + bumprev 1 net.lib + bumprev 1 stack.lib + bumprev 1 unix.lib + +############################################################################## + +cvs-tag: + cvs -q tag V1_`cat c.lib_rev.rev` + +############################################################################## + +kitchen_sink: $(TYPE) $(LIBS) $(STARTUPS) + +############################################################################## + +ifneq (,$(TYPE)) +$(TYPE): + $(MAKEDIR) $@ +endif + +############################################################################## + +lib: + -$(MAKEDIR) $@ + +lib/libm.a: lib + $(MAKE) TYPE=large_data kitchen_sink + $(COPY) $(foreach file,$(LIBS),large_data/$(file)) lib + +lib/small-data/libm.a: lib lib/small-data + $(MAKE) TYPE=small_data kitchen_sink + $(COPY) $(foreach file,$(LIBS),small_data/$(file)) lib/small-data + +lib/crt0.o : lib crt0.o + $(COPY) crt0.o lib + +lib/crtbegin.o : lib crtbegin.o + $(COPY) crtbegin.o lib + +lib/crtend.o : lib crtend.o + $(COPY) crtend.o lib + +lib/mainnb.o : lib mainnb.o + $(COPY) mainnb.o lib + +lib/mainb.o : lib mainb.o + $(COPY) mainb.o lib + +############################################################################## + +$(LIBAMIGA_OBJS)/amiga_hookentry.o : amiga_hookentry.c + +$(LIBC_OBJS)/stdlib_getsp.o : stdlib_getsp.c + +$(LIBC_OBJS)/stdlib_swapstack.o : stdlib_swapstack.c + +$(LIBC_OBJS)/stdlib_setjmp.o : stdlib_setjmp.c + +$(LIBSTACK_OBJS)/stdlib_setjmp.o : stdlib_setjmp.c + +############################################################################## + +$(LIBC_OBJS)/stdlib_stacksize.o : stdlib_stacksize.c stdlib_gcc_help.h + +$(LIBC_OBJS)/stdlib_shell_escape.o : stdlib_shell_escape.c stdlib_gcc_help.h + +$(LIBC_OBJS)/stdlib_alloca.o : stdlib_alloca.c stdlib_mem_debug.h + +$(LIBC_OBJS)/stdlib_calloc.o : stdlib_calloc.c stdlib_mem_debug.h + +$(LIBC_OBJS)/stdlib_free.o : stdlib_free.c stdlib_mem_debug.h + +$(LIBC_OBJS)/stdlib_init_exit.o : stdlib_init_exit.c stdlib_mem_debug.h + +$(LIBC_OBJS)/stdlib_malloc.o : stdlib_malloc.c stdlib_mem_debug.h + +$(LIBC_OBJS)/stdlib_realloc.o : stdlib_realloc.c stdlib_mem_debug.h + +$(LIBC_OBJS)/stdlib_red_black.o : stdlib_red_black.c stdlib_mem_debug.h + +############################################################################## + +$(LIBC_OBJS) : + $(MAKEDIR) $@ + +$(LIBC_OBJS)/libc.a : $(LIBC_OBJS) $(foreach file,$(C_LIB),$(LIBC_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(C_LIB),$(LIBC_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +$(LIBUNIX_OBJS) : + $(MAKEDIR) $@ + +$(LIBUNIX_OBJS)/libunix.a : $(LIBUNIX_OBJS) $(foreach file,$(UNIX_LIB),$(LIBUNIX_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(UNIX_LIB),$(LIBUNIX_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +$(LIBM_OBJS) : + $(MAKEDIR) $@ + +$(LIBM_OBJS)/libm.a : $(LIBM_OBJS) $(foreach file,$(MATH_LIB_IEEE),$(LIBM_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(MATH_LIB_IEEE),$(LIBM_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +$(LIBSTACK_OBJS) : + $(MAKEDIR) $@ + +$(LIBSTACK_OBJS)/libstack.a : $(LIBSTACK_OBJS) $(foreach file,$(STACK_LIB),$(LIBSTACK_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(STACK_LIB),$(LIBSTACK_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +$(LIBNET_OBJS) : + $(MAKEDIR) $@ + +$(LIBNET_OBJS)/libnet.a : $(LIBNET_OBJS) $(foreach file,$(NET_LIB),$(LIBNET_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(NET_LIB),$(LIBNET_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +$(LIBDEBUG_OBJS) : + $(MAKEDIR) $@ + +$(LIBDEBUG_OBJS)/libdebug.a : $(LIBDEBUG_OBJS) $(foreach file,$(DEBUG_LIB),$(LIBDEBUG_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(DEBUG_LIB),$(LIBDEBUG_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +$(LIBAMIGA_OBJS) : + $(MAKEDIR) $@ + +$(LIBAMIGA_OBJS)/libamiga.a : $(LIBAMIGA_OBJS) $(foreach file,$(AMIGA_LIB),$(LIBAMIGA_OBJS)/$(file)) + -$(DELETE) $@ + @$(AR) $@ $(foreach file,$(AMIGA_LIB),$(LIBAMIGA_OBJS)/$(file)) + $(RANLIB) $@ + +############################################################################## + +crt0.o : crt0.S + @echo "Assembling $<" + @$(CC) -Wa,-mregnames -o crt0.o -c crt0.S + +bcrt0.o : crt0.S + @echo "Assembling $<" + @$(CC) -DSMALL_DATA -Wa,-mregnames -o bcrt0.o -c crt0.S + +mainnb.o : stdlib_main.c + @echo "Compiling $<" + @$(CC) -o mainnb.o -c $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(INCLUDES) -msdata=data stdlib_main.c + +mainb.o : stdlib_main.c + @echo "Compiling $<" + @$(CC) -o mainb.o -c $(WARNINGS) $(OPTIMIZE) $(DEBUG) $(OPTIONS) $(INCLUDES) -msdata=sysv -DSMALL_DATA stdlib_main.c + +############################################################################## + +mkid: +# mkid -v #?.(c|h|asm|i) include/#?.(c|h|asm|i) include/sys/#?.(c|h|asm|i) + mkid *.[ch] include/*.h include/sys/*.h + +update: + mkid -v -u diff --git a/library/amiga.lib_rev.c b/library/amiga.lib_rev.c new file mode 100644 index 0000000..e025e1d --- /dev/null +++ b/library/amiga.lib_rev.c @@ -0,0 +1,38 @@ +/* + * $Id: amiga.lib_rev.c,v 1.1.1.1 2004-07-26 16:30:15 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "amiga.lib_rev.h" + +/****************************************************************************/ + +char __amiga_lib_version[] = VERSTAG; diff --git a/library/amiga.lib_rev.h b/library/amiga.lib_rev.h new file mode 100644 index 0000000..13310d5 --- /dev/null +++ b/library/amiga.lib_rev.h @@ -0,0 +1,6 @@ +#define VERSION 1 +#define REVISION 165 +#define DATE "26.7.2004" +#define VERS "amiga.lib 1.165" +#define VSTRING "amiga.lib 1.165 (26.7.2004)\r\n" +#define VERSTAG "\0$VER: amiga.lib 1.165 (26.7.2004)" diff --git a/library/amiga.lib_rev.rev b/library/amiga.lib_rev.rev new file mode 100644 index 0000000..9e42f3e --- /dev/null +++ b/library/amiga.lib_rev.rev @@ -0,0 +1 @@ +165 diff --git a/library/amiga_acrypt.c b/library/amiga_acrypt.c new file mode 100644 index 0000000..736b3ea --- /dev/null +++ b/library/amiga_acrypt.c @@ -0,0 +1,102 @@ +/* + * $Id: amiga_acrypt.c,v 1.1.1.1 2004-07-26 16:30:16 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +#define OSIZE 12 + +/****************************************************************************/ + +UBYTE * +ACrypt(UBYTE * buffer, const UBYTE * password, const UBYTE * user) +{ + UBYTE * result = NULL; + LONG buf[OSIZE]; + LONG i,d,k; + + ENTER(); + + assert( buffer != NULL && password != NULL && user != NULL ); + + SHOWPOINTER(buffer); + SHOWSTRING(password); + SHOWSTRING(user); + + if(buffer == NULL || password == NULL || user == NULL) + { + SHOWMSG("invalid parameters"); + goto out; + } + + for(i = 0 ; i < OSIZE ; i++) + { + if((*password) != '\0') + d = (*password++); + else + d = i; + + if((*user) != '\0') + d += (*user++); + else + d += i; + + buf[i] = 'A' + d; + } + + for(i = 0 ; i < OSIZE ; i++) + { + for(k = 0 ; k < OSIZE ; k++) + buf[i] = (buf[i] + buf[OSIZE - k - 1]) % 53; + + buffer[i] = buf[i] + 'A'; + } + + buffer[OSIZE-1] = '\0'; + + SHOWSTRING(buffer); + + result = buffer; + + out: + + RETURN(result); + return(result); +} diff --git a/library/amiga_addtof.c b/library/amiga_addtof.c new file mode 100644 index 0000000..043dccd --- /dev/null +++ b/library/amiga_addtof.c @@ -0,0 +1,83 @@ +/* + * $Id: amiga_addtof.c,v 1.1.1.1 2004-07-26 16:30:16 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include + +/****************************************************************************/ + +#include +#include +#include + +/****************************************************************************/ + +#include "macros.h" + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +typedef LONG (* CFUNC)(APTR arg); + +/****************************************************************************/ + +static LONG INTERRUPT ASM +call_routine(REG(a1,struct Isrvstr *i)) +{ + CFUNC p = (CFUNC)i->ccode; + + (*p)(i->Carg); + + return(0); +} + +/****************************************************************************/ + +VOID +AddTOF(struct Isrvstr *i,CFUNC p,APTR arg) +{ + assert( i != NULL && p != NULL ); + + i->code = (long (*)())call_routine; + i->Iptr = i; + i->ccode = p; + i->Carg = arg; + + AddIntServer(INTB_VERTB,(struct Interrupt *)i); +} diff --git a/library/amiga_argarraydone.c b/library/amiga_argarraydone.c new file mode 100644 index 0000000..f8f89ce --- /dev/null +++ b/library/amiga_argarraydone.c @@ -0,0 +1,71 @@ +/* + * $Id: amiga_argarraydone.c,v 1.1.1.1 2004-07-26 16:30:16 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include + +/****************************************************************************/ + +#include +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +extern char **CXLIB_argarray; + +extern struct DiskObject * CXLIB_disko; + +/****************************************************************************/ + +VOID +ArgArrayDone(VOID) +{ + if(CXLIB_argarray != NULL) + { + FreeVec(CXLIB_argarray); + CXLIB_argarray = NULL; + } + + if(CXLIB_disko != NULL) + { + FreeDiskObject(CXLIB_disko); + CXLIB_disko = NULL; + } +} diff --git a/library/amiga_argarrayinit.c b/library/amiga_argarrayinit.c new file mode 100644 index 0000000..6147a11 --- /dev/null +++ b/library/amiga_argarrayinit.c @@ -0,0 +1,99 @@ +/* + * $Id: amiga_argarrayinit.c,v 1.1.1.1 2004-07-26 16:30:16 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#include + +/****************************************************************************/ + +#include +#include +#include +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +const unsigned char ** CXLIB_argarray; + +struct DiskObject * CXLIB_disko; + +/****************************************************************************/ + +STRPTR * +ArgArrayInit(LONG argc, CONST_STRPTR * argv) +{ + unsigned char ** result = NULL; + + if(argc != 0) /* run from CLI */ + { + int i; + + if(argc == 1) + goto out; /* skip command name */ + + CXLIB_argarray = (const unsigned char **)AllocVec(sizeof(char *) * argc,MEMF_ANY|MEMF_CLEAR); + if(CXLIB_argarray == NULL) + goto out; + + for(i = 1 ; i < argc ; i++) + CXLIB_argarray[i-1] = argv[i]; + + result = (unsigned char **)CXLIB_argarray; + } + else if (IconBase != NULL) + { + struct WBStartup * msg; + + /* run from WB */ + msg = (struct WBStartup *)argv; + + CXLIB_disko = GetDiskObject(msg->sm_ArgList[0].wa_Name); + if(CXLIB_disko == NULL) + goto out; + + result = (unsigned char **)CXLIB_disko->do_ToolTypes; + } + + out: + + return(result); +} diff --git a/library/amiga_argint.c b/library/amiga_argint.c new file mode 100644 index 0000000..1c7a765 --- /dev/null +++ b/library/amiga_argint.c @@ -0,0 +1,60 @@ +/* + * $Id: amiga_argint.c,v 1.1.1.1 2004-07-26 16:30:16 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include + +/****************************************************************************/ + +#include +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +LONG +ArgInt(CONST_STRPTR *tt,CONST_STRPTR entry,LONG default_val) +{ + STRPTR str; + + if(tt != NULL && IconBase != NULL && ((str = (STRPTR)FindToolType((STRPTR *)tt,(STRPTR)entry))) != NULL) + StrToLong(str,&default_val); + + return(default_val); +} diff --git a/library/amiga_argstring.c b/library/amiga_argstring.c new file mode 100644 index 0000000..bc08007 --- /dev/null +++ b/library/amiga_argstring.c @@ -0,0 +1,61 @@ +/* + * $Id: amiga_argstring.c,v 1.1.1.1 2004-07-26 16:30:16 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +STRPTR +ArgString(CONST_STRPTR *tt,CONST_STRPTR entry,CONST_STRPTR default_string) +{ + STRPTR result; + + if(tt != NULL && IconBase != NULL && ((result = (STRPTR)FindToolType((STRPTR *)tt,(STRPTR)entry))) != NULL) + return(result); + else + return((STRPTR)default_string); +} diff --git a/library/amiga_beginio.c b/library/amiga_beginio.c new file mode 100644 index 0000000..9a4a1e2 --- /dev/null +++ b/library/amiga_beginio.c @@ -0,0 +1,84 @@ +/* + * $Id: amiga_beginio.c,v 1.1.1.1 2004-07-26 16:30:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +/****************************************************************************/ + +#if defined(__SASC) + +VOID __begin_io(struct IORequest * ior); +#pragma libcall DeviceBase __begin_io 01e 901 + +#endif /* __SASC */ + +/****************************************************************************/ + +#if defined(__GNUC__) + +#define __begin_io(ior) ({ \ + struct IORequest * _BeginIO_ior = (ior); \ + { \ + register struct Library * const __BeginIO__bn __asm("a6") = (struct Library *) (DeviceBase);\ + register struct IORequest * __BeginIO_ior __asm("a1") = (_BeginIO_ior); \ + __asm volatile ("jsr a6@(-30:W)" \ + : \ + : "r"(__BeginIO__bn), "r"(__BeginIO_ior) \ + : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + } \ +}) + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +VOID +BeginIO(struct IORequest *ior) +{ + struct Device * DeviceBase; + + ENTER(); + + assert( ior != NULL && ior->io_Device != NULL ); + + DeviceBase = ior->io_Device; + __begin_io(ior); + + LEAVE(); +} diff --git a/library/amiga_callhook.c b/library/amiga_callhook.c new file mode 100644 index 0000000..dc9a2bd --- /dev/null +++ b/library/amiga_callhook.c @@ -0,0 +1,67 @@ +/* + * $Id: amiga_callhook.c,v 1.1.1.1 2004-07-26 16:30:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __PPC__ + +/****************************************************************************/ + +#include + +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +ULONG +CallHook(struct Hook *hook_ptr,Object *obj,...) +{ + ULONG result; + va_list arg; + + assert( hook_ptr != NULL ); + + va_start(arg,obj); + + result = CallHookA(hook_ptr,obj,(APTR)arg); + + va_end(arg); + + return(result); +} + +/****************************************************************************/ + +#endif /* __PPC__ */ diff --git a/library/amiga_callhooka.asm b/library/amiga_callhooka.asm new file mode 100644 index 0000000..91086da --- /dev/null +++ b/library/amiga_callhooka.asm @@ -0,0 +1,80 @@ +* +* $Id: amiga_callhooka.asm,v 1.1.1.1 2004-07-26 16:30:17 obarthel Exp $ +* +* :ts=8 +* +* Portable ISO 'C' (1994) runtime library for the Amiga computer +* Copyright (c) 2002-2004 by Olaf Barthel +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* - Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* - Neither the name of Olaf Barthel nor the names of contributors +* may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* + + section text,code + +h_Entry equ 8 + + xdef _CallHookA + +**************************************************************************** +* new hook standard +* use struct Hook (with minnode at the top) +* +* *** register calling convention: *** +* A0 - pointer to hook itself +* A1 - pointer to parameter packed ("message") +* A2 - Hook specific address data ("object," e.g, gadget ) +* +* *** C conventions: *** +* Note that parameters are in unusual register order: a0, a2, a1. +* This is to provide a performance boost for assembly language +* programming (the object in a2 is most frequently untouched). +* It is also no problem in "register direct" C function parameters. +* +* calling through a hook +* CallHook( hook, object, msgid, p1, p2, ... ); +* CallHookA( hook, object, msgpkt ); +* +* using a C function: CFunction( hook, object, message ); +* hook.h_Entry = HookEntry; +* hook.h_SubEntry = CFunction; +* +**************************************************************************** + +* C calling hook interface for prepared message packet +_CallHookA: + movem.l a2/a6,-(sp) + move.l 12(sp),a0 + move.l 16(sp),a2 + move.l 20(sp),a1 + pea.l hook_return(pc) + move.l h_Entry(a0),-(sp) + rts + +hook_return: + + movem.l (sp)+,a2/a6 + rts + + end diff --git a/library/amiga_callhooka.c b/library/amiga_callhooka.c new file mode 100644 index 0000000..725ce6b --- /dev/null +++ b/library/amiga_callhooka.c @@ -0,0 +1,93 @@ +/* + * $Id: amiga_callhooka.c,v 1.1.1.1 2004-07-26 16:30:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if (defined(__GNUC__) && !defined(__PPC__)) + +/****************************************************************************/ + +asm(" + +h_Entry = 8 + + .text + .even + +|--------------------------------------------------------------------------- +| new hook standard +| use struct Hook (with minnode at the top) +| +| *** register calling convention: *** +| A0 - pointer to hook itself +| A1 - pointer to parameter packed ('message') +| A2 - Hook specific address data ('object,' e.g, gadget ) +| +| *** C conventions: *** +| Note that parameters are in unusual register order: a0, a2, a1. +| This is to provide a performance boost for assembly language +| programming (the object in a2 is most frequently untouched). +| It is also no problem in 'register direct' C function parameters. +| +| calling through a hook +| CallHook( hook, object, msgid, p1, p2, ... ); +| CallHookA( hook, object, msgpkt ); +| +| using a C function: CFunction( hook, object, message ); +| hook.h_Entry = HookEntry; +| hook.h_SubEntry = CFunction; +| +|--------------------------------------------------------------------------- + +| C calling hook interface for prepared message packet + + .globl _CallHookA + +_CallHookA: + + moveml a2/a6,sp@- + moveal sp@(12),a0 + moveal sp@(16),a2 + moveal sp@(20),a1 + pea callhooka_return + movel a0@(h_Entry),sp@- + rts + +callhooka_return: + + moveml sp@+,a2/a6 + rts + +"); + +/****************************************************************************/ + +#endif /* __GNUC__ && !__PPC__ */ diff --git a/library/amiga_coercemethod.c b/library/amiga_coercemethod.c new file mode 100644 index 0000000..ea95cff --- /dev/null +++ b/library/amiga_coercemethod.c @@ -0,0 +1,93 @@ +/* + * $Id: amiga_coercemethod.c,v 1.1.1.1 2004-07-26 16:30:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __PPC__ + +/****************************************************************************/ + +#include +#include + +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +ULONG +CoerceMethodA(Class * cl,Object * obj,Msg msg) +{ + ULONG result = 0; + + ENTER(); + + SHOWPOINTER(cl); + SHOWPOINTER(obj); + SHOWPOINTER(msg); + + assert( cl != NULL && obj != NULL ); + + if(cl != NULL && obj != NULL) + result = CallHookA(&cl->cl_Dispatcher,obj,msg); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +ULONG +CoerceMethod(Class *cl, Object *obj, ULONG method_id, ...) +{ + ULONG result = 0; + + ENTER(); + + SHOWPOINTER(cl); + SHOWPOINTER(obj); + SHOWVALUE(method_id); + + assert( cl != NULL && obj != NULL ); + + if(cl != NULL && obj != NULL) + result = CoerceMethodA(cl,obj,(Msg)&method_id); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* __PPC__ */ diff --git a/library/amiga_createextio.c b/library/amiga_createextio.c new file mode 100644 index 0000000..94b604e --- /dev/null +++ b/library/amiga_createextio.c @@ -0,0 +1,62 @@ +/* + * $Id: amiga_createextio.c,v 1.1.1.1 2004-07-26 16:30:18 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +struct IORequest * +CreateExtIO(CONST struct MsgPort * port, LONG io_size) +{ + struct IORequest * result = NULL; + + assert( port != NULL && io_size > 0 ); + + if(port == NULL || io_size < (LONG)sizeof(*result)) + goto out; + + result = CreateIORequest(port,(ULONG)io_size); + + out: + + return(result); +} diff --git a/library/amiga_createport.c b/library/amiga_createport.c new file mode 100644 index 0000000..0bd3fa0 --- /dev/null +++ b/library/amiga_createport.c @@ -0,0 +1,69 @@ +/* + * $Id: amiga_createport.c,v 1.1.1.1 2004-07-26 16:30:18 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +struct MsgPort * +CreatePort(CONST_STRPTR name, LONG pri) +{ + struct MsgPort * result = NULL; + + assert( -128 <= pri && pri <= 127 ); + + if(pri < -128 || pri > 127) + goto out; + + result = CreateMsgPort(); + if(result != NULL && name != NULL) + { + result->mp_Node.ln_Name = (char *)name; + result->mp_Node.ln_Pri = pri; + + AddPort(result); + } + + out: + + return(result); +} diff --git a/library/amiga_createstdio.c b/library/amiga_createstdio.c new file mode 100644 index 0000000..2ea311d --- /dev/null +++ b/library/amiga_createstdio.c @@ -0,0 +1,62 @@ +/* + * $Id: amiga_createstdio.c,v 1.1.1.1 2004-07-26 16:30:18 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +struct IOStdReq * +CreateStdIO(CONST struct MsgPort * port) +{ + struct IOStdReq * result = NULL; + + assert( port != NULL ); + + if(port == NULL) + goto out; + + result = (struct IOStdReq *)CreateIORequest((struct MsgPort *)port,sizeof(*result)); + + out: + + return(result); +} diff --git a/library/amiga_createtask.c b/library/amiga_createtask.c new file mode 100644 index 0000000..05b2841 --- /dev/null +++ b/library/amiga_createtask.c @@ -0,0 +1,194 @@ +/* + * $Id: amiga_createtask.c,v 1.1.1.1 2004-07-26 16:30:18 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __PPC__ + +/****************************************************************************/ + +#include +#include +#include + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include "macros.h" +#include "debug.h" + +/****************************************************************************/ + +/* + * Create a task with given name, priority, and stack size. + * It will use the default exception and trap handlers for now. + */ + +/****************************************************************************/ + +/* the template for the mementries. Unfortunately, this is hard to + * do from C: mementries have unions, and they cannot be statically + * initialized... + * + * In the interest of simplicity I recreate the mem entry structures + * here with appropriate sizes. We will copy this to a local + * variable and set the stack size to what the user specified, + * then attempt to actually allocate the memory. + */ + +#define ME_TASK 0 +#define ME_STACK 1 + +#define NUM_MEM_ENTRIES 2 + +/****************************************************************************/ + +struct FakeMemEntry +{ + ULONG fme_Reqs; + ULONG fme_Size; +}; + +/****************************************************************************/ + +struct FakeMemList +{ + struct Node fml_Node; + UWORD fml_NumEntries; + struct FakeMemEntry fml_ME[NUM_MEM_ENTRIES]; +}; + +/****************************************************************************/ + +struct Task * +CreateTask(CONST_STRPTR name,LONG pri,CONST APTR init_pc,ULONG stack_size) +{ + struct Task * new_task; + struct FakeMemList fake_mem_list; + struct MemList * ml = NULL; + APTR result = NULL; + + ENTER(); + + SHOWSTRING(name); + SHOWVALUE(pri); + SHOWPOINTER(init_pc); + SHOWVALUE(stack_size); + + assert( name != NULL && (-128 <= pri && pri <= 127) && init_pc != NULL && stack_size > 0 ); + + if(name == NULL || pri < -128 || pri > 127 || init_pc == NULL || stack_size == 0) + { + SHOWMSG("invalid parameters"); + goto out; + } + + /* round the stack up to longwords... */ + stack_size = (stack_size + 3UL) & ~3UL; + + /* + * This will allocate two chunks of memory: task of PUBLIC + * and stack of PRIVATE + */ + memset(&fake_mem_list,0,sizeof(fake_mem_list)); + + fake_mem_list.fml_NumEntries = NUM_MEM_ENTRIES; + fake_mem_list.fml_ME[ME_TASK].fme_Reqs = MEMF_PUBLIC | MEMF_CLEAR; + fake_mem_list.fml_ME[ME_TASK].fme_Size = sizeof(struct Task); + fake_mem_list.fml_ME[ME_STACK].fme_Reqs = MEMF_ANY | MEMF_CLEAR; + fake_mem_list.fml_ME[ME_STACK].fme_Size = stack_size; + + ml = (struct MemList *)AllocEntry((struct MemList *)&fake_mem_list); + + /* Did the allocation succeed? */ + if(((LONG)ml) < 0) + { + SHOWMSG("memory allocation failed"); + + /* Note: if AllocEntry() fails, the entire allocation is + * released before the function returns with bit #31 + * set and the number of the slot that failed being + * returned. Thus, the return value is not a valid + * address that would need to be freed. + */ + ml = NULL; + goto out; + } + + /* set the stack accounting stuff */ + new_task = (struct Task *)ml->ml_ME[ME_TASK].me_Addr; + + new_task->tc_SPLower = ml->ml_ME[ME_STACK].me_Addr; + new_task->tc_SPUpper = (APTR)((ULONG)(new_task->tc_SPLower) + stack_size); + new_task->tc_SPReg = new_task->tc_SPUpper; + + /* misc task data structures */ + new_task->tc_Node.ln_Type = NT_TASK; + new_task->tc_Node.ln_Pri = pri; + new_task->tc_Node.ln_Name = (char *)name; + + /* add it to the tasks memory list */ + NewList(&new_task->tc_MemEntry); + AddHead(&new_task->tc_MemEntry,(struct Node *)ml); + + /* add the task to the system -- use the default final PC */ + + PROFILE_OFF(); + result = AddTask(new_task,init_pc,NULL); + PROFILE_ON(); + + if(result == NULL) + { + SHOWMSG("could not add task"); + goto out; + } + + /* Gobbled up by task. */ + ml = NULL; + + out: + + if(ml != NULL) + FreeEntry(ml); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* __PPC__ */ diff --git a/library/amiga_deleteextio.c b/library/amiga_deleteextio.c new file mode 100644 index 0000000..40840b7 --- /dev/null +++ b/library/amiga_deleteextio.c @@ -0,0 +1,54 @@ +/* + * $Id: amiga_deleteextio.c,v 1.1.1.1 2004-07-26 16:30:18 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +VOID +DeleteExtIO(struct IORequest * io) +{ + assert(io != NULL); + + if(io != NULL) + DeleteIORequest((struct IORequest *)io); +} diff --git a/library/amiga_deleteport.c b/library/amiga_deleteport.c new file mode 100644 index 0000000..bff883d --- /dev/null +++ b/library/amiga_deleteport.c @@ -0,0 +1,56 @@ +/* + * $Id: amiga_deleteport.c,v 1.1.1.1 2004-07-26 16:30:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +VOID +DeletePort(struct MsgPort * port) +{ + assert( port != NULL ); + + if(port->mp_Node.ln_Name != NULL) + RemPort(port); + + DeleteMsgPort(port); +} diff --git a/library/amiga_deletestdio.c b/library/amiga_deletestdio.c new file mode 100644 index 0000000..747146c --- /dev/null +++ b/library/amiga_deletestdio.c @@ -0,0 +1,52 @@ +/* + * $Id: amiga_deletestdio.c,v 1.1.1.1 2004-07-26 16:30:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +VOID +DeleteStdIO(struct IOStdReq * io) +{ + if(io != NULL) + DeleteIORequest((struct IORequest *)io); +} diff --git a/library/amiga_deletetask.c b/library/amiga_deletetask.c new file mode 100644 index 0000000..91ebdf2 --- /dev/null +++ b/library/amiga_deletetask.c @@ -0,0 +1,48 @@ +/* + * $Id: amiga_deletetask.c,v 1.1.1.1 2004-07-26 16:30:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +VOID +DeleteTask(struct Task *tc) +{ + RemTask(tc); +} diff --git a/library/amiga_domethod.c b/library/amiga_domethod.c new file mode 100644 index 0000000..059c070 --- /dev/null +++ b/library/amiga_domethod.c @@ -0,0 +1,100 @@ +/* + * $Id: amiga_domethod.c,v 1.1.1.1 2004-07-26 16:30:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __PPC__ + +/****************************************************************************/ + +#include +#include + +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +ULONG +DoMethodA(Object * obj,Msg msg) +{ + ULONG result = 0; + + ENTER(); + + SHOWPOINTER(obj); + SHOWPOINTER(msg); + + assert(obj != NULL); + + if(obj != NULL) + { + Class * cl; + + cl = OCLASS(obj); + + assert( cl != NULL ); + + if(cl != NULL) + result = CallHookA(&cl->cl_Dispatcher,obj,msg); + } + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +ULONG +DoMethod(Object *obj, ULONG method_id, ...) +{ + ULONG result = 0; + + ENTER(); + + SHOWPOINTER(obj); + SHOWVALUE(method_id); + + assert( obj != NULL ); + + if(obj != NULL) + result = DoMethodA(obj,(Msg)&method_id); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* __PPC__ */ diff --git a/library/amiga_dosupermethod.c b/library/amiga_dosupermethod.c new file mode 100644 index 0000000..48699a2 --- /dev/null +++ b/library/amiga_dosupermethod.c @@ -0,0 +1,93 @@ +/* + * $Id: amiga_dosupermethod.c,v 1.1.1.1 2004-07-26 16:30:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __PPC__ + +/****************************************************************************/ + +#include +#include + +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +ULONG +DoSuperMethodA(Class * cl, Object * obj, Msg msg) +{ + ULONG result = 0; + + ENTER(); + + SHOWPOINTER(cl); + SHOWPOINTER(obj); + SHOWPOINTER(msg); + + assert( cl != NULL && obj != NULL ); + + if(cl != NULL && obj != NULL) + result = CallHookA(&cl->cl_Super->cl_Dispatcher,obj,msg); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +ULONG +DoSuperMethod(Class *cl, Object *obj, ULONG method_id, ...) +{ + ULONG result = 0; + + ENTER(); + + SHOWPOINTER(cl); + SHOWPOINTER(obj); + SHOWVALUE(method_id); + + assert( cl != NULL && obj != NULL ); + + if(cl != NULL && obj != NULL) + result = DoSuperMethodA(cl,obj,(Msg)&method_id); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* __PPC__ */ diff --git a/library/amiga_dotimer.c b/library/amiga_dotimer.c new file mode 100644 index 0000000..cef8ff1 --- /dev/null +++ b/library/amiga_dotimer.c @@ -0,0 +1,113 @@ +/* + * $Id: amiga_dotimer.c,v 1.1.1.1 2004-07-26 16:30:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include "macros.h" +#include "debug.h" + +/****************************************************************************/ + +LONG +DoTimer(struct timeval *tv,LONG unit,LONG command) +{ + struct timerequest * tr = NULL; + struct MsgPort * mp; + LONG error; + + assert( tv != NULL ); + + mp = AllocVec(sizeof(*mp),MEMF_ANY|MEMF_PUBLIC|MEMF_CLEAR); + if(mp == NULL) + { + error = IOERR_OPENFAIL; + goto out; + } + + mp->mp_Node.ln_Type = NT_MSGPORT; + mp->mp_Flags = PA_SIGNAL; + mp->mp_SigBit = SIGB_SINGLE; + mp->mp_SigTask = FindTask(NULL); + NewList(&mp->mp_MsgList); + + tr = (struct timerequest *)CreateIORequest(mp,sizeof(*tr)); + if(tr == NULL) + { + error = IOERR_OPENFAIL; + goto out; + } + + error = OpenDevice(TIMERNAME,(ULONG)unit,(struct IORequest *)tr,0); + if(error != 0) + goto out; + + tr->tr_node.io_Command = command; + tr->tr_time.tv_secs = tv->tv_secs; + tr->tr_time.tv_micro = tv->tv_micro; + + PROFILE_OFF(); + + SetSignal(0,SIGF_SINGLE); + + error = DoIO((struct IORequest *)tr); + + PROFILE_ON(); + + tv->tv_secs = tr->tr_time.tv_secs; + tv->tv_micro = tr->tr_time.tv_micro; + + out: + + if(tr != NULL) + { + if(tr->tr_node.io_Device != NULL) + CloseDevice((struct IORequest *)tr); + + DeleteIORequest((struct IORequest *)tr); + } + + FreeVec(mp); + + return(error); +} diff --git a/library/amiga_fastrand.c b/library/amiga_fastrand.c new file mode 100644 index 0000000..712f335 --- /dev/null +++ b/library/amiga_fastrand.c @@ -0,0 +1,52 @@ +/* + * $Id: amiga_fastrand.c,v 1.1.1.1 2004-07-26 16:30:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +ULONG +FastRand(ULONG seed) +{ + ULONG value; + + value = seed + seed; + if(value < seed) + value ^= 0x1D872B41; + + return(value); +} diff --git a/library/amiga_freeievents.c b/library/amiga_freeievents.c new file mode 100644 index 0000000..8463939 --- /dev/null +++ b/library/amiga_freeievents.c @@ -0,0 +1,62 @@ +/* + * $Id: amiga_freeievents.c,v 1.1.1.1 2004-07-26 16:30:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +VOID +FreeIEvents(struct InputEvent * ie) +{ + struct InputEvent * next; + + while(ie != NULL) + { + next = ie->ie_NextEvent; + + FreeVec(ie); + + ie = next; + } +} diff --git a/library/amiga_hookentry.asm b/library/amiga_hookentry.asm new file mode 100644 index 0000000..6faec4e --- /dev/null +++ b/library/amiga_hookentry.asm @@ -0,0 +1,51 @@ +* +* $Id: amiga_hookentry.asm,v 1.1.1.1 2004-07-26 16:30:20 obarthel Exp $ +* +* :ts=8 +* +* Portable ISO 'C' (1994) runtime library for the Amiga computer +* Copyright (c) 2002-2004 by Olaf Barthel +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* - Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* - Neither the name of Olaf Barthel nor the names of contributors +* may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* + + section text,code + +h_SubEntry equ 12 + + xdef _HookEntry + +_HookEntry: + + move.l a1,-(sp) + move.l a2,-(sp) + move.l a0,-(sp) + move.l h_SubEntry(a0),a0 + jsr (a0) + lea 12(sp),sp + + rts + + end diff --git a/library/amiga_hookentry.c b/library/amiga_hookentry.c new file mode 100644 index 0000000..978f442 --- /dev/null +++ b/library/amiga_hookentry.c @@ -0,0 +1,61 @@ +/* + * $Id: amiga_hookentry.c,v 1.1.1.1 2004-07-26 16:30:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if (defined(__GNUC__) && !defined(__PPC__)) + +/****************************************************************************/ + +asm(" + +h_SubEntry = 12 + + .text + .even + + .globl _HookEntry + +_HookEntry: + + movel a1,sp@- + movel a2,sp@- + movel a0,sp@- + movel a0@(h_SubEntry:W),a0 + jsr a0@ + lea sp@(12:W),sp + rts + +"); + +/****************************************************************************/ + +#endif /* __GNUC__ && !__PPC__ */ diff --git a/library/amiga_hotkey.c b/library/amiga_hotkey.c new file mode 100644 index 0000000..1682c8b --- /dev/null +++ b/library/amiga_hotkey.c @@ -0,0 +1,78 @@ +/* + * $Id: amiga_hotkey.c,v 1.1.1.1 2004-07-26 16:30:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +CxObj * +HotKey(CONST_STRPTR descr,struct MsgPort * port,LONG ID) +{ + CxObj * result = NULL; + CxObj * filter = NULL; + + assert( descr != NULL && port != NULL ); + + if(CxBase == NULL) + goto out; + + filter = CxFilter(descr); + if(filter == NULL) + goto out; + + AttachCxObj(filter,CxSender(port,ID)); + AttachCxObj(filter,CxTranslate(NULL)); + + if(CxObjError(filter)) + goto out; + + result = filter; + + out: + + if(result == NULL && filter != NULL) + DeleteCxObjAll(filter); + + return(result); +} diff --git a/library/amiga_invertstring.c b/library/amiga_invertstring.c new file mode 100644 index 0000000..c3cacb0 --- /dev/null +++ b/library/amiga_invertstring.c @@ -0,0 +1,208 @@ +/* + * $Id: amiga_invertstring.c,v 1.1.1.1 2004-07-26 16:30:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include + +/****************************************************************************/ + +#include +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +static int +do_escape(int cc) +{ + int result; + + switch(cc) + { + case 'n': + case 'r': + + result = '\r'; + break; + + case 't': + + result = '\t'; + break; + + case '0': + + result = '\0'; + break; + + case '\\': + case '\"': + case '\'': + case '<': + + result = cc; + break; + + default: + + result = -1; + break; + } + + return(result); +} + +/****************************************************************************/ + +static ULONG +do_angle(STRPTR * strp, struct InputEvent *ie) +{ + ULONG result; + char * cp; + IX ix; + + /* find closing angle '>', put a null there */ + for(cp = (*strp) ; (*cp) ; cp++) + { + if((*cp) == '>') + { + (*cp) = '\0'; + break; + } + } + + result = ParseIX((*strp),&ix); + + if(cp != NULL) + { + (*cp) = '>'; /* fix it */ + (*strp) = cp; /* point to char following '>' */ + } + else + { + (*strp) = cp - 1; /* ++will point to terminating null */ + } + + if(result == 0) + { + /* use IX to describe a suitable InputEvent */ + ie->ie_Class = ix.ix_Class; + ie->ie_Code = ix.ix_Code; + ie->ie_Qualifier = ix.ix_Qualifier; + } + + return(result); +} + +/****************************************************************************/ + +extern VOID FreeIEvents(struct InputEvent *ie); + +/****************************************************************************/ + +struct InputEvent * +InvertString(CONST_STRPTR str, CONST struct KeyMap *km) +{ + /* bugs: + can't escape '>' + puts '\0' on closing angles */ + + /* allocate input event for each character in string */ + + struct InputEvent * result = NULL; + struct InputEvent * chain = NULL; + struct InputEvent * ie; + int cc; + + if(CxBase == NULL || str == NULL || (*str) == '\0') + goto out; + + do /* have checked that str is not null */ + { + /* allocate the next ie and link it in */ + ie = AllocVec(sizeof(*ie),MEMF_ANY|MEMF_CLEAR|MEMF_PUBLIC); + if(ie == NULL) + goto out; + + ie->ie_NextEvent = chain; + chain = ie; + + /* now fill in the input event */ + cc = (*str); + switch(cc) + { + case '<': + + str++; + + if(do_angle((STRPTR*)&str, ie) != 0) + goto out; + + break; + + case '\\': + + str++; + + cc = do_escape(*str); /* get escaped character */ + if(cc < 0) + goto out; + + /* fall through */ + + default: + + InvertKeyMap((ULONG) cc, ie, (struct KeyMap *)km); + break; + } + + str++; + } + while((*str) != '\0'); + + result = chain; + + out: + + if(result == NULL && chain != NULL) + FreeIEvents(chain); + + return(result); +} diff --git a/library/amiga_newlist.c b/library/amiga_newlist.c new file mode 100644 index 0000000..c0b7a9f --- /dev/null +++ b/library/amiga_newlist.c @@ -0,0 +1,60 @@ +/* + * $Id: amiga_newlist.c,v 1.1.1.1 2004-07-26 16:30:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +VOID +NewList(struct List *lh) +{ + ENTER(); + + SHOWPOINTER(lh); + + assert( lh != NULL ); + + lh->lh_Head = (struct Node *)&lh->lh_Tail; + lh->lh_Tail = NULL; + lh->lh_TailPred = (struct Node *)&lh->lh_Head; + + LEAVE(); +} diff --git a/library/amiga_rangerand.c b/library/amiga_rangerand.c new file mode 100644 index 0000000..720dc80 --- /dev/null +++ b/library/amiga_rangerand.c @@ -0,0 +1,80 @@ +/* + * $Id: amiga_rangerand.c,v 1.1.1.1 2004-07-26 16:30:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +ULONG RangeSeed; + +/****************************************************************************/ + +UWORD +RangeRand(ULONG max_value) +{ + ULONG next_value; + ULONG result; + ULONG value; + UWORD range; + UWORD bits; + + range = (max_value & 0xFFFF); + bits = range - 1; + + value = RangeSeed; + + do + { + next_value = value + value; + if(next_value <= value) + next_value ^= 0x1D872B41; + + value = next_value; + + bits = bits >> 1; + } + while(bits != 0); + + RangeSeed = value; + + if(range == 0) + result = value & 0xFFFF; + else + result = (range * (value & 0xFFFF)) >> 16; + + return((UWORD)result); +} diff --git a/library/amiga_remtof.c b/library/amiga_remtof.c new file mode 100644 index 0000000..9cad549 --- /dev/null +++ b/library/amiga_remtof.c @@ -0,0 +1,57 @@ +/* + * $Id: amiga_remtof.c,v 1.1.1.1 2004-07-26 16:30:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +VOID +RemTOF(struct Isrvstr *i) +{ + assert( i != NULL ); + + RemIntServer(INTB_VERTB,(struct Interrupt *)i); +} diff --git a/library/amiga_setsuperattrs.c b/library/amiga_setsuperattrs.c new file mode 100644 index 0000000..1a50a58 --- /dev/null +++ b/library/amiga_setsuperattrs.c @@ -0,0 +1,101 @@ +/* + * $Id: amiga_setsuperattrs.c,v 1.1.1.1 2004-07-26 16:30:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __PPC__ + +/****************************************************************************/ + +#include +#include + +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +STATIC ULONG +SetSuperAttrsA(Class * cl,Object * obj,struct TagItem * tags) +{ + ULONG result = 0; + + ENTER(); + + SHOWPOINTER(cl); + SHOWPOINTER(obj); + SHOWPOINTER(tags); + + assert( cl != NULL && obj != NULL ); + + if(cl != NULL && obj != NULL) + { + struct opSet ops; + + ops.MethodID = OM_SET; + ops.ops_AttrList = tags; + ops.ops_GInfo = NULL; + + result = CallHookA(&cl->cl_Super->cl_Dispatcher,obj,&ops); + } + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +ULONG +SetSuperAttrs(Class * cl,Object * obj,ULONG tag1,...) +{ + ULONG result = 0; + + ENTER(); + + SHOWPOINTER(cl); + SHOWPOINTER(obj); + SHOWVALUE(tag1); + + assert( cl != NULL && obj != NULL ); + + if(cl != NULL && obj != NULL) + result = SetSuperAttrsA(cl,obj,(struct TagItem *)&tag1); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* __PPC__ */ diff --git a/library/amiga_timedelay.c b/library/amiga_timedelay.c new file mode 100644 index 0000000..fd19f71 --- /dev/null +++ b/library/amiga_timedelay.c @@ -0,0 +1,54 @@ +/* + * $Id: amiga_timedelay.c,v 1.1.1.1 2004-07-26 16:30:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +LONG +TimeDelay(LONG unit,ULONG seconds,ULONG micros) +{ + struct timeval tv; + LONG error; + + tv.tv_secs = seconds; + tv.tv_micro = micros; + + error = DoTimer(&tv,unit,TR_ADDREQUEST); + + return(error); +} diff --git a/library/amiga_waitbeam.c b/library/amiga_waitbeam.c new file mode 100644 index 0000000..27a11eb --- /dev/null +++ b/library/amiga_waitbeam.c @@ -0,0 +1,60 @@ +/* + * $Id: amiga_waitbeam.c,v 1.1.1.1 2004-07-26 16:30:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +#define DO_NOTHING ((void)0) + +/****************************************************************************/ + +VOID +waitbeam(LONG position) +{ + while(position > VBeamPos()) + DO_NOTHING; +} diff --git a/library/c.lib_rev.c b/library/c.lib_rev.c new file mode 100644 index 0000000..d8fc471 --- /dev/null +++ b/library/c.lib_rev.c @@ -0,0 +1,38 @@ +/* + * $Id: c.lib_rev.c,v 1.1.1.1 2004-07-26 16:30:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "c.lib_rev.h" + +/****************************************************************************/ + +char __c_lib_version[] = VERSTAG; diff --git a/library/c.lib_rev.h b/library/c.lib_rev.h new file mode 100644 index 0000000..8a885c0 --- /dev/null +++ b/library/c.lib_rev.h @@ -0,0 +1,6 @@ +#define VERSION 1 +#define REVISION 165 +#define DATE "26.7.2004" +#define VERS "c.lib 1.165" +#define VSTRING "c.lib 1.165 (26.7.2004)\r\n" +#define VERSTAG "\0$VER: c.lib 1.165 (26.7.2004)" diff --git a/library/c.lib_rev.rev b/library/c.lib_rev.rev new file mode 100644 index 0000000..9e42f3e --- /dev/null +++ b/library/c.lib_rev.rev @@ -0,0 +1 @@ +165 diff --git a/library/crt0.S b/library/crt0.S new file mode 100644 index 0000000..ef548de --- /dev/null +++ b/library/crt0.S @@ -0,0 +1,22 @@ +// +// $Id: crt0.S,v 1.1.1.1 2004-07-26 16:30:22 obarthel Exp $ +// +// :ts=4 +// + + .text + + .globl _main + .globl _start + +_start: + +#if defined(SMALL_DATA) + /* Don't do a function call here, since that + means LR has to be saved */ + lis r13, _SDA_BASE_@ha + addi r13, r13, _SDA_BASE_@l +#endif + + b _main + diff --git a/library/crtbegin.c b/library/crtbegin.c new file mode 100644 index 0000000..8c4d933 --- /dev/null +++ b/library/crtbegin.c @@ -0,0 +1,138 @@ +/* + * $Id: crtbegin.c,v 1.1.1.1 2004-07-26 16:30:22 obarthel Exp $ + * + * :ts=4 + * + * Handles global constructors and destructors. + */ + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#if defined(__amigaos4__) + +/****************************************************************************/ + +/* + * Dummy constructor and destructor array. The linker script will put these at the + * very beginning of section ".ctors" and ".dtors". crtend.o contains a similar entry + * with a NULL pointer entry and is put at the end of the sections. This way, the init + * code can find the global constructor/destructor pointers + */ +static void (*__CTOR_LIST__[1]) (void) __attribute__((section(".ctors"))) = { (void *)-1 }; +static void (*__DTOR_LIST__[1]) (void) __attribute__((section(".dtors"))) = { (void *)-1 }; + +/****************************************************************************/ + +static void +_do_ctors(void) +{ + void (**pFuncPtr)(void); + + /* Skip the first entry in the list (it's -1 anyway) */ + pFuncPtr = __CTOR_LIST__ + 1; + + /* Call all constructors in forward order */ + while (*pFuncPtr != NULL) + (**pFuncPtr++)(); +} + +/****************************************************************************/ + +static void +_do_dtors(void) +{ + ULONG i = (ULONG)__DTOR_LIST__[0]; + void (**pFuncPtr)(void); + + if (i == ~0UL) + { + /* Find the end of the destructors list */ + i = 1; + + while (__DTOR_LIST__[i] != NULL) + i++; + + /* We're at the NULL entry now. Go back by one */ + i--; + } + + /* Call all destructors in reverse order */ + pFuncPtr = __DTOR_LIST__ + i; + while (i-- > 0) + (**pFuncPtr--)(); +} + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +typedef void (*func_ptr)(void); + +/****************************************************************************/ + +static void +_do_ctors(void) +{ + extern func_ptr __CTOR_LIST__[]; + ULONG nptrs = (ULONG)__CTOR_LIST__[0]; + ULONG i; + + for(i = nptrs ; i > 0 ; i--) + __CTOR_LIST__[i](); +} + +/****************************************************************************/ + +static void +_do_dtors(void) +{ + extern func_ptr __DTOR_LIST__[]; + extern jmp_buf __exit_jmp_buf; + ULONG nptrs = (ULONG)__DTOR_LIST__[0]; + static ULONG i; + + /* If one of the destructors drops into + * exit(), processing will continue with + * the next following destructor. + */ + (void)setjmp(__exit_jmp_buf); + + while(i++ < nptrs) + __DTOR_LIST__[i](); +} + +/****************************************************************************/ + +#endif /*__amigaos4__ */ + +/****************************************************************************/ + +/* FIXME: Do we need to put these in .init/.fini sections? */ + +//void _init(void) __attribute__((section(".init"))); +//void _fini(void) __attribute__((section(".fini"))); + +/****************************************************************************/ + +void +_init(void) +{ + _do_ctors(); +} + +/****************************************************************************/ + +void +_fini(void) +{ + _do_dtors(); +} diff --git a/library/crtend.c b/library/crtend.c new file mode 100644 index 0000000..321336a --- /dev/null +++ b/library/crtend.c @@ -0,0 +1,18 @@ +/* + * $Id: crtend.c,v 1.1.1.1 2004-07-26 16:30:22 obarthel Exp $ + * + * :ts=4 + * + * End markers for the CTOR and DTOR list. + */ + +#if defined(__amigaos4__) + +/****************************************************************************/ + +static volatile void (*__CTOR_LIST__[1]) (void) __attribute__((used,section(".ctors"))) = { (void *)0 }; +static volatile void (*__DTOR_LIST__[1]) (void) __attribute__((used,section(".dtors"))) = { (void *)0 }; + +/****************************************************************************/ + +#endif /*__amigaos4__ */ diff --git a/library/ctype_headers.h b/library/ctype_headers.h new file mode 100644 index 0000000..faa8646 --- /dev/null +++ b/library/ctype_headers.h @@ -0,0 +1,61 @@ +/* + * $Id: ctype_headers.h,v 1.1.1.1 2004-07-26 16:30:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#define _CTYPE_HEADERS_H + +/****************************************************************************/ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_LOCALE_UTILITY_H +#include "stdlib_locale_utility.h" +#endif /* _STDLIB_LOCALE_UTILITY_H */ + +/****************************************************************************/ + +#include "macros.h" + +/****************************************************************************/ + +#include +#include +#include + +/****************************************************************************/ + +#endif /* _CTYPE_HEADERS_H */ diff --git a/library/ctype_isalnum.c b/library/ctype_isalnum.c new file mode 100644 index 0000000..edbbf34 --- /dev/null +++ b/library/ctype_isalnum.c @@ -0,0 +1,64 @@ +/* + * $Id: ctype_isalnum.c,v 1.1.1.1 2004-07-26 16:30:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +#undef isalnum +#undef isalpha +#undef isdigit + +/****************************************************************************/ + +int +isalnum(int c) +{ + DECLARE_LOCALEBASE(); + int result; + + if(__locale_table[LC_CTYPE] != NULL) + { + assert( LocaleBase != NULL ); + + result = IsAlNum(__locale_table[LC_CTYPE],(ULONG)c); + } + else + { + result = isalpha(c) || isdigit(c); + } + + return(result); +} diff --git a/library/ctype_isalpha.c b/library/ctype_isalpha.c new file mode 100644 index 0000000..8318ffc --- /dev/null +++ b/library/ctype_isalpha.c @@ -0,0 +1,63 @@ +/* + * $Id: ctype_isalpha.c,v 1.1.1.1 2004-07-26 16:30:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +#undef isalpha + +/****************************************************************************/ + +int +isalpha(int c) +{ + DECLARE_LOCALEBASE(); + int result; + + if(__locale_table[LC_CTYPE] != NULL) + { + assert( LocaleBase != NULL ); + + result = IsAlpha(__locale_table[LC_CTYPE],(ULONG)c); + } + else + { + result = (('a' <= c && c <= 'z') || + ('A' <= c && c <= 'Z')); + } + + return(result); +} diff --git a/library/ctype_isascii.c b/library/ctype_isascii.c new file mode 100644 index 0000000..4acade6 --- /dev/null +++ b/library/ctype_isascii.c @@ -0,0 +1,56 @@ +/* + * $Id: ctype_isascii.c,v 1.1.1.1 2004-07-26 16:30:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +#undef isascii + +/****************************************************************************/ + +int isascii(int c); + +/****************************************************************************/ + +int +isascii(int c) +{ + int result; + + result = (0 <= c && c <= 127); + + return(result); +} diff --git a/library/ctype_iscntrl.c b/library/ctype_iscntrl.c new file mode 100644 index 0000000..a431517 --- /dev/null +++ b/library/ctype_iscntrl.c @@ -0,0 +1,62 @@ +/* + * $Id: ctype_iscntrl.c,v 1.1.1.1 2004-07-26 16:30:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +#undef iscntrl + +/****************************************************************************/ + +int +iscntrl(int c) +{ + DECLARE_LOCALEBASE(); + int result; + + if(__locale_table[LC_CTYPE] != NULL) + { + assert( LocaleBase != NULL ); + + result = IsCntrl(__locale_table[LC_CTYPE],(ULONG)c); + } + else + { + result = (('\0' <= c && c < ' ') || (c == 127)); + } + + return(result); +} diff --git a/library/ctype_isdigit.c b/library/ctype_isdigit.c new file mode 100644 index 0000000..0302b63 --- /dev/null +++ b/library/ctype_isdigit.c @@ -0,0 +1,62 @@ +/* + * $Id: ctype_isdigit.c,v 1.1.1.1 2004-07-26 16:30:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +#undef isdigit + +/****************************************************************************/ + +int +isdigit(int c) +{ + DECLARE_LOCALEBASE(); + int result; + + if(__locale_table[LC_CTYPE] != NULL) + { + assert( LocaleBase != NULL ); + + result = IsDigit(__locale_table[LC_CTYPE],(ULONG)c); + } + else + { + result = ('0' <= c && c <= '9'); + } + + return(result); +} diff --git a/library/ctype_isgraph.c b/library/ctype_isgraph.c new file mode 100644 index 0000000..56b5ffc --- /dev/null +++ b/library/ctype_isgraph.c @@ -0,0 +1,62 @@ +/* + * $Id: ctype_isgraph.c,v 1.1.1.1 2004-07-26 16:30:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +#undef isgraph + +/****************************************************************************/ + +int +isgraph(int c) +{ + DECLARE_LOCALEBASE(); + int result; + + if(__locale_table[LC_CTYPE] != NULL) + { + assert( LocaleBase != NULL ); + + result = IsGraph(__locale_table[LC_CTYPE],(ULONG)c); + } + else + { + result = (' ' < c && c < 127); + } + + return(result); +} diff --git a/library/ctype_islower.c b/library/ctype_islower.c new file mode 100644 index 0000000..159f2c6 --- /dev/null +++ b/library/ctype_islower.c @@ -0,0 +1,62 @@ +/* + * $Id: ctype_islower.c,v 1.1.1.1 2004-07-26 16:30:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +#undef islower + +/****************************************************************************/ + +int +islower(int c) +{ + DECLARE_LOCALEBASE(); + int result; + + if(__locale_table[LC_CTYPE] != NULL) + { + assert( LocaleBase != NULL ); + + result = IsLower(__locale_table[LC_CTYPE],(ULONG)c); + } + else + { + result = ('a' <= c && c <= 'z'); + } + + return(result); +} diff --git a/library/ctype_isprint.c b/library/ctype_isprint.c new file mode 100644 index 0000000..869fa59 --- /dev/null +++ b/library/ctype_isprint.c @@ -0,0 +1,62 @@ +/* + * $Id: ctype_isprint.c,v 1.1.1.1 2004-07-26 16:30:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +#undef isprint + +/****************************************************************************/ + +int +isprint(int c) +{ + DECLARE_LOCALEBASE(); + int result; + + if(__locale_table[LC_CTYPE] != NULL) + { + assert( LocaleBase != NULL ); + + result = IsPrint(__locale_table[LC_CTYPE],(ULONG)c); + } + else + { + result = (' ' <= c && c <= '~'); + } + + return(result); +} diff --git a/library/ctype_ispunct.c b/library/ctype_ispunct.c new file mode 100644 index 0000000..b0fbec1 --- /dev/null +++ b/library/ctype_ispunct.c @@ -0,0 +1,65 @@ +/* + * $Id: ctype_ispunct.c,v 1.1.1.1 2004-07-26 16:30:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +#undef ispunct + +/****************************************************************************/ + +int +ispunct(int c) +{ + DECLARE_LOCALEBASE(); + int result; + + if(__locale_table[LC_CTYPE] != NULL) + { + assert( LocaleBase != NULL ); + + result = IsPunct(__locale_table[LC_CTYPE],(ULONG)c); + } + else + { + result = (('!' <= c && c <= '/') || + (':' <= c && c <= '@') || + ('[' <= c && c <= '`') || + ('{' <= c && c <= '~')); + } + + return(result); +} diff --git a/library/ctype_isspace.c b/library/ctype_isspace.c new file mode 100644 index 0000000..c1f5910 --- /dev/null +++ b/library/ctype_isspace.c @@ -0,0 +1,67 @@ +/* + * $Id: ctype_isspace.c,v 1.1.1.1 2004-07-26 16:30:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +#undef isspace + +/****************************************************************************/ + +int +isspace(int c) +{ + DECLARE_LOCALEBASE(); + int result; + + if(__locale_table[LC_CTYPE] != NULL) + { + assert( LocaleBase != NULL ); + + result = IsSpace(__locale_table[LC_CTYPE],(ULONG)c); + } + else + { + result = (c == '\t' || + c == '\r' || + c == '\n' || + c == '\v' || + c == '\f' || + c == ' '); + } + + return(result); +} diff --git a/library/ctype_isupper.c b/library/ctype_isupper.c new file mode 100644 index 0000000..e6e4c01 --- /dev/null +++ b/library/ctype_isupper.c @@ -0,0 +1,62 @@ +/* + * $Id: ctype_isupper.c,v 1.1.1.1 2004-07-26 16:30:24 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +#undef isupper + +/****************************************************************************/ + +int +isupper(int c) +{ + DECLARE_LOCALEBASE(); + int result; + + if(__locale_table[LC_CTYPE] != NULL) + { + assert( LocaleBase != NULL ); + + result = IsUpper(__locale_table[LC_CTYPE],(ULONG)c); + } + else + { + result = ('A' <= c && c <= 'Z'); + } + + return(result); +} diff --git a/library/ctype_isxdigit.c b/library/ctype_isxdigit.c new file mode 100644 index 0000000..c82883d --- /dev/null +++ b/library/ctype_isxdigit.c @@ -0,0 +1,64 @@ +/* + * $Id: ctype_isxdigit.c,v 1.1.1.1 2004-07-26 16:30:24 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +#undef isxdigit + +/****************************************************************************/ + +int +isxdigit(int c) +{ + DECLARE_LOCALEBASE(); + int result; + + if(__locale_table[LC_CTYPE] != NULL) + { + assert( LocaleBase != NULL ); + + result = IsXDigit(__locale_table[LC_CTYPE],(ULONG)c); + } + else + { + result = (('0' <= c && c <= '9') || + ('a' <= c && c <= 'f') || + ('A' <= c && c <= 'F')); + } + + return(result); +} diff --git a/library/ctype_table.c b/library/ctype_table.c new file mode 100644 index 0000000..d0b75a5 --- /dev/null +++ b/library/ctype_table.c @@ -0,0 +1,196 @@ +/* + * $Id: ctype_table.c,v 1.1.1.1 2004-07-26 16:30:24 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#define __C_MACROS__ +#include + +/****************************************************************************/ + +/* The construction of this table is rather peculiar. The assumption is that + the table index from which a flag value could be fetched is in the range + -128..255 since the character to be tested could be a signed or unsigned + 8 bit value. The table access pointer (declared below) therefore points + to the 128th byte of '__ctype_data[]'. */ +static const unsigned char __ctype_data[3 * 128] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + /* 0 */ __CTYPE_CONTROL, + /* 1 */ __CTYPE_CONTROL, + /* 2 */ __CTYPE_CONTROL, + /* 3 */ __CTYPE_CONTROL, + /* 4 */ __CTYPE_CONTROL, + /* 5 */ __CTYPE_CONTROL, + /* 6 */ __CTYPE_CONTROL, + /* 7 */ __CTYPE_CONTROL, + /* 8 */ __CTYPE_CONTROL, + /* 9 */ __CTYPE_CONTROL|__CTYPE_WHITE_SPACE, + /* 10 */ __CTYPE_CONTROL|__CTYPE_WHITE_SPACE, + /* 11 */ __CTYPE_CONTROL|__CTYPE_WHITE_SPACE, + /* 12 */ __CTYPE_CONTROL|__CTYPE_WHITE_SPACE, + /* 13 */ __CTYPE_CONTROL|__CTYPE_WHITE_SPACE, + /* 14 */ __CTYPE_CONTROL, + /* 15 */ __CTYPE_CONTROL, + /* 16 */ __CTYPE_CONTROL, + /* 17 */ __CTYPE_CONTROL, + /* 18 */ __CTYPE_CONTROL, + /* 19 */ __CTYPE_CONTROL, + /* 20 */ __CTYPE_CONTROL, + /* 21 */ __CTYPE_CONTROL, + /* 22 */ __CTYPE_CONTROL, + /* 23 */ __CTYPE_CONTROL, + /* 24 */ __CTYPE_CONTROL, + /* 25 */ __CTYPE_CONTROL, + /* 26 */ __CTYPE_CONTROL, + /* 27 */ __CTYPE_CONTROL, + /* 28 */ __CTYPE_CONTROL, + /* 29 */ __CTYPE_CONTROL, + /* 30 */ __CTYPE_CONTROL, + /* 31 */ __CTYPE_CONTROL, + /* 32, ' ' */ __CTYPE_PRINTABLE|__CTYPE_WHITE_SPACE, + /* 33, '!' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 34, '"' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 35, '#' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 36, '$' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 37, '%' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 38, '&' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 39, ''' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 40, '(' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 41, ')' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 42, '*' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 43, '+' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 44, ',' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 45, '-' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 46, '.' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 47, '/' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 48, '0' */ __CTYPE_DIGIT|__CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE, + /* 49, '1' */ __CTYPE_DIGIT|__CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE, + /* 50, '2' */ __CTYPE_DIGIT|__CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE, + /* 51, '3' */ __CTYPE_DIGIT|__CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE, + /* 52, '4' */ __CTYPE_DIGIT|__CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE, + /* 53, '5' */ __CTYPE_DIGIT|__CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE, + /* 54, '6' */ __CTYPE_DIGIT|__CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE, + /* 55, '7' */ __CTYPE_DIGIT|__CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE, + /* 56, '8' */ __CTYPE_DIGIT|__CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE, + /* 57, '9' */ __CTYPE_DIGIT|__CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE, + /* 58, ':' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 59, ';' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 60, '<' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 61, '=' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 62, '>' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 63, '?' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 64, '@' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 65, 'A' */ __CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 66, 'B' */ __CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 67, 'C' */ __CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 68, 'D' */ __CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 69, 'E' */ __CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 70, 'F' */ __CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 71, 'G' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 72, 'H' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 73, 'I' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 74, 'J' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 75, 'K' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 76, 'L' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 77, 'M' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 78, 'N' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 79, 'O' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 80, 'P' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 81, 'Q' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 82, 'R' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 83, 'S' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 84, 'T' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 85, 'U' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 86, 'V' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 87, 'W' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 88, 'X' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 89, 'Y' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 90, 'Z' */ __CTYPE_PRINTABLE|__CTYPE_UPPER_CASE, + /* 91, '[' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 92, '\' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 93, ']' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 94, '^' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 95, '_' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 96, '`' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 97, 'a' */ __CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 98, 'b' */ __CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 99, 'c' */ __CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 100, 'd' */ __CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 101, 'e' */ __CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 102, 'f' */ __CTYPE_HEX_DIGIT|__CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 103, 'g' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 104, 'h' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 105, 'i' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 106, 'j' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 107, 'k' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 108, 'l' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 109, 'm' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 110, 'n' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 111, 'o' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 112, 'p' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 113, 'q' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 114, 'r' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 115, 's' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 116, 't' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 117, 'u' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 118, 'v' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 119, 'w' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 120, 'x' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 121, 'y' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 122, 'z' */ __CTYPE_PRINTABLE|__CTYPE_LOWER_CASE, + /* 123, '{' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 124, '|' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 125, '}' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 126, '~' */ __CTYPE_PUNCTUATION|__CTYPE_PRINTABLE, + /* 127 */ __CTYPE_CONTROL, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/****************************************************************************/ + +const unsigned char * const __ctype_table = &__ctype_data[128]; diff --git a/library/ctype_tolower.c b/library/ctype_tolower.c new file mode 100644 index 0000000..1b7ec0f --- /dev/null +++ b/library/ctype_tolower.c @@ -0,0 +1,58 @@ +/* + * $Id: ctype_tolower.c,v 1.1.1.1 2004-07-26 16:30:25 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +tolower(int c) +{ + DECLARE_LOCALEBASE(); + int result; + + if(__locale_table[LC_CTYPE] != NULL) + { + assert( LocaleBase != NULL ); + + result = ConvToLower(__locale_table[LC_CTYPE],(ULONG)c); + } + else + { + result = ('A' <= c && c <= 'Z') ? (c + ('a' - 'A')) : c; + } + + return(result); +} diff --git a/library/ctype_toupper.c b/library/ctype_toupper.c new file mode 100644 index 0000000..000e4eb --- /dev/null +++ b/library/ctype_toupper.c @@ -0,0 +1,58 @@ +/* + * $Id: ctype_toupper.c,v 1.1.1.1 2004-07-26 16:30:25 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_HEADERS_H +#include "ctype_headers.h" +#endif /* _CTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +toupper(int c) +{ + DECLARE_LOCALEBASE(); + int result; + + if(__locale_table[LC_CTYPE] != NULL) + { + assert( LocaleBase != NULL ); + + result = ConvToUpper(__locale_table[LC_CTYPE],(ULONG)c); + } + else + { + result = ('a' <= c && c <= 'z') ? (c - ('a' - 'A')) : c; + } + + return(result); +} diff --git a/library/debug.c b/library/debug.c new file mode 100644 index 0000000..62d04aa --- /dev/null +++ b/library/debug.c @@ -0,0 +1,342 @@ +/* + * $Id: debug.c,v 1.1.1.1 2004-07-26 16:30:25 obarthel Exp $ + * + * :ts=8 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/****************************************************************************/ + +#define NULL ((void *)0L) + +#include +#include + +/****************************************************************************/ + +#ifndef DEBUG +#define DEBUG 1 +#endif + +#include "debug.h" + +/****************************************************************************/ + +extern void KPrintF(const char * format,...); +extern void KPutFmt(const char * format,va_list arg); + +/****************************************************************************/ + +#define DEBUGLEVEL_OnlyAsserts 0 +#define DEBUGLEVEL_Reports 1 +#define DEBUGLEVEL_CallTracing 2 + +/****************************************************************************/ + +extern int __debug_level; + +/****************************************************************************/ + +static int indent_level = 0; + +static char program_name[40]; +static int program_name_len = 0; + +/****************************************************************************/ + +void +_SETPROGRAMNAME(char *name) +{ + if(name != NULL && name[0] != '\0') + { + int i; + + for(i = 0 ; name[i] != '\0' && i < (int)sizeof(program_name)-1 ; i++) + program_name[i] = name[i]; + + program_name[i] = '\0'; + + program_name_len = i; + } + else + { + program_name_len = 0; + } +} + +/****************************************************************************/ + +int +_SETDEBUGLEVEL(int level) +{ + int old_level = __debug_level; + + __debug_level = level; + + return(old_level); +} + +/****************************************************************************/ + +int +_GETDEBUGLEVEL(void) +{ + return(__debug_level); +} + +/****************************************************************************/ + +static int previous_debug_level = -1; + +void +_PUSHDEBUGLEVEL(int level) +{ + previous_debug_level = _SETDEBUGLEVEL(level); +} + +void +_POPDEBUGLEVEL(void) +{ + if(previous_debug_level != -1) + { + _SETDEBUGLEVEL(previous_debug_level); + + previous_debug_level = -1; + } +} + +/****************************************************************************/ + +static void +_INDENT(void) +{ + if(program_name_len > 0) + KPrintF("(%s) ",program_name); + + if(__debug_level >= DEBUGLEVEL_CallTracing) + { + int i; + + for(i = 0 ; i < indent_level ; i++) + KPrintF(" "); + } +} + +/****************************************************************************/ + +void +_SHOWVALUE( + unsigned long value, + int size, + const char *name, + const char *file, + int line) +{ + if(__debug_level >= DEBUGLEVEL_Reports) + { + char *fmt; + + switch(size) + { + case 1: + + fmt = "%s:%ld:%s = %ld, 0x%02lx"; + break; + + case 2: + + fmt = "%s:%ld:%s = %ld, 0x%04lx"; + break; + + default: + + fmt = "%s:%ld:%s = %ld, 0x%08lx"; + break; + } + + _INDENT(); + + KPrintF(fmt,file,line,name,value,value); + + if(size == 1 && value < 256) + { + if(value < ' ' || (value >= 127 && value < 160)) + KPrintF(", '\\x%02lx'",value); + else + KPrintF(", '%lc'",value); + } + + KPrintF("\n"); + } +} + +/****************************************************************************/ + +void +_SHOWPOINTER( + const void *pointer, + const char *name, + const char *file, + int line) +{ + if(__debug_level >= DEBUGLEVEL_Reports) + { + char *fmt; + + _INDENT(); + + if(pointer != NULL) + fmt = "%s:%ld:%s = 0x%08lx\n"; + else + fmt = "%s:%ld:%s = NULL\n"; + + KPrintF(fmt,file,line,name,pointer); + } +} + +/****************************************************************************/ + +void +_SHOWSTRING( + const char *string, + const char *name, + const char *file, + int line) +{ + if(__debug_level >= DEBUGLEVEL_Reports) + { + _INDENT(); + KPrintF("%s:%ld:%s = 0x%08lx \"%s\"\n",file,line,name,string,string); + } +} + +/****************************************************************************/ + +void +_SHOWMSG( + const char *string, + const char *file, + int line) +{ + if(__debug_level >= DEBUGLEVEL_Reports) + { + _INDENT(); + KPrintF("%s:%ld:%s\n",file,line,string); + } +} + +/****************************************************************************/ + +void +_DPRINTF_HEADER( + const char *file, + int line) +{ + if(__debug_level >= DEBUGLEVEL_Reports) + { + _INDENT(); + KPrintF("%s:%ld:",file,line); + } +} + +void +_DPRINTF(const char *fmt,...) +{ + if(__debug_level >= DEBUGLEVEL_Reports) + { + va_list args; + + va_start(args,fmt); + KPutFmt((char *)fmt,args); + va_end(args); + + KPrintF("\n"); + } +} + +void +_DLOG(const char *fmt,...) +{ + if(__debug_level >= DEBUGLEVEL_Reports) + { + va_list args; + + va_start(args,fmt); + KPutFmt((char *)fmt,args); + va_end(args); + } +} + +/****************************************************************************/ + +void +_ENTER( + const char *file, + int line, + const char *function) +{ + if(__debug_level >= DEBUGLEVEL_CallTracing) + { + _INDENT(); + KPrintF("%s:%ld:Entering %s\n",file,line,function); + } + + indent_level++; +} + +void +_LEAVE( + const char *file, + int line, + const char *function) +{ + indent_level--; + + if(__debug_level >= DEBUGLEVEL_CallTracing) + { + _INDENT(); + KPrintF("%s:%ld: Leaving %s\n",file,line,function); + } +} + +void +_RETURN( + const char *file, + int line, + const char *function, + unsigned long result) +{ + indent_level--; + + if(__debug_level >= DEBUGLEVEL_CallTracing) + { + _INDENT(); + KPrintF("%s:%ld: Leaving %s (result 0x%08lx, %ld)\n",file,line,function,result,result); + } +} diff --git a/library/debug.h b/library/debug.h new file mode 100644 index 0000000..0177e78 --- /dev/null +++ b/library/debug.h @@ -0,0 +1,191 @@ +/* + * $Id: debug.h,v 1.1.1.1 2004-07-26 16:30:26 obarthel Exp $ + * + * :ts=8 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DEBUG_H +#define _DEBUG_H + +/****************************************************************************/ + +/* IMPORTANT: If DEBUG is redefined, it must happen only here. This + * will cause all modules to depend upon it to be rebuilt + * by the smakefile (that is, provided the smakefile has + * all the necessary dependency lines in place). + */ + +/*#define DEBUG*/ + +/****************************************************************************/ + +#define PUSH_REPORTS() PUSHDEBUGLEVEL(1) +#define PUSH_CALLS() PUSHDEBUGLEVEL(2) +#define PUSH_ALL() PUSHDEBUGLEVEL(2) +#define POP() POPDEBUGLEVEL() + +/****************************************************************************/ + +#if defined(DEBUG) + +/****************************************************************************/ + +extern void kprintf(const char *format,...); +extern void abort(void); +extern char * __program_name; + +/****************************************************************************/ + + void _SHOWVALUE(unsigned long value,int size,const char *name,const char *file,int line); + void _SHOWPOINTER(const void *p,const char *name,const char *file,int line); + void _SHOWSTRING(const char *string,const char *name,const char *file,int line); + void _SHOWMSG(const char *msg,const char *file,int line); + void _ENTER(const char *file,int line,const char *function); + void _LEAVE(const char *file,int line,const char *function); + void _RETURN(const char *file,int line,const char *function,unsigned long result); + void _DPRINTF_HEADER(const char *file,int line); + void _DPRINTF(const char *format,...); + void _DLOG(const char *format,...); + int _SETDEBUGLEVEL(int level); + void _PUSHDEBUGLEVEL(int level); + void _POPDEBUGLEVEL(void); + int _GETDEBUGLEVEL(void); + void _SETPROGRAMNAME(char *name); + + #if defined(__SASC) + #define ENTER() _ENTER(__FILE__,__LINE__,__FUNC__) + #define LEAVE() _LEAVE(__FILE__,__LINE__,__FUNC__) + #define RETURN(r) _RETURN(__FILE__,__LINE__,__FUNC__,(unsigned long)r) + #define SHOWVALUE(v) _SHOWVALUE((unsigned long)v,sizeof(v),#v,__FILE__,__LINE__) + #define SHOWPOINTER(p) _SHOWPOINTER(p,#p,__FILE__,__LINE__) + #define SHOWSTRING(s) _SHOWSTRING(s,#s,__FILE__,__LINE__) + #define SHOWMSG(s) _SHOWMSG(s,__FILE__,__LINE__) + #define D(s) do { _DPRINTF_HEADER(__FILE__,__LINE__); _DPRINTF s; } while(0) + #define PRINTHEADER() _DPRINTF_HEADER(__FILE__,__LINE__) + #define PRINTF(s) _DLOG s + #define LOG(s) do { _DPRINTF_HEADER(__FILE__,__LINE__); _DLOG("<%s()>:",__FUNC__); _DLOG s; } while(0) + #define SETDEBUGLEVEL(l) _SETDEBUGLEVEL(l) + #define PUSHDEBUGLEVEL(l) _PUSHDEBUGLEVEL(l) + #define POPDEBUGLEVEL() _POPDEBUGLEVEL() + #define SETPROGRAMNAME(n) _SETPROGRAMNAME(n) + #define GETDEBUGLEVEL() _GETDEBUGLEVEL() + #elif defined(__GNUC__) + #define ENTER() _ENTER(__FILE__,__LINE__,__FUNCTION__) + #define LEAVE() _LEAVE(__FILE__,__LINE__,__FUNCTION__) + #define RETURN(r) _RETURN(__FILE__,__LINE__,__FUNCTION__,(unsigned long)r) + #define SHOWVALUE(v) _SHOWVALUE((unsigned long)v,sizeof(v),#v,__FILE__,__LINE__) + #define SHOWPOINTER(p) _SHOWPOINTER(p,#p,__FILE__,__LINE__) + #define SHOWSTRING(s) _SHOWSTRING(s,#s,__FILE__,__LINE__) + #define SHOWMSG(s) _SHOWMSG(s,__FILE__,__LINE__) + #define D(s) do { _DPRINTF_HEADER(__FILE__,__LINE__); _DPRINTF s; } while(0) + #define PRINTHEADER() _DPRINTF_HEADER(__FILE__,__LINE__) + #define PRINTF(s) _DLOG s + #define LOG(s) do { _DPRINTF_HEADER(__FILE__,__LINE__); _DLOG("<%s()>:",__FUNCTION__); _DLOG s; } while(0) + #define SETDEBUGLEVEL(l) _SETDEBUGLEVEL(l) + #define PUSHDEBUGLEVEL(l) _PUSHDEBUGLEVEL(l) + #define POPDEBUGLEVEL() _POPDEBUGLEVEL() + #define SETPROGRAMNAME(n) _SETPROGRAMNAME(n) + #define GETDEBUGLEVEL() _GETDEBUGLEVEL() + #else + #define __FUNC__ "" + #define ENTER() _ENTER(__FILE__,__LINE__,__FUNC__) + #define LEAVE() _LEAVE(__FILE__,__LINE__,__FUNC__) + #define RETURN(r) _RETURN(__FILE__,__LINE__,__FUNC__,(unsigned long)r) + #define SHOWVALUE(v) _SHOWVALUE((unsigned long)v,sizeof(v),#v,__FILE__,__LINE__) + #define SHOWPOINTER(p) _SHOWPOINTER(p,#p,__FILE__,__LINE__) + #define SHOWSTRING(s) _SHOWSTRING(s,#s,__FILE__,__LINE__) + #define SHOWMSG(s) _SHOWMSG(s,__FILE__,__LINE__) + #define D(s) do { _DPRINTF_HEADER(__FILE__,__LINE__); _DPRINTF s; } while(0) + #define PRINTHEADER() _DPRINTF_HEADER(__FILE__,__LINE__) + #define PRINTF(s) _DLOG s + #define LOG(s) do { _DPRINTF_HEADER(__FILE__,__LINE__); _DLOG("<%s()>:",__FUNC__); _DLOG s; } while(0) + #define SETDEBUGLEVEL(l) _SETDEBUGLEVEL(l) + #define PUSHDEBUGLEVEL(l) _PUSHDEBUGLEVEL(l) + #define POPDEBUGLEVEL() _POPDEBUGLEVEL() + #define SETPROGRAMNAME(n) _SETPROGRAMNAME(n) + #define GETDEBUGLEVEL() _GETDEBUGLEVEL() + #endif + + #undef DEBUG + #define DEBUG 1 + + #define assert(expression) \ + ((void) \ + ((expression) ? 0 : \ + ( \ + *(char *)0 = 0, /* Enforcer hit */ \ + _SETDEBUGLEVEL(2), \ + kprintf("[%s] " \ + "%s:%ld: failed assertion '%s'\n", \ + __program_name, \ + __FILE__, \ + __LINE__, \ + #expression), \ + abort(), \ + 0 \ + ) \ + ) \ + ) + +#else + +/****************************************************************************/ + +#ifdef NDEBUG +#define assert(expression) ((void)0) +#else +#include +#endif /* NDEBUG */ + +/****************************************************************************/ + + #define ENTER() ((void)0) + #define LEAVE() ((void)0) + #define RETURN(r) ((void)0) + #define SHOWVALUE(v) ((void)0) + #define SHOWPOINTER(p) ((void)0) + #define SHOWSTRING(s) ((void)0) + #define SHOWMSG(s) ((void)0) + #define D(s) ((void)0) + #define PRINTHEADER() ((void)0) + #define PRINTF(s) ((void)0) + #define LOG(s) ((void)0) + #define SETDEBUGLEVEL(l) ((void)0) + #define PUSHDEBUGLEVEL(l) ((void)0) + #define POPDEBUGLEVEL() ((void)0) + #define SETPROGRAMNAME(n) ((void)0) + #define GETDEBUGLEVEL() (0) + + #define DEBUG 0 +#endif /* DEBUG */ + +/****************************************************************************/ + +#endif /* _DEBUG_H */ diff --git a/library/debug.lib_rev.c b/library/debug.lib_rev.c new file mode 100644 index 0000000..782a977 --- /dev/null +++ b/library/debug.lib_rev.c @@ -0,0 +1,38 @@ +/* + * $Id: debug.lib_rev.c,v 1.1.1.1 2004-07-26 16:30:26 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug.lib_rev.h" + +/****************************************************************************/ + +char __debug_lib_version[] = VERSTAG; diff --git a/library/debug.lib_rev.h b/library/debug.lib_rev.h new file mode 100644 index 0000000..1341da9 --- /dev/null +++ b/library/debug.lib_rev.h @@ -0,0 +1,6 @@ +#define VERSION 1 +#define REVISION 165 +#define DATE "26.7.2004" +#define VERS "debug.lib 1.165" +#define VSTRING "debug.lib 1.165 (26.7.2004)\r\n" +#define VERSTAG "\0$VER: debug.lib 1.165 (26.7.2004)" diff --git a/library/debug.lib_rev.rev b/library/debug.lib_rev.rev new file mode 100644 index 0000000..9e42f3e --- /dev/null +++ b/library/debug.lib_rev.rev @@ -0,0 +1 @@ +165 diff --git a/library/debug_cmpstrexec.c b/library/debug_cmpstrexec.c new file mode 100644 index 0000000..d151548 --- /dev/null +++ b/library/debug_cmpstrexec.c @@ -0,0 +1,62 @@ +/* + * $Id: debug_cmpstrexec.c,v 1.1.1.1 2004-07-26 16:30:26 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +LONG +cmpstrexec(const char * source1,const char * source2) +{ + LONG result = 0; + + assert( source1 != NULL && source2 != NULL ); + + if(source1 != NULL && source2 != NULL) + { + while((*source1) == (*source2)) + { + if((*source1) == '\0') + goto out; + + source1++; + source2++; + } + + result = (*source1) - (*source2); + } + + out: + + return(result); +} diff --git a/library/debug_headers.h b/library/debug_headers.h new file mode 100644 index 0000000..72b8adf --- /dev/null +++ b/library/debug_headers.h @@ -0,0 +1,151 @@ +/* + * $Id: debug_headers.h,v 1.1.1.1 2004-07-26 16:30:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DEBUG_HEADERS_H +#define _DEBUG_HEADERS_H + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#if defined(__SASC) + +#include +/*#include */ +#include + +LONG RawMayGetChar(VOID); +VOID RawPutChar(UBYTE c); + +#pragma libcall SysBase RawMayGetChar 1fe 00 +#pragma libcall SysBase RawPutChar 204 001 + +#endif /* __SASC */ + +/****************************************************************************/ + +#if defined(__amigaos4__) +#include +#endif /* __amigaos4__ */ + +/****************************************************************************/ + +#if defined(__GNUC__) + +#define __NOLIBBASE__ +#include + +#ifndef __PPC__ + +#define RawMayGetChar() ({ \ + UBYTE _RawMayGetChar__re = \ + ({ \ + register struct Library * const __RawMayGetChar__bn __asm("a6") = SysBase;\ + register UBYTE __RawMayGetChar__re __asm("d0"); \ + __asm volatile ("jsr a6@(-510:W)" \ + : "=r"(__RawMayGetChar__re) \ + : "r"(__RawMayGetChar__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __RawMayGetChar__re; \ + }); \ + _RawMayGetChar__re; \ +}) + +#define RawPutChar(c) ({ \ + ULONG _RawPutChar_c = (c); \ + { \ + register struct Library * const __RawPutChar__bn __asm("a6") = SysBase;\ + register ULONG __RawPutChar_c __asm("d0") = (_RawPutChar_c); \ + __asm volatile ("jsr a6@(-516:W)" \ + : \ + : "r"(__RawPutChar__bn), "r"(__RawPutChar_c) \ + : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + } \ +}) + +#endif /* __PPC___ */ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#define SysBase (*(struct Library **)4) +#define IExec ((struct ExecIFace *)((struct ExecBase *)SysBase)->MainInterface) + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +#include "macros.h" + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +extern LONG cmpstrexec(const char *source1, const char *source2); +extern LONG KCmpStr(const char *source1, const char *source2); +extern LONG KMayGetCh(VOID); +extern LONG KMayGetChar(VOID); +extern LONG kgetc(VOID); +extern LONG kgetchar(VOID); +extern LONG kgetch(VOID); +extern LONG KGetCh(VOID); +extern LONG KGetChar(VOID); +extern LONG kgetnum(VOID); +extern LONG KGetNum(void); +extern VOID KDoFmt(const char *format_string, APTR data_stream, APTR put_char_routine, APTR put_char_data); +extern VOID KPutFmt(const char *format, va_list arg); +extern VOID KVPrintF(const char * format, va_list arg); +extern VOID kvprintf(const char *format, va_list arg); +extern VOID kprintf(const char *format, ...); +extern VOID KPrintF(const char *format, ...); +extern VOID kputc(UBYTE c); +extern VOID kputchar(UBYTE c); +extern VOID kputch(UBYTE c); +extern VOID KPutCh(UBYTE c); +extern VOID KPutChar(UBYTE c); +extern VOID kputstr(const UBYTE *s); +extern VOID KPutS(const UBYTE *s); +extern VOID kputs(const UBYTE *s); +extern VOID KPutStr(const UBYTE *s); + +/****************************************************************************/ + +#endif /* _DEBUG_HEADERS_H */ diff --git a/library/debug_kcmpstr.c b/library/debug_kcmpstr.c new file mode 100644 index 0000000..8fe0892 --- /dev/null +++ b/library/debug_kcmpstr.c @@ -0,0 +1,46 @@ +/* + * $Id: debug_kcmpstr.c,v 1.1.1.1 2004-07-26 16:30:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +LONG +KCmpStr(const char * source1,const char * source2) +{ + LONG result; + + result = cmpstrexec(source1,source2); + + return(result); +} diff --git a/library/debug_kdofmt.c b/library/debug_kdofmt.c new file mode 100644 index 0000000..61832d8 --- /dev/null +++ b/library/debug_kdofmt.c @@ -0,0 +1,45 @@ +/* + * $Id: debug_kdofmt.c,v 1.1.1.1 2004-07-26 16:30:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +VOID +KDoFmt(const char * format_string,APTR data_stream,APTR put_char_routine,APTR put_char_data) +{ + assert( format_string != NULL ); + + if(format_string != NULL) + RawDoFmt((STRPTR)format_string,data_stream,(VOID (*)())put_char_routine,put_char_data); +} diff --git a/library/debug_kgetc.c b/library/debug_kgetc.c new file mode 100644 index 0000000..91b5cae --- /dev/null +++ b/library/debug_kgetc.c @@ -0,0 +1,48 @@ +/* + * $Id: debug_kgetc.c,v 1.1.1.1 2004-07-26 16:30:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +LONG +kgetc(VOID) +{ + LONG result; + + do + result = KMayGetChar(); + while(result < 0); + + return(result); +} diff --git a/library/debug_kgetch1.c b/library/debug_kgetch1.c new file mode 100644 index 0000000..0e90870 --- /dev/null +++ b/library/debug_kgetch1.c @@ -0,0 +1,46 @@ +/* + * $Id: debug_kgetch1.c,v 1.1.1.1 2004-07-26 16:30:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +LONG +kgetch(VOID) +{ + LONG result; + + result = kgetc(); + + return(result); +} diff --git a/library/debug_kgetch2.c b/library/debug_kgetch2.c new file mode 100644 index 0000000..7b35164 --- /dev/null +++ b/library/debug_kgetch2.c @@ -0,0 +1,46 @@ +/* + * $Id: debug_kgetch2.c,v 1.1.1.1 2004-07-26 16:30:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +LONG +KGetCh(VOID) +{ + LONG result; + + result = kgetc(); + + return(result); +} diff --git a/library/debug_kgetchar1.c b/library/debug_kgetchar1.c new file mode 100644 index 0000000..29309d1 --- /dev/null +++ b/library/debug_kgetchar1.c @@ -0,0 +1,46 @@ +/* + * $Id: debug_kgetchar1.c,v 1.1.1.1 2004-07-26 16:30:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +LONG +kgetchar(VOID) +{ + LONG result; + + result = kgetc(); + + return(result); +} diff --git a/library/debug_kgetchar2.c b/library/debug_kgetchar2.c new file mode 100644 index 0000000..ee9500d --- /dev/null +++ b/library/debug_kgetchar2.c @@ -0,0 +1,46 @@ +/* + * $Id: debug_kgetchar2.c,v 1.1.1.1 2004-07-26 16:30:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +LONG +KGetChar(VOID) +{ + LONG result; + + result = kgetc(); + + return(result); +} diff --git a/library/debug_kgetnum1.c b/library/debug_kgetnum1.c new file mode 100644 index 0000000..f9ba9e2 --- /dev/null +++ b/library/debug_kgetnum1.c @@ -0,0 +1,110 @@ +/* + * $Id: debug_kgetnum1.c,v 1.1.1.1 2004-07-26 16:30:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +LONG +kgetnum(VOID) +{ + LONG sum = 0; + LONG result; + BOOL is_negative = FALSE; + LONG position = 0; + LONG c; + + while(TRUE) + { + c = kgetc(); + + if(c == '-') + { + if(position == 0) + { + is_negative = TRUE; + + kputc(c); + + position++; + } + } + else if (c == '\b') + { + if(position > 0) + { + position--; + if(position == 0) + { + is_negative = FALSE; + + sum = 0; + } + else + { + sum = sum / 10; + } + + kputc(c); + kputc(' '); + kputc(c); + } + } + else if (c == '\r') + { + kputc('\n'); + break; + } + else if ('0' <= c && c <= '9') + { + LONG new_sum; + + new_sum = sum * 10 + (c - '0'); + if(new_sum >= sum) + { + sum = new_sum; + + kputc(c); + + position++; + } + } + } + + if(is_negative) + result = (-sum); + else + result = sum; + + return(result); +} diff --git a/library/debug_kgetnum2.c b/library/debug_kgetnum2.c new file mode 100644 index 0000000..7c8deb1 --- /dev/null +++ b/library/debug_kgetnum2.c @@ -0,0 +1,46 @@ +/* + * $Id: debug_kgetnum2.c,v 1.1.1.1 2004-07-26 16:30:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +LONG +KGetNum(void) +{ + LONG result; + + result = kgetnum(); + + return(result); +} diff --git a/library/debug_kmaygetch.c b/library/debug_kmaygetch.c new file mode 100644 index 0000000..ef123a1 --- /dev/null +++ b/library/debug_kmaygetch.c @@ -0,0 +1,46 @@ +/* + * $Id: debug_kmaygetch.c,v 1.1.1.1 2004-07-26 16:30:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +LONG +KMayGetCh(VOID) +{ + LONG result; + + result = KMayGetChar(); + + return(result); +} diff --git a/library/debug_kmaygetchar.c b/library/debug_kmaygetchar.c new file mode 100644 index 0000000..07866c3 --- /dev/null +++ b/library/debug_kmaygetchar.c @@ -0,0 +1,55 @@ +/* + * $Id: debug_kmaygetchar.c,v 1.1.1.1 2004-07-26 16:30:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +LONG +KMayGetChar(VOID) +{ + LONG result; + + #if defined(__amigaos4__) + { + /* Call RawMayGetChar() through the 68k LVO. */ + result = EmulateTags(SysBase, ET_Offset, -510, TAG_DONE); + } + #else + { + result = RawMayGetChar(); + } + #endif /* __amigaos4__ */ + + return(result); +} diff --git a/library/debug_kprintf1.c b/library/debug_kprintf1.c new file mode 100644 index 0000000..dc03493 --- /dev/null +++ b/library/debug_kprintf1.c @@ -0,0 +1,51 @@ +/* + * $Id: debug_kprintf1.c,v 1.1.1.1 2004-07-26 16:30:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +VOID +kprintf(const char * format,...) +{ + assert( format != NULL ); + + if(format != NULL) + { + va_list arg; + + va_start(arg,format); + KPutFmt(format,arg); + va_end(arg); + } +} diff --git a/library/debug_kprintf2.c b/library/debug_kprintf2.c new file mode 100644 index 0000000..fad139d --- /dev/null +++ b/library/debug_kprintf2.c @@ -0,0 +1,51 @@ +/* + * $Id: debug_kprintf2.c,v 1.1.1.1 2004-07-26 16:30:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +VOID +KPrintF(const char * format,...) +{ + assert( format != NULL ); + + if(format != NULL) + { + va_list arg; + + va_start(arg,format); + KPutFmt(format,arg); + va_end(arg); + } +} diff --git a/library/debug_kputc.c b/library/debug_kputc.c new file mode 100644 index 0000000..ecb4e08 --- /dev/null +++ b/library/debug_kputc.c @@ -0,0 +1,51 @@ +/* + * $Id: debug_kputc.c,v 1.1.1.1 2004-07-26 16:30:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +VOID +kputc(UBYTE c) +{ + #if defined(__amigaos4__) + { + /* Call RawPutChar() through the 68k LVO. */ + EmulateTags(SysBase, ET_Offset, -516, ET_RegisterD0, c, TAG_DONE); + } + #else + { + RawPutChar(c); + } + #endif /* __amigaos4__ */ +} diff --git a/library/debug_kputch1.c b/library/debug_kputch1.c new file mode 100644 index 0000000..65e250c --- /dev/null +++ b/library/debug_kputch1.c @@ -0,0 +1,42 @@ +/* + * $Id: debug_kputch1.c,v 1.1.1.1 2004-07-26 16:30:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +VOID +kputch(UBYTE c) +{ + kputc(c); +} diff --git a/library/debug_kputch2.c b/library/debug_kputch2.c new file mode 100644 index 0000000..232a5ca --- /dev/null +++ b/library/debug_kputch2.c @@ -0,0 +1,42 @@ +/* + * $Id: debug_kputch2.c,v 1.1.1.1 2004-07-26 16:30:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +VOID +KPutCh(UBYTE c) +{ + kputc(c); +} diff --git a/library/debug_kputchar1.c b/library/debug_kputchar1.c new file mode 100644 index 0000000..d96396a --- /dev/null +++ b/library/debug_kputchar1.c @@ -0,0 +1,42 @@ +/* + * $Id: debug_kputchar1.c,v 1.1.1.1 2004-07-26 16:30:29 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +VOID +kputchar(UBYTE c) +{ + kputc(c); +} diff --git a/library/debug_kputchar2.c b/library/debug_kputchar2.c new file mode 100644 index 0000000..e42dec8 --- /dev/null +++ b/library/debug_kputchar2.c @@ -0,0 +1,42 @@ +/* + * $Id: debug_kputchar2.c,v 1.1.1.1 2004-07-26 16:30:29 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +VOID +KPutChar(UBYTE c) +{ + kputc(c); +} diff --git a/library/debug_kputfmt.c b/library/debug_kputfmt.c new file mode 100644 index 0000000..3961777 --- /dev/null +++ b/library/debug_kputfmt.c @@ -0,0 +1,194 @@ +/* + * $Id: debug_kputfmt.c,v 1.1.1.1 2004-07-26 16:30:29 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +#if defined(__amigaos4__) + +/****************************************************************************/ + +/* Count the number of parameters that need to be passed on the stack. If a + parameter table is provided, pick up the parameters and store them in + the table. The table layout follows the format string and can include + both 16 and 32 bit data. */ +static size_t +process_var_args(char *format_string,va_list argument_list,unsigned short * table) +{ + size_t num_args = 0; + char len; + char c; + + while((c = (*format_string++)) != '\0') + { + if(c != '%') + continue; + + /* Process the flags; only '-' is allowed here. */ + if((*format_string) == '-') + format_string++; + + /* Process the field width; this must be a string of digits. */ + c = (*format_string); + while('0' <= c && c <= '9') + { + format_string++; + + c = (*format_string); + } + + /* Process the size limit field, if any. */ + if((*format_string) == '.') + { + format_string++; + + c = (*format_string); + while('0' <= c && c <= '9') + { + format_string++; + + c = (*format_string); + } + } + + /* Take care of the parameter length, if any. */ + len = (*format_string); + if(len == 'l') + format_string++; + + c = (*format_string++); + if(c == '\0') + break; + + /* Check if any of the following parameters might come from the + stack, and if so, convert them into the form expected by the + operating system. */ + switch(c) + { + /* 32 bit pointers (BSTR or STRPTR) */ + case 'b': + case 's': + + if(table != NULL) + (*(unsigned long *)&table[num_args]) = (unsigned long)va_arg(argument_list,char *); + + num_args += 2; + break; + + /* Single character */ + case 'c': + + /* NOTE: va_arg() is quietly assumed not to be able to expand 'char' type + parameters. They appear to default to 'int' and should show up as such + on the stack (or wherever they ended up). We therefore assume that they + should be picked up as type 'int' rather than as type 'char'. */ + + /* Numeric constant, which is assumed to be of type int. */ + case 'd': + case 'u': + case 'x': + + if(table != NULL) + { + if(len == 'l') + (*(unsigned long *)&table[num_args]) = (unsigned long)va_arg(argument_list,int); + else + table[num_args] = (unsigned short)va_arg(argument_list,int); + } + + if(len == 'l') + num_args += 2; + else + num_args++; + + break; + + /* Anything else is taken as is... */ + default: + + break; + } + } + + return(num_args); +} + +/****************************************************************************/ + +#endif /* __amigaos4__ */ + +/****************************************************************************/ + +static VOID ASM +raw_put_char(REG(d0,UBYTE c)) +{ + kputc(c); +} + +/****************************************************************************/ + +VOID +KPutFmt(const char * format_string,va_list argument_list) +{ + assert( format_string != NULL ); + + if(format_string != NULL) + { + #if defined(__amigaos4__) + { + size_t num_args; + + /* The following assumes that GCC extensions are available. */ + + num_args = process_var_args((char *)format_string,argument_list,NULL); + if(num_args > 0) + { + unsigned short table[num_args]; + + (void)process_var_args((char *)format_string,argument_list,table); + + KDoFmt(format_string,(APTR)table,(APTR)raw_put_char,NULL); + } + else + { + KDoFmt(format_string,NULL,(APTR)raw_put_char,NULL); + } + } + #else + { + KDoFmt(format_string,(APTR)argument_list,(APTR)raw_put_char,NULL); + } + #endif /* __amigaos4__ */ + } +} diff --git a/library/debug_kputs1.c b/library/debug_kputs1.c new file mode 100644 index 0000000..27fda6c --- /dev/null +++ b/library/debug_kputs1.c @@ -0,0 +1,44 @@ +/* + * $Id: debug_kputs1.c,v 1.1.1.1 2004-07-26 16:30:29 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +void +KPutS(const UBYTE * s) +{ + assert( s != NULL ); + + kputstr(s); +} diff --git a/library/debug_kputs2.c b/library/debug_kputs2.c new file mode 100644 index 0000000..d4ee490 --- /dev/null +++ b/library/debug_kputs2.c @@ -0,0 +1,44 @@ +/* + * $Id: debug_kputs2.c,v 1.1.1.1 2004-07-26 16:30:29 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +void +kputs(const UBYTE * s) +{ + assert( s != NULL ); + + kputstr(s); +} diff --git a/library/debug_kputstr1.c b/library/debug_kputstr1.c new file mode 100644 index 0000000..7a8cbfc --- /dev/null +++ b/library/debug_kputstr1.c @@ -0,0 +1,50 @@ +/* + * $Id: debug_kputstr1.c,v 1.1.1.1 2004-07-26 16:30:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +void +kputstr(const UBYTE * s) +{ + assert( s != NULL ); + + if(s != NULL) + { + UBYTE c; + + while((c = (*s++)) != '\0') + kputc(c); + } +} diff --git a/library/debug_kputstr2.c b/library/debug_kputstr2.c new file mode 100644 index 0000000..3b18225 --- /dev/null +++ b/library/debug_kputstr2.c @@ -0,0 +1,44 @@ +/* + * $Id: debug_kputstr2.c,v 1.1.1.1 2004-07-26 16:30:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +void +KPutStr(const UBYTE * s) +{ + assert( s != NULL ); + + kputstr(s); +} diff --git a/library/debug_kvprintf1.c b/library/debug_kvprintf1.c new file mode 100644 index 0000000..cb04c78 --- /dev/null +++ b/library/debug_kvprintf1.c @@ -0,0 +1,45 @@ +/* + * $Id: debug_kvprintf1.c,v 1.1.1.1 2004-07-26 16:30:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +VOID +kvprintf(const char * format,va_list arg) +{ + assert( format != NULL ); + + if(format != NULL) + KPutFmt(format,arg); +} diff --git a/library/debug_kvprintf2.c b/library/debug_kvprintf2.c new file mode 100644 index 0000000..7db323a --- /dev/null +++ b/library/debug_kvprintf2.c @@ -0,0 +1,45 @@ +/* + * $Id: debug_kvprintf2.c,v 1.1.1.1 2004-07-26 16:30:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "debug_headers.h" + +/****************************************************************************/ + +VOID +KVPrintF(const char * format,va_list arg) +{ + assert( format != NULL ); + + if(format != NULL) + KPutFmt(format,arg); +} diff --git a/library/debug_level.c b/library/debug_level.c new file mode 100644 index 0000000..e4bcb36 --- /dev/null +++ b/library/debug_level.c @@ -0,0 +1,37 @@ +/* + * $Id: debug_level.c,v 1.1.1.1 2004-07-26 16:30:30 obarthel Exp $ + * + * :ts=8 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/****************************************************************************/ + +/* By default, show and test only assertions. */ +int __debug_level = 0; diff --git a/library/dirent_closedir.c b/library/dirent_closedir.c new file mode 100644 index 0000000..6c32c57 --- /dev/null +++ b/library/dirent_closedir.c @@ -0,0 +1,112 @@ +/* + * $Id: dirent_closedir.c,v 1.1.1.1 2004-07-26 16:30:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _DIRENT_HEADERS_H +#include "dirent_headers.h" +#endif /* _DIRENT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +closedir(DIR * directory_pointer) +{ + struct DirectoryHandle * dh; + struct Node * node; + int result = -1; + + ENTER(); + + SHOWPOINTER(directory_pointer); + + if(__check_abort_enabled) + __check_abort(); + + if(directory_pointer == NULL) + { + errno = EBADF; + goto out; + } + + #ifndef NDEBUG + { + BOOL directory_pointer_is_valid = FALSE; + + for(dh = (struct DirectoryHandle *)__directory_list.mlh_Head ; + dh->dh_MinNode.mln_Succ != NULL ; + dh = (struct DirectoryHandle *)dh->dh_MinNode.mln_Succ) + { + if(dh == (struct DirectoryHandle *)directory_pointer) + { + directory_pointer_is_valid = TRUE; + break; + } + } + + if(NOT directory_pointer_is_valid) + { + errno = EBADF; + goto out; + } + } + #endif /* NDEBUG */ + + dh = (struct DirectoryHandle *)directory_pointer; + + Remove((struct Node *)dh); + + while((node = RemHead(&dh->dh_VolumeList)) != NULL) + free(node); + + PROFILE_OFF(); + UnLock(dh->dh_DirLock); + PROFILE_ON(); + + free(dh); + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/dirent_data.c b/library/dirent_data.c new file mode 100644 index 0000000..964398c --- /dev/null +++ b/library/dirent_data.c @@ -0,0 +1,72 @@ +/* + * $Id: dirent_data.c,v 1.1.1.1 2004-07-26 16:30:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DIRENT_HEADERS_H +#include "dirent_headers.h" +#endif /* _DIRENT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +/* Directories being scanned whose locks need to be freed when shutting down. */ +struct MinList __directory_list; + +/****************************************************************************/ + +CLIB_CONSTRUCTOR(__dirent_init) +{ + ENTER(); + + NewList((struct List *)&__directory_list); + + RETURN(OK); + CONSTRUCTOR_SUCCEED(); +} + +/****************************************************************************/ + +CLIB_DESTRUCTOR(__dirent_exit) +{ + ENTER(); + + if(__directory_list.mlh_Head != NULL) + { + while(NOT IsListEmpty((struct List *)&__directory_list)) + closedir((DIR *)__directory_list.mlh_Head); + } + + LEAVE(); +} diff --git a/library/dirent_headers.h b/library/dirent_headers.h new file mode 100644 index 0000000..839126e --- /dev/null +++ b/library/dirent_headers.h @@ -0,0 +1,63 @@ +/* + * $Id: dirent_headers.h,v 1.1.1.1 2004-07-26 16:30:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DIRENT_HEADERS_H +#define _DIRENT_HEADERS_H + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +struct DirectoryHandle +{ + struct MinNode dh_MinNode; + BPTR dh_DirLock; + struct FileInfoBlock dh_FileInfo; + struct dirent dh_DirectoryEntry; + int dh_Position; + struct Node * dh_VolumeNode; + struct List dh_VolumeList; + BOOL dh_ScanVolumeList; +}; + +/****************************************************************************/ + +extern struct MinList __directory_list; + +/****************************************************************************/ + +#endif /* _DIRENT_HEADERS_H */ diff --git a/library/dirent_opendir.c b/library/dirent_opendir.c new file mode 100644 index 0000000..2e93e45 --- /dev/null +++ b/library/dirent_opendir.c @@ -0,0 +1,269 @@ +/* + * $Id: dirent_opendir.c,v 1.1.1.1 2004-07-26 16:30:31 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _DIRENT_HEADERS_H +#include "dirent_headers.h" +#endif /* _DIRENT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#if defined(UNIX_PATH_SEMANTICS) + +/****************************************************************************/ + +static struct Node * +find_by_name(struct List * list,const char * name) +{ + struct Node * result = NULL; + struct Node * node; + + for(node = list->lh_Head ; node->ln_Succ != NULL ; node = node->ln_Succ) + { + if(strcasecmp(node->ln_Name,name) == 0) + { + result = node; + break; + } + } + + return(result); +} + +/****************************************************************************/ + +#endif /* UNIX_PATH_SEMANTICS */ + +/****************************************************************************/ + +DIR * +opendir(const char * path_name) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info path_name_nti; + #endif /* UNIX_PATH_SEMANTICS */ + struct DirectoryHandle * dh = NULL; + DIR * result = NULL; + struct Node * node; + + ENTER(); + + SHOWSTRING(path_name); + + assert( path_name != NULL ); + + if(__check_abort_enabled) + __check_abort(); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL) + { + SHOWMSG("invalid parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + dh = malloc(sizeof(*dh)); + if(dh == NULL) + { + SHOWMSG("memory allocation failed"); + goto out; + } + + memset(dh,0,sizeof(*dh)); + + NewList(&dh->dh_VolumeList); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + + SHOWSTRING(path_name); + + if(path_name_nti.is_root) + { + struct DosList * dol; + UBYTE * name; + + SHOWMSG("collecting volume names"); + + dh->dh_ScanVolumeList = TRUE; + + PROFILE_OFF(); + dol = LockDosList(LDF_VOLUMES|LDF_READ); + PROFILE_ON(); + + while((dol = NextDosEntry(dol,LDF_VOLUMES|LDF_READ)) != NULL) + { + name = BADDR(dol->dol_Name); + if(name != NULL && name[0] > 0) + { + size_t len; + + len = name[0]; + + node = malloc(sizeof(*node) + len + 2); + if(node == NULL) + { + UnLockDosList(LDF_VOLUMES|LDF_READ); + + errno = ENOMEM; + goto out; + } + + node->ln_Name = (char *)(node + 1); + + memmove(node->ln_Name,&name[1],len); + node->ln_Name[len++] = ':'; + node->ln_Name[len] = '\0'; + + /* Check if the name is already on the list. Mind you, + this is not the most sophisticated algorithm but then + the number of volumes should be small. */ + if(find_by_name(&dh->dh_VolumeList,node->ln_Name) != NULL) + { + free(node); + continue; + } + + D(("adding '%s'",node->ln_Name)); + + AddTail(&dh->dh_VolumeList,node); + } + } + + UnLockDosList(LDF_VOLUMES|LDF_READ); + + /* Bail out if we cannot present anything. */ + if(IsListEmpty(&dh->dh_VolumeList)) + { + errno = ENOMEM; + goto out; + } + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + if(NOT dh->dh_ScanVolumeList) + { + LONG status; + + SHOWMSG("we are supposed to scan a directory"); + SHOWSTRING(path_name); + + PROFILE_OFF(); + dh->dh_DirLock = Lock((STRPTR)path_name,SHARED_LOCK); + PROFILE_ON(); + + if(dh->dh_DirLock == ZERO) + { + SHOWMSG("couldn't get a lock on it"); + + __translate_access_io_error_to_errno(IoErr(),&errno); + goto out; + } + + assert( (((ULONG)&dh->dh_FileInfo) & 3) == 0 ); + + PROFILE_OFF(); + status = Examine(dh->dh_DirLock,&dh->dh_FileInfo); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("couldn't examine it"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + if(dh->dh_FileInfo.fib_DirEntryType < 0) + { + SHOWMSG("this isn't a directory"); + + errno = ENOTDIR; + goto out; + } + } + + SHOWMSG("OK, done"); + + assert( __directory_list.mlh_Head != NULL ); + + AddTail((struct List *)&__directory_list,(struct Node *)dh); + + result = (DIR *)dh; + dh = NULL; + + out: + + if(dh != NULL) + { + SHOWMSG("ouch. cleaning up"); + + while((node = RemHead(&dh->dh_VolumeList)) != NULL) + free(node); + + PROFILE_OFF(); + UnLock(dh->dh_DirLock); + PROFILE_ON(); + + free(dh); + } + + RETURN(result); + return(result); +} diff --git a/library/dirent_readdir.c b/library/dirent_readdir.c new file mode 100644 index 0000000..bd0f718 --- /dev/null +++ b/library/dirent_readdir.c @@ -0,0 +1,227 @@ +/* + * $Id: dirent_readdir.c,v 1.1.1.1 2004-07-26 16:30:31 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DIRENT_HEADERS_H +#include "dirent_headers.h" +#endif /* _DIRENT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +struct dirent * +readdir(DIR * directory_pointer) +{ + struct dirent * result = NULL; + struct DirectoryHandle * dh; + BPTR parent_directory = ZERO; + + ENTER(); + + SHOWPOINTER(directory_pointer); + + if(__check_abort_enabled) + __check_abort(); + + PROFILE_OFF(); + + if(directory_pointer == NULL) + { + SHOWMSG("ouch. invalid parameter"); + + errno = EBADF; + goto out; + } + + dh = (struct DirectoryHandle *)directory_pointer; + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics && dh->dh_ScanVolumeList) + { + SHOWMSG("we are scanning the volume list"); + + if(dh->dh_Position == 0) + { + SHOWMSG("returning the ."); + + dh->dh_Position++; + + dh->dh_DirectoryEntry.d_ino = 0; + strcpy(dh->dh_DirectoryEntry.d_name,"."); + + result = &dh->dh_DirectoryEntry; + } + else + { + D_S(struct FileInfoBlock,fib); + struct MsgPort * port; + UBYTE * bcpl_name; + BPTR dir_lock; + UBYTE name[8]; + + if(dh->dh_VolumeNode == NULL && NOT IsListEmpty(&dh->dh_VolumeList)) + dh->dh_VolumeNode = dh->dh_VolumeList.lh_Head; + + bcpl_name = (STRPTR)((((ULONG)&name[0]) + 3UL) & ~3UL); + strcpy(bcpl_name,"\1:"); /* BSTR for ":" */ + + while(result == NULL && dh->dh_VolumeNode != NULL && dh->dh_VolumeNode->ln_Succ != NULL) + { + if(IsFileSystem(dh->dh_VolumeNode->ln_Name)) + { + port = DeviceProc(dh->dh_VolumeNode->ln_Name); + if(port != NULL) + { + dir_lock = DoPkt(port,ACTION_LOCATE_OBJECT,ZERO,MKBADDR(bcpl_name),SHARED_LOCK, 0,0); + if(dir_lock != ZERO) + { + if(Examine(dir_lock,fib)) + { + assert( sizeof(dh->dh_DirectoryEntry.d_name) >= sizeof(fib->fib_FileName) ); + + strcpy(dh->dh_DirectoryEntry.d_name,fib->fib_FileName); + + dh->dh_DirectoryEntry.d_ino = fib->fib_DiskKey; + + result = &dh->dh_DirectoryEntry; + } + + UnLock(dir_lock); + } + } + } + + dh->dh_VolumeNode = dh->dh_VolumeNode->ln_Succ; + } + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + if(NOT dh->dh_ScanVolumeList) + { + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(dh->dh_Position == 0) + { + SHOWMSG("returning ."); + + dh->dh_Position++; + + dh->dh_DirectoryEntry.d_ino = dh->dh_FileInfo.fib_DiskKey; + + strcpy(dh->dh_DirectoryEntry.d_name,"."); + + result = &dh->dh_DirectoryEntry; + } + else if (dh->dh_Position == 1) + { + D_S(struct FileInfoBlock,fib); + + dh->dh_Position++; + + parent_directory = ParentDir(dh->dh_DirLock); + if(parent_directory != ZERO) + { + if(CANNOT Examine(parent_directory,fib)) + { + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + } + else + { + /* This is the virtual root directory's key. */ + fib->fib_DiskKey = 0; + } + + SHOWMSG("returning .."); + + dh->dh_DirectoryEntry.d_ino = fib->fib_DiskKey; + + strcpy(dh->dh_DirectoryEntry.d_name,".."); + + result = &dh->dh_DirectoryEntry; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + if(result == NULL) + { + assert( (((ULONG)&dh->dh_FileInfo) & 3) == 0 ); + + if(ExNext(dh->dh_DirLock,&dh->dh_FileInfo)) + { + dh->dh_DirectoryEntry.d_ino = dh->dh_FileInfo.fib_DiskKey; + + assert( sizeof(dh->dh_DirectoryEntry.d_name) >= sizeof(dh->dh_FileInfo.fib_FileName) ); + + strcpy(dh->dh_DirectoryEntry.d_name,dh->dh_FileInfo.fib_FileName); + + result = &dh->dh_DirectoryEntry; + } + else + { + if(IoErr() != ERROR_NO_MORE_ENTRIES) + { + SHOWMSG("error scanning directory"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + SHOWMSG("that was the end of the line"); + } + } + } + + if(result != NULL) + D(("next entry to return is '%s'",result->d_name)); + else + SHOWMSG("end of directory reached"); + + out: + + UnLock(parent_directory); + + PROFILE_ON(); + + RETURN(result); + return(result); +} diff --git a/library/dirent_rewinddir.c b/library/dirent_rewinddir.c new file mode 100644 index 0000000..b1445bf --- /dev/null +++ b/library/dirent_rewinddir.c @@ -0,0 +1,87 @@ +/* + * $Id: dirent_rewinddir.c,v 1.1.1.1 2004-07-26 16:30:31 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DIRENT_HEADERS_H +#include "dirent_headers.h" +#endif /* _DIRENT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +void +rewinddir(DIR * directory_pointer) +{ + ENTER(); + + SHOWPOINTER(directory_pointer); + + if(__check_abort_enabled) + __check_abort(); + + PROFILE_OFF(); + + if(directory_pointer != NULL) + { + struct DirectoryHandle * dh; + + dh = (struct DirectoryHandle *)directory_pointer; + + dh->dh_Position = 0; + + if(dh->dh_ScanVolumeList) + { + SHOWMSG("returning to first volume"); + + dh->dh_VolumeNode = NULL; + } + else + { + SHOWMSG("calling Examine() again"); + + assert( (((ULONG)&dh->dh_FileInfo) & 3) == 0 ); + + if(CANNOT Examine(dh->dh_DirLock,&dh->dh_FileInfo)) + { + SHOWMSG("ouch. that didn't work"); + __translate_io_error_to_errno(IoErr(),&errno); + } + } + } + + PROFILE_ON(); + + LEAVE(); +} diff --git a/library/errno_data.c b/library/errno_data.c new file mode 100644 index 0000000..0d1af8c --- /dev/null +++ b/library/errno_data.c @@ -0,0 +1,40 @@ +/* + * $Id: errno_data.c,v 1.1.1.1 2004-07-26 16:30:32 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ERRNO_H +#include +#endif /* _ERRNO_H */ + +/****************************************************************************/ + +int errno; diff --git a/library/fcntl_close.c b/library/fcntl_close.c new file mode 100644 index 0000000..67546c4 --- /dev/null +++ b/library/fcntl_close.c @@ -0,0 +1,179 @@ +/* + * $Id: fcntl_close.c,v 1.1.1.1 2004-07-26 16:30:32 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _FCNTL_HEADERS_H +#include "fcntl_headers.h" +#endif /* _FCNTL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +__close(int file_descriptor,int * error_ptr) +{ + DECLARE_UTILITYBASE(); + struct fd * fd; + int result = -1; + BOOL no_close; + + ENTER(); + + SHOWVALUE(file_descriptor); + + assert( UtilityBase != NULL ); + + assert( error_ptr != NULL ); + assert( file_descriptor >= 0 && file_descriptor < __num_fd ); + assert( __fd[file_descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + (*error_ptr) = EBADF; + goto out; + } + + result = 0; + + SHOWMSG("last customer; cleaning up"); + + if(fd->fd_Original != NULL) /* this is an alias */ + { + struct fd * list_fd; + + SHOWMSG("taking out the alias"); + + assert( fd->fd_Original != fd ); + assert( fd->fd_Original->fd_Original == NULL ); + + /* Remove this alias from the list. */ + for(list_fd = fd->fd_Original ; + list_fd != NULL ; + list_fd = list_fd->fd_NextLink) + { + if(list_fd->fd_NextLink == fd) + { + list_fd->fd_NextLink = fd->fd_NextLink; + break; + } + } + + no_close = TRUE; + } + else if (fd->fd_NextLink != NULL) /* this one has aliases attached; it is the 'original' resource */ + { + struct fd * first_alias; + struct fd * list_fd; + + SHOWMSG("closing original descriptor; migrating it to first alias"); + + /* The first link now becomes the original resource */ + first_alias = fd->fd_NextLink; + first_alias->fd_Original = NULL; + + /* The resources are migrated to the first link. */ + for(list_fd = first_alias->fd_NextLink ; + list_fd != NULL ; + list_fd = list_fd->fd_NextLink) + { + list_fd->fd_Original = first_alias; + } + + no_close = TRUE; + } + else + { + no_close = FLAG_IS_SET(fd->fd_Flags,FDF_NO_CLOSE); + } + + (*error_ptr) = OK; + + if(NOT no_close) + { + struct file_hook_message message; + + /* Reset the console to regular buffered input. */ + if(FLAG_IS_SET(fd->fd_Flags,FDF_NON_BLOCKING)) + { + SHOWMSG("resetting non-blocking access mode"); + + message.action = file_hook_action_set_blocking; + message.block = 1; + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + } + + SHOWMSG("shutting down"); + + message.action = file_hook_action_close; + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + + result = message.result; + + (*error_ptr) = message.error; + } + + memset(fd,0,sizeof(*fd)); + + out: + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +int +close(int file_descriptor) +{ + int result; + + ENTER(); + + result = __close(file_descriptor,&errno); + + RETURN(result); + return(result); +} diff --git a/library/fcntl_creat.c b/library/fcntl_creat.c new file mode 100644 index 0000000..8c35591 --- /dev/null +++ b/library/fcntl_creat.c @@ -0,0 +1,81 @@ +/* + * $Id: fcntl_creat.c,v 1.1.1.1 2004-07-26 16:30:32 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _FCNTL_HEADERS_H +#include "fcntl_headers.h" +#endif /* _FCNTL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +creat(const char * path_name, mode_t mode) +{ + int result = -1; + + ENTER(); + + SHOWSTRING(path_name); + SHOWVALUE(mode); + + if(__check_abort_enabled) + __check_abort(); + + assert( path_name != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + result = open(path_name,O_WRONLY|O_CREAT|O_TRUNC,mode); + + out: + + RETURN(result); + return(result); +} diff --git a/library/fcntl_fcntl.c b/library/fcntl_fcntl.c new file mode 100644 index 0000000..4f9a598 --- /dev/null +++ b/library/fcntl_fcntl.c @@ -0,0 +1,247 @@ +/* + * $Id: fcntl_fcntl.c,v 1.1.1.1 2004-07-26 16:30:33 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _FCNTL_HEADERS_H +#include "fcntl_headers.h" +#endif /* _FCNTL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +fcntl(int file_descriptor, int cmd, ... /* int arg */ ) +{ + DECLARE_UTILITYBASE(); + struct file_hook_message message; + struct flock * l; + int result = -1; + struct fd * fd; + va_list arg; + int flags; + int fdbase; + int i; + + ENTER(); + + SHOWVALUE(file_descriptor); + SHOWVALUE(cmd); + + assert( UtilityBase != NULL ); + + assert( file_descriptor >= 0 && file_descriptor < __num_fd ); + assert( __fd[file_descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + errno = EBADF; + goto out; + } + + switch(cmd) + { + case F_GETLK: + case F_SETLK: + case F_SETLKW: + + SHOWMSG("cmd=F_GETLK/F_SETLK/F_SETLKW"); + + va_start(arg,cmd); + + l = va_arg(arg,struct flock *); + + assert( l != NULL ); + + if(l->l_type < F_RDLCK || l->l_type > F_WRLCK) + { + SHOWMSG("invalid flock type"); + va_end(arg); + + errno = EINVAL; + break; + } + + if(l->l_whence < SEEK_SET || l->l_whence > SEEK_END) + { + SHOWMSG("invalid flock offset"); + va_end(arg); + + errno = EINVAL; + break; + } + + message.action = file_hook_action_lock_record; + message.lock = l; + message.command = cmd; + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + + result = message.result; + errno = message.error; + + va_end(arg); + + break; + + case F_GETFL: + + SHOWMSG("cmd=F_GETFL"); + + if(FLAG_IS_SET(fd->fd_Flags,FDF_NON_BLOCKING)) + result = O_NONBLOCK; + else + result = 0; + + break; + + case F_SETFL: + + SHOWMSG("cmd=F_SETFL"); + + result = 0; + + va_start(arg,cmd); + + flags = va_arg(arg,int); + + if((FLAG_IS_SET(flags,O_NONBLOCK) && FLAG_IS_CLEAR(fd->fd_Flags,FDF_NON_BLOCKING)) || + (FLAG_IS_CLEAR(flags,O_NONBLOCK) && FLAG_IS_SET(fd->fd_Flags,FDF_NON_BLOCKING))) + { + message.action = file_hook_action_set_blocking; + message.block = FLAG_IS_CLEAR(flags,O_NONBLOCK); + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + + result = message.result; + if(result < 0) + { + errno = message.error; + + va_end(arg); + goto out; + } + + if(FLAG_IS_SET(flags,O_NONBLOCK)) + SET_FLAG(fd->fd_Flags,FDF_NON_BLOCKING); + else + CLEAR_FLAG(fd->fd_Flags,FDF_NON_BLOCKING); + } + + va_end(arg); + + break; + + case F_DUPFD: + + SHOWMSG("cmd=F_DUPFD"); + + va_start(arg, cmd); + fdbase = va_arg(arg, int); + va_end(arg); + + if(fdbase < 0) + { + errno = EINVAL; + goto out; + } + + /* Check if we have that many fd's already */ + while(fdbase >= __num_fd) + { + if(__check_abort_enabled) + __check_abort(); + + /* No; enlarge it */ + if(__grow_fd_table() < 0) + goto out; + } + + /* Guaranteed to have enough here */ + while(TRUE) + { + if(__check_abort_enabled) + __check_abort(); + + for(i = fdbase ; i < __num_fd ; i++) + { + if(FLAG_IS_CLEAR(__fd[i]->fd_Flags,FDF_IN_USE)) + { + /* Got a file descriptor, duplicate it */ + message.action = file_hook_action_duplicate_fd; + message.duplicate_fd = __fd[i]; + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + + /* If it worked, leave */ + if (message.result == 0) + { + result = i; + goto out; + } + } + } + + /* Didn't really find any, grow the table further */ + if (__grow_fd_table() < 0) + goto out; + } + + errno = EMFILE; + break; + + default: + + SHOWMSG("something else"); + + errno = ENOSYS; + break; + } + + out: + + RETURN(result); + return(result); +} diff --git a/library/fcntl_headers.h b/library/fcntl_headers.h new file mode 100644 index 0000000..1d2d794 --- /dev/null +++ b/library/fcntl_headers.h @@ -0,0 +1,45 @@ +/* + * $Id: fcntl_headers.h,v 1.1.1.1 2004-07-26 16:30:33 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _FCNTL_HEADERS_H +#define _FCNTL_HEADERS_H + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#endif /* _FCNTL_HEADERS_H */ diff --git a/library/fcntl_lseek.c b/library/fcntl_lseek.c new file mode 100644 index 0000000..cc5ad0b --- /dev/null +++ b/library/fcntl_lseek.c @@ -0,0 +1,125 @@ +/* + * $Id: fcntl_lseek.c,v 1.1.1.1 2004-07-26 16:30:33 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _FCNTL_HEADERS_H +#include "fcntl_headers.h" +#endif /* _FCNTL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +off_t +__lseek(int file_descriptor, off_t offset, int mode, int * error_ptr) +{ + DECLARE_UTILITYBASE(); + struct file_hook_message message; + off_t result = -1; + struct fd * fd; + + ENTER(); + + SHOWVALUE(file_descriptor); + SHOWVALUE(offset); + SHOWVALUE(mode); + + assert( UtilityBase != NULL ); + + assert( error_ptr != NULL ); + assert( file_descriptor >= 0 && file_descriptor < __num_fd ); + assert( __fd[file_descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + (*error_ptr) = EBADF; + goto out; + } + + if(mode < SEEK_SET || mode > SEEK_END) + { + SHOWMSG("seek mode is invalid"); + + (*error_ptr) = EINVAL; + goto out; + } + + SHOWMSG("calling the hook"); + + #if defined(UNIX_PATH_SEMANTICS) + { + message.action = file_hook_action_seek_and_extend; + } + #else + { + message.action = file_hook_action_seek; + } + #endif /* UNIX_PATH_SEMANTICS */ + + message.position = offset; + message.mode = mode; + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + + (*error_ptr) = message.error; + + result = message.result; + + out: + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +off_t +lseek(int file_descriptor, off_t offset, int mode) +{ + off_t result; + + ENTER(); + + result = __lseek(file_descriptor,offset,mode,&errno); + + RETURN(result); + return(result); +} diff --git a/library/fcntl_open.c b/library/fcntl_open.c new file mode 100644 index 0000000..cd0357c --- /dev/null +++ b/library/fcntl_open.c @@ -0,0 +1,475 @@ +/* + * $Id: fcntl_open.c,v 1.1.1.1 2004-07-26 16:30:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _FCNTL_HEADERS_H +#include "fcntl_headers.h" +#endif /* _FCNTL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +open(const char *path_name, int open_flag, ... /* mode_t mode */ ) +{ + DECLARE_UTILITYBASE(); + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info path_name_nti; + #endif /* UNIX_PATH_SEMANTICS */ + D_S(struct FileInfoBlock,fib); + LONG is_file_system = FALSE; + LONG open_mode; + BPTR lock = ZERO; + struct FileHandle * file_handle; + BPTR handle = ZERO; + BOOL create_new_file = FALSE; + LONG is_interactive; + int fd_slot_number; + struct fd * fd; + int access_mode; + int result = -1; + int i; + + ENTER(); + + SHOWSTRING(path_name); + SHOWVALUE(open_flag); + + assert(path_name != NULL); + assert( UtilityBase != NULL ); + + if(__check_abort_enabled) + __check_abort(); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL) + { + SHOWMSG("path name is invalid"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + access_mode = (open_flag & 3); + if(access_mode < O_RDONLY && access_mode > O_RDWR) + { + SHOWMSG("access mode is invalid"); + + errno = EINVAL; + goto out; + } + + fd_slot_number = __find_vacant_fd_entry(); + if(fd_slot_number < 0) + { + if(__grow_fd_table() < 0) + { + SHOWMSG("couldn't find a vacant file descriptor, and couldn't allocate one either"); + goto out; + } + + fd_slot_number = __find_vacant_fd_entry(); + assert( fd_slot_number >= 0 ); + } + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + + if(path_name_nti.is_root) + { + errno = EACCES; + goto out; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + if (Strnicmp(path_name, "PIPE:",5) == SAME && FLAG_IS_SET(open_flag, O_CREAT)) + { + open_mode = MODE_NEWFILE; + } + else if (Strnicmp(path_name,"NIL:",4) != SAME && FLAG_IS_SET(open_flag,O_CREAT)) + { + if(FLAG_IS_SET(open_flag,O_EXCL)) + { + LONG error; + + SHOWMSG("checking if the file to create already exists"); + + PROFILE_OFF(); + lock = Lock((STRPTR)path_name,SHARED_LOCK); + PROFILE_ON(); + + if(lock != ZERO) + { + SHOWMSG("the file already exists"); + + errno = EEXIST; + goto out; + } + + error = IoErr(); + + if(error == ERROR_OBJECT_WRONG_TYPE) + { + SHOWMSG("there's something not a directory on the path"); + + errno = ENOTDIR; + goto out; + } + else if (error != ERROR_OBJECT_NOT_FOUND && error != ERROR_ACTION_NOT_KNOWN) + { + SHOWMSG("error accessing the object"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + SHOWMSG("the object does not already exist"); + } + + open_mode = MODE_READWRITE; + + if(FLAG_IS_SET(open_flag,O_TRUNC)) + { + SHOWMSG("checking if the file to create already exists"); + + PROFILE_OFF(); + lock = Lock((STRPTR)path_name,SHARED_LOCK); + PROFILE_ON(); + + if(lock != ZERO) + { + LONG status; + + PROFILE_OFF(); + status = Examine(lock,fib); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("could not examine the object"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + /* We can open only files, but never directories. */ + if(fib->fib_DirEntryType >= 0) + { + SHOWMSG("can't open a directory"); + + errno = EISDIR; + goto out; + } + + if(FLAG_IS_SET(fib->fib_Protection,FIBF_WRITE) || + FLAG_IS_SET(fib->fib_Protection,FIBF_DELETE)) + { + SHOWMSG("this object is not write enabled"); + + errno = EACCES; + goto out; + } + + open_mode = MODE_NEWFILE; + + PROFILE_OFF(); + + UnLock(lock); + lock = ZERO; + + PROFILE_ON(); + } + else + { + LONG error; + + error = IoErr(); + + if(error == ERROR_OBJECT_WRONG_TYPE) + { + SHOWMSG("there's something not a directory on the path"); + + errno = ENOTDIR; + goto out; + } + else if (error != ERROR_OBJECT_NOT_FOUND && error != ERROR_ACTION_NOT_KNOWN) + { + SHOWMSG("error accessing the object"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + } + } + + create_new_file = TRUE; + } + else + { + open_mode = MODE_OLDFILE; + } + + SHOWSTRING(path_name); + + PROFILE_OFF(); + handle = Open((STRPTR)path_name,open_mode); + PROFILE_ON(); + + if(handle == ZERO) + { + LONG io_err = IoErr(); + + D(("the file '%s' didn't open in mode %ld",path_name,open_mode)); + __translate_access_io_error_to_errno(IoErr(),&errno); + + /* Check if ended up trying to open a directory as if + it were a plain file. */ + if(io_err == ERROR_OBJECT_WRONG_TYPE) + { + PROFILE_OFF(); + + lock = Lock((STRPTR)path_name,SHARED_LOCK); + if(lock != ZERO) + { + if(Examine(lock,fib) && fib->fib_DirEntryType >= 0) + errno = EISDIR; + } + + PROFILE_ON(); + } + + goto out; + } + + file_handle = BADDR(handle); + + /* NOTE: workaround for a bug in dos.library V40 and below which will + * crash the caller if the file handle refers to "NIL:". + */ + if(file_handle->fh_Type != NULL) + { + LONG status; + + PROFILE_OFF(); + status = ExamineFH(handle,fib); + PROFILE_ON(); + + if(status != DOSFALSE) + { + BOOL operation_permitted = TRUE; + + /* Check if the file is readable. */ + if(FLAG_IS_SET(fib->fib_Protection,FIBF_READ)) + { + if(access_mode == O_RDONLY || + access_mode == O_RDWR) + { + operation_permitted = FALSE; + } + } + + /* Check if the file can be written to. */ + if(FLAG_IS_SET(fib->fib_Protection,FIBF_WRITE)) + { + if(access_mode == O_WRONLY) + operation_permitted = FALSE; + } + + if(NOT operation_permitted) + { + SHOWMSG("this object must not be opened"); + + errno = EACCES; + goto out; + } + } + } + + fd = __fd[fd_slot_number]; + + __initialize_fd(fd,(HOOKFUNC)__fd_hook_entry,handle,0); + + PROFILE_OFF(); + is_interactive = IsInteractive(handle); + PROFILE_ON(); + + if(FLAG_IS_SET(open_flag,O_NONBLOCK)) + { + if(is_interactive) + { + SHOWMSG("enabling non-blocking mode"); + + if(SetMode(handle,1)) /* single character mode */ + SET_FLAG(fd->fd_Flags,FDF_NON_BLOCKING); + } + } + + if(NOT is_interactive) + { + size_t len; + + len = 0; + for(i = 0 ; i < (int)strlen(path_name) ; i++) + { + if(path_name[i] == ':') + { + len = i+1; + break; + } + } + + if(len > 0) + { + char * path_name_copy; + + path_name_copy = malloc(len+1); + if(path_name_copy != NULL) + { + memmove(path_name_copy,path_name,len); + path_name_copy[len] = '\0'; + + PROFILE_OFF(); + is_file_system = IsFileSystem(path_name_copy); + PROFILE_ON(); + + free(path_name_copy); + } + } + else + { + PROFILE_OFF(); + is_file_system = IsFileSystem(""); + PROFILE_ON(); + } + + if(is_file_system) + { + /* NOTE: workaround for a bug in dos.library V40 and below which will + * crash the caller if the file handle refers to "NIL:". + */ + if(file_handle->fh_Type != NULL) + { + /* We opened the file in exclusive access mode. Switch it back + into shared access mode so that its contents can be read + while it's still open. */ + if(open_mode == MODE_NEWFILE) + { + PROFILE_OFF(); + ChangeMode(CHANGE_FH,handle,SHARED_LOCK); + PROFILE_ON(); + } + } + + /* We should be able to seek in this file. */ + SET_FLAG(fd->fd_Flags,FDF_CACHE_POSITION); + } + } + + if(FLAG_IS_SET(open_flag,O_APPEND)) + { + SHOWMSG("appending; seeking to end of file"); + + PROFILE_OFF(); + Seek(handle,0,OFFSET_END); + PROFILE_ON(); + + SET_FLAG(fd->fd_Flags,FDF_APPEND); + } + + switch(access_mode) + { + case O_RDONLY: + + SET_FLAG(fd->fd_Flags,FDF_READ); + break; + + case O_WRONLY: + + SET_FLAG(fd->fd_Flags,FDF_WRITE); + break; + + case O_RDWR: + + SET_FLAG(fd->fd_Flags,FDF_READ); + SET_FLAG(fd->fd_Flags,FDF_WRITE); + break; + } + + if(create_new_file && is_file_system) + SET_FLAG(fd->fd_Flags,FDF_CREATED); + + SET_FLAG(fd->fd_Flags,FDF_IN_USE); + + result = fd_slot_number; + + handle = ZERO; + + assert( result != -1 ); + + out: + + PROFILE_OFF(); + + if(handle != ZERO) + Close(handle); + + UnLock(lock); + + PROFILE_ON(); + + RETURN(result); + return(result); +} diff --git a/library/fcntl_read.c b/library/fcntl_read.c new file mode 100644 index 0000000..7f4e833 --- /dev/null +++ b/library/fcntl_read.c @@ -0,0 +1,146 @@ +/* + * $Id: fcntl_read.c,v 1.1.1.1 2004-07-26 16:30:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _FCNTL_HEADERS_H +#include "fcntl_headers.h" +#endif /* _FCNTL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +ssize_t +__read(int file_descriptor, void * buffer, size_t num_bytes, int * error_ptr) +{ + DECLARE_UTILITYBASE(); + struct fd * fd; + off_t result = -1; + + ENTER(); + + SHOWVALUE(file_descriptor); + SHOWPOINTER(buffer); + SHOWVALUE(num_bytes); + + assert( error_ptr != NULL ); + assert( buffer != NULL ); + assert( (int)num_bytes >= 0); + assert( UtilityBase != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(buffer == NULL) + { + SHOWMSG("invalid buffer"); + + (*error_ptr) = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( file_descriptor >= 0 && file_descriptor < __num_fd ); + assert( __fd[file_descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + (*error_ptr) = EBADF; + goto out; + } + + if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_READ)) + { + SHOWMSG("this descriptor is not read-enabled"); + + (*error_ptr) = EBADF; + goto out; + } + + if(num_bytes > 0) + { + struct file_hook_message message; + + SHOWMSG("calling the hook"); + + message.action = file_hook_action_read; + message.data = buffer; + message.size = num_bytes; + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + + (*error_ptr) = message.error; + + result = message.result; + } + else + { + (*error_ptr) = 0; + + result = 0; + } + + out: + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +ssize_t +read(int file_descriptor, void * buffer, size_t num_bytes) +{ + ssize_t result; + + ENTER(); + + result = __read(file_descriptor,buffer,num_bytes,&errno); + + RETURN(result); + return(result); +} diff --git a/library/fcntl_write.c b/library/fcntl_write.c new file mode 100644 index 0000000..47fd026 --- /dev/null +++ b/library/fcntl_write.c @@ -0,0 +1,146 @@ +/* + * $Id: fcntl_write.c,v 1.1.1.1 2004-07-26 16:30:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _FCNTL_HEADERS_H +#include "fcntl_headers.h" +#endif /* _FCNTL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +ssize_t +__write(int file_descriptor, const void * buffer, size_t num_bytes, int * error_ptr) +{ + DECLARE_UTILITYBASE(); + struct fd * fd; + off_t result = -1; + + ENTER(); + + SHOWVALUE(file_descriptor); + SHOWPOINTER(buffer); + SHOWVALUE(num_bytes); + + assert( error_ptr != NULL ); + assert( buffer != NULL ); + assert( (int)num_bytes >= 0 ); + assert( UtilityBase != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(buffer == NULL) + { + SHOWMSG("invalid buffer address"); + + (*error_ptr) = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( file_descriptor >= 0 && file_descriptor < __num_fd ); + assert( __fd[file_descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + (*error_ptr) = EBADF; + goto out; + } + + if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_WRITE)) + { + SHOWMSG("file descriptor is not write-enabled"); + + (*error_ptr) = EBADF; + goto out; + } + + if(num_bytes > 0) + { + struct file_hook_message message; + + SHOWMSG("calling the hook"); + + message.action = file_hook_action_write; + message.data = (void *)buffer; + message.size = num_bytes; + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + + (*error_ptr) = message.error; + + result = message.result; + } + else + { + (*error_ptr) = 0; + + result = 0; + } + + out: + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +ssize_t +write(int file_descriptor, const void * buffer, size_t num_bytes) +{ + ssize_t result; + + ENTER(); + + result = __write(file_descriptor,buffer,num_bytes,&errno); + + RETURN(result); + return(result); +} diff --git a/library/include/assert.h b/library/include/assert.h new file mode 100644 index 0000000..56c372c --- /dev/null +++ b/library/include/assert.h @@ -0,0 +1,70 @@ +/* + * $Id: assert.h,v 1.1.1.1 2004-07-26 16:32:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ASSERT_H +#define _ASSERT_H + +/****************************************************************************/ + +#ifndef assert + +/****************************************************************************/ + +#ifndef NDEBUG + +/****************************************************************************/ + +extern void __assertion_failure(const char *file_name,int line_number,const char * expression); + +/****************************************************************************/ + +#define assert(expression) \ + ((void)((expression) ? 0 : (__assertion_failure(__FILE__,__LINE__,#expression),0))) + +#else + +/****************************************************************************/ + +#define assert(expression) ((void)0) + +/****************************************************************************/ + +#endif /* NDEBUG */ + +/****************************************************************************/ + +#endif /* assert */ + +/****************************************************************************/ + +#endif /* _ASSERT_H */ diff --git a/library/include/ctype.h b/library/include/ctype.h new file mode 100644 index 0000000..8b9579d --- /dev/null +++ b/library/include/ctype.h @@ -0,0 +1,122 @@ +/* + * $Id: ctype.h,v 1.1.1.1 2004-07-26 16:32:50 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CYTPE_H +#define _CYTPE_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +extern int isalnum(int c); +extern int isalpha(int c); +extern int iscntrl(int c); + +extern int isdigit(int c); +extern int isxdigit(int c); + +extern int isgraph(int c); +extern int ispunct(int c); +extern int isprint(int c); + +extern int islower(int c); +extern int isupper(int c); + +extern int isspace(int c); + +extern int tolower(int c); +extern int toupper(int c); + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +#define isascii(c) ((unsigned)(c) <= 127) + +/****************************************************************************/ + +/* + * If requested, reimplement the character classification functions as macros; + * note that the macro variants ignore the current locale and default to the + * 'C' locale rules. Note that the characters to be tested must be either + * signed or unsigned 8 bit values. + */ + +#ifdef __C_MACROS__ + +/****************************************************************************/ + +extern const unsigned char * const __ctype_table; + +/****************************************************************************/ + +#define __CTYPE_CONTROL 0x01 /* This is a control character */ +#define __CTYPE_DIGIT 0x02 /* This is a 'decimal' digit */ +#define __CTYPE_HEX_DIGIT 0x04 /* This is a hexadecimal digit */ +#define __CTYPE_PUNCTUATION 0x08 /* This is a punctuation character */ +#define __CTYPE_PRINTABLE 0x10 /* This is a printable character */ +#define __CTYPE_WHITE_SPACE 0x20 /* This is a blank space character */ +#define __CTYPE_LOWER_CASE 0x40 /* This is a lower case letter */ +#define __CTYPE_UPPER_CASE 0x80 /* This is an upper case letter */ + +/****************************************************************************/ + +#define isalnum(c) ((__ctype_table[c] & (__CTYPE_DIGIT|__CTYPE_LOWER_CASE|__CTYPE_UPPER_CASE)) != 0) +#define isalpha(c) ((__ctype_table[c] & (__CTYPE_LOWER_CASE|__CTYPE_UPPER_CASE)) != 0) +#define iscntrl(c) ((__ctype_table[c] & __CTYPE_CONTROL) != 0) +#define isdigit(c) ((__ctype_table[c] & __CTYPE_DIGIT) != 0) +#define isxdigit(c) ((__ctype_table[c] & __CTYPE_HEX_DIGIT) != 0) +#define isgraph(c) ((__ctype_table[c] & (__CTYPE_DIGIT|__CTYPE_PUNCTUATION|__CTYPE_LOWER_CASE|__CTYPE_UPPER_CASE)) != 0) +#define ispunct(c) ((__ctype_table[c] & __CTYPE_PUNCTUATION) != 0) +#define isprint(c) ((__ctype_table[c] & __CTYPE_PRINTABLE) != 0) +#define islower(c) ((__ctype_table[c] & __CTYPE_LOWER_CASE) != 0) +#define isupper(c) ((__ctype_table[c] & __CTYPE_UPPER_CASE) != 0) +#define isspace(c) ((__ctype_table[c] & __CTYPE_WHITE_SPACE) != 0) + +/****************************************************************************/ + +#endif /* __C_MACROS__ */ + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _CYTPE_H */ diff --git a/library/include/dirent.h b/library/include/dirent.h new file mode 100644 index 0000000..d14ce2e --- /dev/null +++ b/library/include/dirent.h @@ -0,0 +1,88 @@ +/* + * $Id: dirent.h,v 1.1.1.1 2004-07-26 16:32:50 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DIRENT_H +#define _DIRENT_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _SYS_TYPES_H +#include +#endif /* _SYS_TYPES_H */ + +#ifndef _STDIO_H +#include +#endif /* _STDIO_H */ + +/****************************************************************************/ + +#define NAME_MAX FILENAME_MAX + +/****************************************************************************/ + +typedef long DIR; + +/****************************************************************************/ + +struct dirent +{ + ino_t d_ino; + char d_name[NAME_MAX+1]; +}; + +/****************************************************************************/ + +extern DIR * opendir(const char * path_name); +extern struct dirent * readdir(DIR * directory_pointer); +extern void rewinddir(DIR * directory_pointer); +extern int closedir(DIR * directory_pointer); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _DIRENT_H */ diff --git a/library/include/dos.h b/library/include/dos.h new file mode 100644 index 0000000..45312e3 --- /dev/null +++ b/library/include/dos.h @@ -0,0 +1,243 @@ +/* + * $Id: dos.h,v 1.1.1.1 2004-07-26 16:32:50 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DOS_H +#define _DOS_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _STDIO_H +#include +#endif /* _STDIO_H */ + +/****************************************************************************/ + +#ifndef WORKBENCH_STARTUP_H +#include +#endif /* WORKBENCH_STARTUP_H */ + +/****************************************************************************/ + +/* + * The Workbench startup message passed to this program; this may be NULL + * if the program was started from shell instead. + * + * The variable name is set up to be __WBenchMsg to make it fit into the + * ISO 'C' standard context. It is redefined to WBenchMsg to make it + * compatible with the original Amiga program startup code which would + * refer to the variable under that name. + */ +extern struct WBStartup * __WBenchMsg; +#define WBenchMsg __WBenchMsg + +/****************************************************************************/ + +/* This is filled in with a pointer to the name of the program being run. */ +extern char * __program_name; + +/****************************************************************************/ + +/* Set this to FALSE to disable all Ctrl+C checking in the program. */ +extern BOOL __check_abort_enabled; + +/* + * You can replace this function with your own and perform your own + * Ctrl+C checking. + */ +extern void __check_abort(void); + +/****************************************************************************/ + +/* + * Call this function to set up the environment information for your + * program to access its data. This is typically used in Task or Process + * functions, as launched from the main program. + * + * Note: this function is unavailable for residentable programs and may + * not be available for PowerPC programs. + */ +extern void geta4(void); + +/****************************************************************************/ + +/* + * Read and modify the current value of register A4; helpful for + * programs which are residentable, yet need to be able to pass the + * context information around A4 points to. + * + * Note: this function may not be available for PowerPC programs. + */ +extern unsigned long __get_a4(void); +extern void __set_a4(unsigned long value); + +/****************************************************************************/ + +/* + * This will be set to TRUE if the current program was launched from + * the internet superserver ('inetd') or an equivalent facility. + */ +extern BOOL __is_daemon; + +/****************************************************************************/ + +/* + * If the library is built with memory debugging features enabled, + * the following variable controls whether memory allocated, to be + * released, will actually get released. If set to TRUE all memory + * allocations will persist until the program exits. + */ +extern BOOL __never_free; + +/****************************************************************************/ + +/* + * Before memory is allocated, a quick check can be performed in order + * to avoid draining so much system memory that both the operating system + * and application software becomes unstable. This test checks for the + * largest available block of memory, which has to be larger than a + * threshold value for the memory allocation to proceed. That size + * can be configured here. It defaults to 0, which means that no test + * is performed. If this feature is enabled, a minimum threshold value + * of 250000 bytes is recommended. + */ +extern ULONG __free_memory_threshold; + +/****************************************************************************/ + +/* + * The following section lists variables and function pointers which are used + * by the startup code right after the program is launched. These variables are + * looked up before your program's main() function is invoked. Therefore, you + * would have to declare these variables in your program's data section and have + * them initialized to certain well-defined values to get the desired effect. + */ + +/* + * If set to TRUE, your program's process->pr_WindowPtr will be set to -1 + * when it starts. The process->pr_WindowPtr will be automatically restored + * to the initial value before it exits. + */ +extern BOOL __disable_dos_requesters; + +/* + * If set to TRUE, your program will disconnect itself from the shell it was + * launched from and keep running in the background. This service is unavailable + * for residentable programs. Note that you should not use this feature for + * programs which are supposed to be launched by the internet superserver. + * Also, note that when a program is run in the background, its input and + * output streams will be connected to NIL:. + */ +extern BOOL __detach; + +/* + * If this function pointer is not NULL, it must point to a function which + * figures out whether the program should detach itself from the shell it + * was launched from. The function return value replaces the value of the + * __detach variable. + * + * At the time this function is invoked, dos.library and utility.library + * have already been opened for you. + */ +extern BOOL (* __check_detach)(void); + +/* + * This variable can be set up to contain the minimum stack size the program + * should be launched with. If the startup code finds that there is not enough + * stack space available to start with, it will attempt to allocate more and + * then proceed to run your program. + * + * If this variable is set to 0 (the default) then no stack size test will + * be performed upon startup. + */ +extern unsigned int __stack_size; + +/* + * If this function pointer is not NULL, it must point to a function which + * figures out how much stack space is required to run the program. The + * function return value replaces the value of the __stack_size variable + * if it is not equal to zero. + * + * At the time this function is invoked, dos.library and utility.library + * have already been opened for you. + */ +extern unsigned int (* __get_default_stack_size)(void); + +/****************************************************************************/ + +/* + * If linked with -lunix, Unix path names are translated to Amiga path + * names (and the other way round). If you wish to disable this, set the + * following variable to FALSE. Only the path name translation is affected + * by setting this variable to FALSE. You will always get Unix-like behaviour + * from certain functions regardless of whether the path names are translated + * or not. + */ +extern BOOL __unix_path_semantics; + +/****************************************************************************/ + +/* A data structures used by the path translation routines below. */ +struct name_translation_info +{ + char substitute[MAXPATHLEN]; + char * original_name; + int is_root; +}; + +/****************************************************************************/ + +extern int __translate_relative_path_name(char const ** name_ptr,char *replace,size_t max_replace_len); +extern void __restore_path_name(char const ** name_ptr,struct name_translation_info * nti); +extern int __translate_amiga_to_unix_path_name(char const ** name_ptr,struct name_translation_info * nti); +extern int __translate_unix_to_amiga_path_name(char const ** name_ptr,struct name_translation_info * nti); +extern void __translate_io_error_to_errno(LONG io_error,int * errno_ptr); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _DOS_H */ diff --git a/library/include/errno.h b/library/include/errno.h new file mode 100644 index 0000000..034aaee --- /dev/null +++ b/library/include/errno.h @@ -0,0 +1,170 @@ +/* + * $Id: errno.h,v 1.1.1.1 2004-07-26 16:32:51 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ERRNO_H +#define _ERRNO_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +extern int errno; + +/****************************************************************************/ + +#define EPERM 1 /* Operation not permitted */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* Input/output error */ +#define ENXIO 6 /* Device not configured */ +#define E2BIG 7 /* Argument list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file descriptor */ +#define ECHILD 10 /* No child processes */ +#define EDEADLK 11 /* Resource deadlock avoided */ + +#define ENOMEM 12 /* Cannot allocate memory */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ + +#define ENOTBLK 15 /* Block device required */ +#define EBUSY 16 /* Device busy */ + +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* Operation not supported by device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* Too many open files in system */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Inappropriate ioctl for device */ + +#define ETXTBSY 26 /* Text file busy */ + +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read-only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ + +#define EDOM 33 /* Numerical argument out of domain */ +#define ERANGE 34 /* Result too large */ + +/* non-blocking and interrupt i/o */ +#define EAGAIN 35 /* Resource temporarily unavailable */ +#define EWOULDBLOCK EAGAIN /* Operation would block */ +#define EINPROGRESS 36 /* Operation now in progress */ +#define EALREADY 37 /* Operation already in progress */ + +/* ipc/network software -- argument errors */ +#define ENOTSOCK 38 /* Socket operation on non-socket */ +#define EDESTADDRREQ 39 /* Destination address required */ +#define EMSGSIZE 40 /* Message too long */ +#define EPROTOTYPE 41 /* Protocol wrong type for socket */ +#define ENOPROTOOPT 42 /* Protocol not available */ +#define EPROTONOSUPPORT 43 /* Protocol not supported */ +#define ESOCKTNOSUPPORT 44 /* Socket type not supported */ +#define EOPNOTSUPP 45 /* Operation not supported on socket */ +#define EPFNOSUPPORT 46 /* Protocol family not supported */ +#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */ +#define EADDRINUSE 48 /* Address already in use */ +#define EADDRNOTAVAIL 49 /* Can't assign requested address */ + +/* ipc/network software -- operational errors */ +#define ENETDOWN 50 /* Network is down */ +#define ENETUNREACH 51 /* Network is unreachable */ +#define ENETRESET 52 /* Network dropped connection on reset */ +#define ECONNABORTED 53 /* Software caused connection abort */ +#define ECONNRESET 54 /* Connection reset by peer */ +#define ENOBUFS 55 /* No buffer space available */ +#define EISCONN 56 /* Socket is already connected */ +#define ENOTCONN 57 /* Socket is not connected */ +#define ESHUTDOWN 58 /* Can't send after socket shutdown */ +#define ETOOMANYREFS 59 /* Too many references: can't splice */ +#define ETIMEDOUT 60 /* Connection timed out */ +#define ECONNREFUSED 61 /* Connection refused */ + +#define ELOOP 62 /* Too many levels of symbolic links */ +#define ENAMETOOLONG 63 /* File name too long */ + +#define EHOSTDOWN 64 /* Host is down */ +#define EHOSTUNREACH 65 /* No route to host */ +#define ENOTEMPTY 66 /* Directory not empty */ + +/* quotas & mush */ +#define EPROCLIM 67 /* Too many processes */ +#define EUSERS 68 /* Too many users */ +#define EDQUOT 69 /* Disc quota exceeded */ + +/* Network File System */ +#define ESTALE 70 /* Stale NFS file handle */ +#define EREMOTE 71 /* Too many levels of remote in path */ +#define EBADRPC 72 /* RPC struct is bad */ +#define ERPCMISMATCH 73 /* RPC version wrong */ +#define EPROGUNAVAIL 74 /* RPC prog. not avail */ +#define EPROGMISMATCH 75 /* Program version wrong */ +#define EPROCUNAVAIL 76 /* Bad procedure for program */ + +#define ENOLCK 77 /* No locks available */ +#define ENOSYS 78 /* Function not implemented */ + +#define EFTYPE 79 /* Inappropriate file type or format */ + +#define EAUTH 80 /* Authentication error. */ + +#define ENEEDAUTH 81 /* Need authenticator. */ + +#define EIDRM 82 /* Identifier removed. */ + +#define ENOMSG 83 /* No message of the desired type. */ + +#define EOVERFLOW 84 /* Value too large to be stored in data type. */ + +#define EILSEQ 85 /* Encoding error detected */ + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _ERRNO_H */ diff --git a/library/include/fcntl.h b/library/include/fcntl.h new file mode 100644 index 0000000..40e8067 --- /dev/null +++ b/library/include/fcntl.h @@ -0,0 +1,122 @@ +/* + * $Id: fcntl.h,v 1.1.1.1 2004-07-26 16:32:51 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _FCNTL_H +#define _FCNTL_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _SYS_TYPES_H +#include +#endif /* _SYS_TYPES_H */ + +#ifndef _STDDEF_H +#include +#endif /* _STDDEF_H */ + +/****************************************************************************/ + +#define O_RDONLY 0 +#define O_WRONLY 1 +#define O_RDWR 2 + +#define O_APPEND (1<<2) +#define O_CREAT (1<<3) +#define O_EXCL (1<<4) +#define O_TRUNC (1<<5) +#define O_NONBLOCK (1<<6) +#define O_SYNC (0) +#define O_NOCTTY (0) + +/****************************************************************************/ + +#define F_DUPFD 0 +#define F_GETFD 1 +#define F_SETFD 2 +#define F_GETFL 3 +#define F_SETFL 4 +#define F_GETOWN 5 +#define F_SETOWN 6 + +/****************************************************************************/ + +/* + * Advisory file segment locking data type - + * information passed to system by user + */ +struct flock +{ + short l_type; /* lock type: read/write, etc. */ + short l_whence; /* type of l_start */ + off_t l_start; /* starting offset */ + off_t l_len; /* len = 0 means until end of file */ + pid_t l_pid; /* lock owner */ +}; + +#define F_GETLK 100 /* get record locking information */ +#define F_SETLK 101 /* set record locking information */ +#define F_SETLKW 102 /* F_SETLK; wait if blocked */ + +#define F_RDLCK 1 /* shared or read lock */ +#define F_UNLCK 2 /* unlock */ +#define F_WRLCK 3 /* exclusive or write lock */ + +/****************************************************************************/ + +extern int open(const char *path_name, int open_flag, ... /* mode_t mode */ ); +extern int creat(const char * path_name, mode_t mode); +extern int close(int file_descriptor); +extern off_t lseek(int file_descriptor, off_t offset, int mode); +extern ssize_t read(int file_descriptor, void * buffer, size_t num_bytes); +extern ssize_t write(int file_descriptor, const void * buffer, size_t num_bytes); +extern int fcntl(int file_descriptor, int cmd, ... /* int arg */ ); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _FCNTL_H */ diff --git a/library/include/float.h b/library/include/float.h new file mode 100644 index 0000000..a550d97 --- /dev/null +++ b/library/include/float.h @@ -0,0 +1,77 @@ +/* + * $Id: float.h,v 1.1.1.1 2004-07-26 16:32:51 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _FLOAT_H +#define _FLOAT_H + +/****************************************************************************/ + +#define FLT_EPSILON 1.19209290E-07F +#define FLT_DIG 6 +#define FLT_MANT_DIG 24 +#define FLT_MAX 3.40282347E+38F +#define FLT_MAX_EXP 128 +#define FLT_MAX_10_EXP 38 +#define FLT_MIN 1.17549435E-38F +#define FLT_MIN_EXP (-125) +#define FLT_MIN_10_EXP (-37) +#define FLT_RADIX 2 +#define FLT_ROUNDS 1 + +/****************************************************************************/ + +#define DBL_EPSILON 2.2204460492503131E-16 +#define DBL_DIG 15 +#define DBL_MANT_DIG 53 +#define DBL_MAX 1.7976931348623157E+308 +#define DBL_MAX_EXP 1024 +#define DBL_MAX_10_EXP 308 +#define DBL_MIN 2.2250738585072014E-308 +#define DBL_MIN_EXP (-1021) +#define DBL_MIN_10_EXP (-307) + +/****************************************************************************/ + +#define LDBL_EPSILON 2.2204460492503131E-16L +#define LDBL_DIG 15 +#define LDBL_MANT_DIG 53 +#define LDBL_MAX 1.7976931348623157E+308L +#define LDBL_MAX_EXP 1024 +#define LDBL_MAX_10_EXP 308 +#define LDBL_MIN 2.2250738585072014E-308L +#define LDBL_MIN_EXP (-1021) +#define LDBL_MIN_10_EXP (-307) + +/****************************************************************************/ + +#endif /* _FLOAT_H */ diff --git a/library/include/grp.h b/library/include/grp.h new file mode 100644 index 0000000..87abbd0 --- /dev/null +++ b/library/include/grp.h @@ -0,0 +1,71 @@ +/* + * $Id: grp.h,v 1.1.1.1 2004-07-26 16:32:52 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _GRP_H +#define _GRP_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _SYS_TYPES_H +#include +#endif /* _SYS_TYPES_H */ + +/****************************************************************************/ + +struct group +{ + char * gr_name; /* group name */ + char * gr_passwd; /* group password */ + gid_t gr_gid; /* group id */ + char ** gr_mem; /* group members */ +}; + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _GRP_H */ diff --git a/library/include/iso646.h b/library/include/iso646.h new file mode 100644 index 0000000..ab98367 --- /dev/null +++ b/library/include/iso646.h @@ -0,0 +1,53 @@ +/* + * $Id: iso646.h,v 1.1.1.1 2004-07-26 16:32:52 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ISO646_H +#define _ISO646_H + +/****************************************************************************/ + +#define and && +#define and_eq &= +#define bitand & +#define bitor | +#define compl ~ +#define not ! +#define not_eq != +#define or || +#define or_eq |= +#define xor ^ +#define xor_eq ^= + +/****************************************************************************/ + +#endif /* _ISO646_H */ diff --git a/library/include/libgen.h b/library/include/libgen.h new file mode 100644 index 0000000..008c35e --- /dev/null +++ b/library/include/libgen.h @@ -0,0 +1,60 @@ +/* + * $Id: libgen.h,v 1.1.1.1 2004-07-26 16:32:52 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LIBGEN_H +#define _LIBGEN_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +char * basename(char *path); +char * dirname(char *path); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _LIBGEN_H */ diff --git a/library/include/limits.h b/library/include/limits.h new file mode 100644 index 0000000..3b46a26 --- /dev/null +++ b/library/include/limits.h @@ -0,0 +1,65 @@ +/* + * $Id: limits.h,v 1.1.1.1 2004-07-26 16:32:52 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LIMITS_H +#define _LIMITS_H + +/****************************************************************************/ + +#define CHAR_BIT 8 +#define CHAR_MAX 127 +#define CHAR_MIN -128 +#define INT_MAX 2147483647L +#define INT_MIN (-2147483647L - 1) +#define LONG_MAX 2147483647L +#define LONG_MIN (-2147483647L - 1) +#define SCHAR_MAX 127 +#define SCHAR_MIN -128 +#define SHRT_MAX 32767 +#define SHRT_MIN -32768 +#define UCHAR_MAX 255 +#define UINT_MAX 4294967295UL +#define ULONG_MAX 4294967295UL +#define USHRT_MAX 65535 + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#define PATH_MAX 1024 + +/****************************************************************************/ + +#endif /* _LIMITS_H */ diff --git a/library/include/locale.h b/library/include/locale.h new file mode 100644 index 0000000..97b4714 --- /dev/null +++ b/library/include/locale.h @@ -0,0 +1,115 @@ +/* + * $Id: locale.h,v 1.1.1.1 2004-07-26 16:32:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOCALE_H +#define _LOCALE_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#define LC_ALL 0 /* all behaviour */ +#define LC_COLLATE 1 /* behaviour of strcoll() and strxfrm() */ +#define LC_CTYPE 2 /* character handling */ +#define LC_MONETARY 3 /* monetary information returned by localeconv() */ +#define LC_NUMERIC 4 /* decimal point and non-monetary information + returned by localeconv() */ +#define LC_TIME 5 /* behaviour of strftime() */ + +/****************************************************************************/ + +struct lconv +{ + char * decimal_point; /* Decimal point character (non-monetary). */ + char * thousands_sep; /* Non-monetary digit group separator + character(s). */ + char * grouping; /* Non-monetary digit groupings. */ + char * int_curr_symbol; /* International currency symbol, followed + by the character that separates it from + the monetary quantity. */ + char * currency_symbol; /* The local currency symbol for the + current locale. */ + char * mon_decimal_point; /* Decimal point character for monetary + quantities. */ + char * mon_thousands_sep; /* Monetary digit group separator + character(s). */ + char * mon_grouping; /* Monetary digit groupings. */ + char * positive_sign; /* Sign character(s) for non-negative + monetary quantities. */ + char * negative_sign; /* Sign character(s) for negative + monetary quantities. */ + char int_frac_digits; /* Digits shown right of the decimal + point in international monetary + format. */ + char frac_digits; /* Digits shown to the right of the decimal + point in other monetary formats. */ + char p_cs_precedes; /* If currency symbol precedes non-negative + monetary values this will be 1, otherwise + it will be 0. */ + char p_sep_by_space; /* If currency symbol is separated from + non-negative monetary values by a blank + space this will be 1, otherwise it will + be 0. */ + char n_cs_precedes; /* If currency symbol precedes negative + monetary values this will be 1, otherwise + it will be 0. */ + char n_sep_by_space; /* If currency symbol is separated from + negative monetary values by a blank + space this will be 1, otherwise it will + be 0. */ + char p_sign_posn; /* Where to place the positive sign and the + currency symbol for a non-negative monetary + quantity. */ + char n_sign_posn; /* Where to place the negative sign and the + currency symbol for a negative monetary + quantity. */ +}; + +/****************************************************************************/ + +extern char *setlocale(int category, const char *locale); +extern struct lconv *localeconv(void); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _LOCALE_H */ diff --git a/library/include/math.h b/library/include/math.h new file mode 100644 index 0000000..8548980 --- /dev/null +++ b/library/include/math.h @@ -0,0 +1,90 @@ +/* + * $Id: math.h,v 1.1.1.1 2004-07-26 16:32:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_H +#define _MATH_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _STDLIB_H +#include +#endif /* _STDLIB_H */ + +/****************************************************************************/ + +extern double __huge_val; + +/****************************************************************************/ + +#define HUGE_VAL ((const double)__huge_val) + +/****************************************************************************/ + +extern double acos(double x); +extern double asin(double x); +extern double atan(double x); +extern double atan2(double y,double x); +extern double ceil(double x); +extern double cos(double x); +extern double cosh(double x); +extern double exp(double x); +extern double fabs(double x); +extern double floor(double x); +extern double fmod(double x,double y); +extern double frexp(double x,int *nptr); +extern double ldexp(double x,int n); +extern double log(double x); +extern double log10(double x); +extern double modf(double x,double *nptr); +extern double pow(double x,double y); +extern double sin(double x); +extern double sinh(double x); +extern double sqrt(double x); +extern double tan(double x); +extern double tanh(double x); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _MATH_H */ diff --git a/library/include/pwd.h b/library/include/pwd.h new file mode 100644 index 0000000..bf3d28e --- /dev/null +++ b/library/include/pwd.h @@ -0,0 +1,74 @@ +/* + * $Id: pwd.h,v 1.1.1.1 2004-07-26 16:32:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _PWD_H +#define _PWD_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _SYS_TYPES_H +#include +#endif /* _SYS_TYPES_H */ + +/****************************************************************************/ + +struct passwd +{ + char * pw_name; /* Username */ + char * pw_passwd; /* Encrypted password */ + uid_t pw_uid; /* User ID */ + gid_t pw_gid; /* Group ID */ + char * pw_gecos; /* Real name etc */ + char * pw_dir; /* Home directory */ + char * pw_shell; /* Shell */ +}; + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _PWD_H */ diff --git a/library/include/setjmp.h b/library/include/setjmp.h new file mode 100644 index 0000000..875d6c4 --- /dev/null +++ b/library/include/setjmp.h @@ -0,0 +1,85 @@ +/* + * $Id: setjmp.h,v 1.1.1.1 2004-07-26 16:32:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SETJMP_H +#define _SETJMP_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef __PPC__ + +struct __jmp_buf +{ + void * jb_ReturnAddress; + long jb_D[7]; + void * jb_A[8]; + long jb_F[8 * 3]; +}; + +#else + +struct __jmp_buf +{ + void * jb_ReturnAddress; + unsigned long jb_CondCode; + void * jb_StackPointer; + unsigned long jb_GPR[19]; + double jb_FPR[18]; +}; + +#endif /* __PPC__ */ + +/****************************************************************************/ + +typedef struct __jmp_buf jmp_buf[1]; + +/****************************************************************************/ + +extern int setjmp(jmp_buf env); +extern void longjmp(jmp_buf env,int status); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _SETJMP_H */ diff --git a/library/include/signal.h b/library/include/signal.h new file mode 100644 index 0000000..c4ae591 --- /dev/null +++ b/library/include/signal.h @@ -0,0 +1,105 @@ +/* + * $Id: signal.h,v 1.1.1.1 2004-07-26 16:32:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SIGNAL_H +#define _SIGNAL_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#define SIG_IGN ((void (*)(int))0) +#define SIG_DFL ((void (*)(int))1) +#define SIG_ERR ((void (*)(int))-1) + +/****************************************************************************/ + +#define SIGABRT 1 +#define SIGFPE 2 +#define SIGILL 3 +#define SIGINT 4 +#define SIGSEGV 5 +#define SIGTERM 6 + +/****************************************************************************/ + +extern void (*signal(int sig, void (*)(int)))(int); +extern int raise(int sig); + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifndef _SYS_TYPES_H +#include +#endif /* _SYS_TYPES_H */ + +/****************************************************************************/ + +typedef int sig_atomic_t; + +/****************************************************************************/ + +typedef int sigset_t; + +/****************************************************************************/ + +#define SIG_BLOCK 0 +#define SIG_UNBLOCK 1 +#define SIG_SETMASK 2 + +/****************************************************************************/ + +extern int sigmask(int signum); +extern int sigblock(int signal_mask); +extern int sigsetmask(int signal_mask); +extern int sigprocmask(int how, const sigset_t *set, sigset_t *oset); +extern int sigemptyset(sigset_t * set); +extern int sigaddset(sigset_t * set,int sig); +extern int kill(pid_t pid, int signal_number); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _SIGNAL_H */ diff --git a/library/include/stdarg.h b/library/include/stdarg.h new file mode 100644 index 0000000..a51ef90 --- /dev/null +++ b/library/include/stdarg.h @@ -0,0 +1,76 @@ +/* + * $Id: stdarg.h,v 1.1.1.1 2004-07-26 16:32:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDARG_H +#define _STDARG_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef __amigaos4__ + +/****************************************************************************/ + +typedef char * va_list; + +/****************************************************************************/ + +#define va_start(ap, last) ((void)(ap = (va_list)&(last) + sizeof(last))) +#define va_arg(ap, type) ((type *)(ap += sizeof(type)))[-1] +#define va_end(ap) ((void)0) + +/****************************************************************************/ + +#else + #if defined(__GNUC__) + #undef _STDARG_H + #include_next "stdarg.h" + #else + #error "Unknown compiler" + #endif /* __GNUC__ */ +#endif /* __amigaos4__ */ + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _STDARG_H */ diff --git a/library/include/stddef.h b/library/include/stddef.h new file mode 100644 index 0000000..68dc42f --- /dev/null +++ b/library/include/stddef.h @@ -0,0 +1,71 @@ +/* + * $Id: stddef.h,v 1.1.1.1 2004-07-26 16:32:54 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDDEF_H +#define _STDDEF_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef NULL +#ifndef __cplusplus +#define NULL ((void *)0L) +#else +#define NULL 0L +#endif /* __cplusplus */ +#endif /* NULL */ + +/****************************************************************************/ + +typedef long int ptrdiff_t; +typedef unsigned int size_t; +typedef unsigned int wchar_t; + +/****************************************************************************/ + +#define offsetof(type, member) ((size_t)&((type *)0)->member) + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _STDDEF_H */ diff --git a/library/include/stdio.h b/library/include/stdio.h new file mode 100644 index 0000000..4d81082 --- /dev/null +++ b/library/include/stdio.h @@ -0,0 +1,347 @@ +/* + * $Id: stdio.h,v 1.1.1.1 2004-07-26 16:32:54 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_H +#define _STDIO_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _STDDEF_H +#include +#endif /* _STDDEF_H */ + +#ifndef _STDARG_H +#include +#endif /* _STDARG_H */ + +/****************************************************************************/ + +/* 'End of file' indicator returned by, for example, fgetc() */ +#define EOF (-1) + +/****************************************************************************/ + +/* + * Maximum number of files that can be open at a time. This number does not + * correspond to a real limitation for this 'C' runtime library and is + * included solely for ISO 'C' (1994) compliance. + */ +#define FOPEN_MAX 8 + +/****************************************************************************/ + +/* Maximum size of a file/path name. */ +#define FILENAME_MAX 256 + +/****************************************************************************/ + +/* Default size for all standard I/O file buffers. */ +#define BUFSIZ 8192 + +/****************************************************************************/ + +/* File buffering modes for use with setvbuf() */ + +#define _IOFBF 0 /* Full buffering (flush when buffer is full) */ + +#define _IOLBF 1 /* Line buffering (flush when buffer is full or when + a line feed character is written) */ + +#define _IONBF 2 /* Perform no buffering at all */ + +/****************************************************************************/ + +/* Positioning modes for use with fseek() */ + +#define SEEK_SET 0 /* New position is absolute */ +#define SEEK_CUR 1 /* New position is relative to current file position */ +#define SEEK_END 2 /* New position is relative to end of file */ + +/****************************************************************************/ + +/* Used by fgetpos() and fsetpos() */ + +#if defined(__GNUC__) +typedef long long fpos_t; +#else +typedef long fpos_t; +#endif /* __GNUC__ */ + +/****************************************************************************/ + +/* + * This is part of the internal 'FILE' structure; this is guaranteed not to + * change in future library releases. However, the private portion of this + * data structure may change. + */ +typedef struct +{ + unsigned long flags; /* See below for some of the public + flag bits defined; this is by no + means a complete list, though! */ + unsigned char * buffer; /* Points to the first byte of the + buffer; this could be NULL! */ + long size; /* How many bytes will fit into the + buffer; this could be 0! */ + long position; /* Current buffer position, which is + usually a number between 0 and + size-1 */ + long num_read_bytes; /* How many bytes can be read from + the buffer; this can be 0! */ + long num_write_bytes; /* How many bytes have been copied + to the buffer which have not been + written back yet; this can be 0! */ + + /* Private fields follow... */ +} FILE; + +/****************************************************************************/ + +/* Field and flag definitions for the getc/putc macros below. */ +#define __FILE_BUFFER_MASK 3 /* Masks off the buffering mode */ +#define __FILE_EOF (1<<2) /* EOF reached */ +#define __FILE_READABLE (1<<3) /* File is readable */ +#define __FILE_WRITABLE (1<<4) /* File is writable */ +#define __FILE_IN_USE (1<<5) /* File is in use */ +#define __FILE_ERROR (1<<6) /* Error detected */ + +/****************************************************************************/ + +/* + * Maximum file name buffer size for use with tmpfile() and tmpnam(); + * note that the maximum file name length is shorter by one character + */ +#define L_tmpnam 10 + +/* Maximum number of unique file names tmpnam() can generate */ +#define TMP_MAX 0x3ffff + +/****************************************************************************/ + +/* Anchor for the buffered standard I/O streams */ +extern struct iob ** __iob; + +/****************************************************************************/ + +/* The three standard I/O streams */ +#define stdin ((FILE *)__iob[0]) +#define stdout ((FILE *)__iob[1]) +#define stderr ((FILE *)__iob[2]) + +/****************************************************************************/ + +extern void perror(const char * s); + +/****************************************************************************/ + +extern FILE *fopen(const char *filename, const char *mode); +extern int fclose(FILE *stream); +extern int fflush(FILE *stream); +extern FILE *freopen(const char *filename, const char *mode, FILE *stream); +extern int setvbuf(FILE *stream,char *buf,int bufmode,size_t size); +extern void setbuf(FILE *stream, char *buf); + +/****************************************************************************/ + +extern int fseek(FILE *stream, long int offset, int wherefrom); +extern long int ftell(FILE *stream); +extern void rewind(FILE *stream); +extern int fgetpos(FILE *stream, fpos_t *pos); +extern int fsetpos(FILE *stream, fpos_t *pos); + +/****************************************************************************/ + +extern int fgetc(FILE *stream); +extern int getc(FILE *stream); +extern int getchar(void); +extern int ungetc(int c,FILE *stream); + +/****************************************************************************/ + +extern int fputc(int c,FILE *stream); +extern int putc(int c,FILE *stream); +extern int putchar(int c); + +/****************************************************************************/ + +extern char *fgets(char *s,int n,FILE *stream); +extern char *gets(char *s); + +/****************************************************************************/ + +extern int fscanf(FILE *stream, const char *format, ...); +extern int scanf(const char *format, ...); +extern int sscanf(const char *s,const char *format, ...); + +/****************************************************************************/ + +extern int fputs(const char *s, FILE *stream); +extern int puts(const char *s); + +/****************************************************************************/ + +extern int fprintf(FILE *stream,const char *format,...); +extern int printf(const char *format, ...); +extern int sprintf(char *s, const char *format, ...); + +/****************************************************************************/ + +extern int vfprintf(FILE *stream,const char *format,va_list arg); +extern int vprintf(const char *format,va_list arg); +extern int vsprintf(char *s, const char *format,va_list arg); + +/****************************************************************************/ + +extern size_t fread(void *ptr,size_t element_size,size_t count,FILE *stream); +extern size_t fwrite(const void *ptr,size_t element_size,size_t count,FILE *stream); + +/****************************************************************************/ + +extern int feof(FILE *stream); +extern int ferror(FILE *stream); +extern void clearerr(FILE *stream); + +/****************************************************************************/ + +extern int rename(const char *oldname,const char *newname); +extern int remove(const char *filename); + +/****************************************************************************/ + +extern FILE *tmpfile(void); +extern char *tmpnam(char *buf); + +/****************************************************************************/ + +/* + * A special buffer flush routine which returns the last character written + * in case of success and EOF in case of failure. This is used by the + * putc() macro defined below. + */ +extern int __flush(FILE *stream); + +/****************************************************************************/ + +/* + * fgetc() implemented as a "simple" macro; note that fgetc() does much more than + * can be conveniently expressed as a macro! + */ +#define getc(f) \ + (((((FILE *)(f))->flags & (__FILE_IN_USE|__FILE_READABLE|__FILE_EOF)) == (__FILE_IN_USE|__FILE_READABLE) && \ + (((FILE *)(f))->flags & __FILE_BUFFER_MASK) != _IONBF && \ + ((FILE *)(f))->position < ((FILE *)(f))->num_read_bytes) ? \ + ((FILE *)(f))->buffer[((FILE *)(f))->position++] : \ + fgetc(f)) + +/****************************************************************************/ + +/* + * fputc() implemented as a "simple" macro; note that fputc() does much more than + * can be conveniently expressed as a macro! + */ +#define putc(c,f) \ + (((((FILE *)(f))->flags & (__FILE_IN_USE|__FILE_WRITABLE)) == (__FILE_IN_USE|__FILE_WRITABLE) && \ + (((FILE *)(f))->flags & __FILE_BUFFER_MASK) != _IONBF && \ + (((FILE *)(f))->num_write_bytes < ((FILE *)(f))->size)) ? \ + (((FILE *)(f))->buffer[((FILE *)(f))->num_write_bytes++] = (c), \ + (((((FILE *)(f))->flags & __FILE_BUFFER_MASK) == _IOLBF && \ + ((FILE *)(f))->buffer[((FILE *)(f))->num_write_bytes-1] == '\n') ? \ + __flush(f) : \ + (((FILE *)(f))->buffer[((FILE *)(f))->num_write_bytes-1]))) : \ + fputc((c),(f))) + +/****************************************************************************/ + +/* + * If requested, reimplement some of the file I/O routines as macros. + */ + +#ifdef __C_MACROS__ + +/****************************************************************************/ + +#define getchar() getc(stdin) +#define putchar(c) putc((c),stdout) +#define clearerr(file) ((void)((file)->flags &= ~(__FILE_EOF|__FILE_ERROR))) +#define feof(file) (((file)->flags & __FILE_EOF) != 0) +#define ferror(file) (((file)->flags & __FILE_ERROR) != 0) + +/****************************************************************************/ + +#endif /* __C_MACROS__ */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#define MAXPATHLEN (4 * FILENAME_MAX) + +/****************************************************************************/ + +extern FILE * fdopen(int file_descriptor, const char * type); +extern int fileno(FILE * file); +extern int asprintf(char **ret, const char *format, ...); +extern int snprintf(char *s,size_t size,const char *format,...); +extern int vsnprintf(char *s,size_t size,const char *format,va_list arg); +extern int pclose(FILE *stream); +extern FILE * popen(const char *command, const char *type); + +/****************************************************************************/ + +extern int vasprintf(char **ret,const char *format,va_list arg); + +/* This is the version for use with memory debugging; do not call + it directly! */ +extern int __vasprintf(const char *file,int line,char **ret,const char *format,va_list arg); + +#ifdef __MEM_DEBUG +#define vasprintf(ret,format,arg) __vasprintf(__FILE__,__LINE__,(ret),(format),(arg)) +#endif /* __MEM_DEBUG */ + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _STDIO_H */ diff --git a/library/include/stdlib.h b/library/include/stdlib.h new file mode 100644 index 0000000..d5dc4f0 --- /dev/null +++ b/library/include/stdlib.h @@ -0,0 +1,185 @@ +/* + * $Id: stdlib.h,v 1.1.1.1 2004-07-26 16:32:55 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_H +#define _STDLIB_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _STDDEF_H +#include +#endif /* _STDDEF_H */ + +/****************************************************************************/ + +/* Maximum number of bytes in a multibyte character */ +#define MB_CUR_MAX 4 + +/****************************************************************************/ + +/* The maximum value that can be returned by the rand() function */ +#define RAND_MAX 2147483647 + +/****************************************************************************/ + +/* Return values to be passed to exit() */ +#define EXIT_FAILURE 20 +#define EXIT_SUCCESS 0 + +/****************************************************************************/ + +/* Data structures used by the div() and ldiv() functions */ +typedef struct { int quot; int rem; } div_t; +typedef struct { long quot; long rem; } ldiv_t; + +/****************************************************************************/ + +extern int mblen(const char *s, size_t n); +extern int mbtowc(wchar_t *pwc, const char *s, size_t n); +extern int wctomb(char *s, wchar_t wchar); +extern size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n); +extern size_t wcstombs(char *s, const wchar_t *pwcs, size_t n); + +/****************************************************************************/ + +extern void *malloc(size_t size); +extern void *calloc(size_t num_elements,size_t element_size); +extern void free(void *ptr); +extern void *realloc(void *ptr,size_t size); + +/* This are the versions for use with memory debugging; do not call + them directly! */ +extern void *__malloc(size_t size,const char *file,int line); +extern void *__calloc(size_t num_elements,size_t element_size,const char *file,int line); +extern void __free(void *ptr,const char *file,int line); +extern void *__realloc(void *ptr,size_t size,const char *file,int line); + +#ifdef __MEM_DEBUG +#define malloc(size) __malloc((size),__FILE__,__LINE__) +#define calloc(num_elements,element_size) __calloc((num_elements),(element_size),__FILE__,__LINE__) +#define free(ptr) __free((ptr),__FILE__,__LINE__) +#define realloc(ptr,size) __realloc((ptr),(size),__FILE__,__LINE__) +#endif /* __MEM_DEBUG */ + +/****************************************************************************/ + +extern int abs(int x); +extern long labs(long x); +extern div_t div(int n,int d); +extern ldiv_t ldiv(long n,long d); + +/****************************************************************************/ + +extern int rand(void); +extern void srand(unsigned seed); + +/****************************************************************************/ + +extern int system(const char *command); + +/****************************************************************************/ + +extern void exit(int status); +extern void abort(void); + +/****************************************************************************/ + +extern int atexit(void (*)(void)); + +/****************************************************************************/ + +extern char * getenv(const char *name); + +/****************************************************************************/ + +extern void * bsearch(const void *key, const void *base, size_t count, size_t size, + int (*compare)(const void * key,const void * value)); +extern void qsort(void *base,size_t count,size_t size, + int (*compare)(const void * element1,const void * element2)); + +/****************************************************************************/ + +extern double strtod(const char *str, char ** ptr); +extern long strtol(const char *str, char **ptr, int base); +extern unsigned long strtoul(const char *str, char **ptr, int base); + +/****************************************************************************/ + +extern double atof(const char *str); +extern int atoi(const char *str); +extern long atol(const char *str); + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#if defined(__GNUC__) + #if defined(alloca) + #undef alloca + #define alloca(size) __builtin_alloca(size) + #endif /* alloca */ +#else + extern void * alloca(size_t size); + extern void * __alloca(size_t size,const char *file,int line); + + #ifdef __MEM_DEBUG + #define alloca(size) __alloca((size),__FILE__,__LINE__) + #endif /* __MEM_DEBUG */ +#endif /* __GNUC__ */ + +/****************************************************************************/ + +extern int setenv(const char *name, const char *value, int overwrite); +extern int putenv(const char *string); +extern void unsetenv(const char *name); +extern char * mktemp(char * name_template); +extern int mkstemp(char *name_template); +extern char * mkdtemp(char *name_template); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _STDLIB_H */ diff --git a/library/include/string.h b/library/include/string.h new file mode 100644 index 0000000..036931a --- /dev/null +++ b/library/include/string.h @@ -0,0 +1,121 @@ +/* + * $Id: string.h,v 1.1.1.1 2004-07-26 16:32:55 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STRING_H +#define _STRING_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _STDDEF_H +#include +#endif /* _STDDEF_H */ + +/****************************************************************************/ + +extern char *strerror(int error_number); +extern char *strcat(char *dest, const char *src); +extern char *strncat(char *dest, const char *src, size_t n); +extern int strcmp(const char *s1, const char * s2); +extern int strncmp(const char *s1, const char *s2, size_t n); +extern char *strcpy(char *dest, const char *src); +extern char *strncpy(char *dest, const char *src, size_t n); +extern size_t strlen(const char *s); +extern char *strchr(const char *s, int c); +extern char *strrchr(const char *s, int c); +extern size_t strspn(const char *s, const char *set); +extern size_t strcspn(const char *s, const char *set); +extern char *strpbrk(const char *s, const char *set); +extern char *strtok(char *str, const char *set); +extern char *strstr(const char *src, const char *sub); + +/****************************************************************************/ + +extern int strcoll(const char *s1, const char *s2); +extern size_t strxfrm(char *dest, const char *src, size_t len); + +/****************************************************************************/ + +extern void *memchr(const void * ptr, int val, size_t len); +extern int memcmp(const void *ptr1, const void *ptr2, size_t len); +extern void *memcpy(void *dest, const void *src, size_t len); +extern void *memmove(void *dest, const void * src, size_t len); +extern void *memset(void *ptr, int val, size_t len); + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifndef _STRINGS_H +#include +#endif /* _STRINGS_H */ + +/****************************************************************************/ + +extern char * index(const char *s, int c); +extern char * rindex(const char *s, int c); + +/****************************************************************************/ + +extern char * strdup(const char *s); + +/* This is the version for use with memory debugging; do not call + it directly! */ +extern char * __strdup(const char *s,const char *file,int line); + +#ifdef __MEM_DEBUG +#define strdup(s) __strdup((s),__FILE__,__LINE__) +#endif /* __MEM_DEBUG */ + +/****************************************************************************/ + +extern void bcopy(const void *from,void *to,size_t len); +extern void bzero(void *m,size_t len); +extern int bcmp(const void *a,const void *b,size_t len); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _STRING_H */ diff --git a/library/include/strings.h b/library/include/strings.h new file mode 100644 index 0000000..aa96498 --- /dev/null +++ b/library/include/strings.h @@ -0,0 +1,77 @@ +/* + * $Id: strings.h,v 1.1.1.1 2004-07-26 16:32:55 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STRINGS_H +#define _STRINGS_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _STDDEF_H +#include +#endif /* _STDDEF_H */ + +/****************************************************************************/ + +/* These two come from 4.4BSD. */ +extern int strcasecmp(const char *s1, const char *s2); +extern int strncasecmp(const char *s1, const char *s2, size_t len); + +/****************************************************************************/ + +/* + * These two provide functions which are available with the Lattice and + * SAS/C compiler runtime libraries. Which probably makes them more exotic + * than XENIX. + */ +#define stricmp(s1, s2) strcasecmp((s1), (s2)) +#define strnicmp(s1, s2, len) strncasecmp((s1), (s2), (len)) + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _STRINGS_H */ diff --git a/library/include/sys/amigaos-va.h b/library/include/sys/amigaos-va.h new file mode 100644 index 0000000..1627780 --- /dev/null +++ b/library/include/sys/amigaos-va.h @@ -0,0 +1,81 @@ +/* + * $Id: amigaos-va.h,v 1.1.1.1 2004-07-26 16:32:57 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_AMIGAOS_VA_H +#define _SYS_AMIGAOS_VA_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _STDARG_H +#include +#endif /* _STDARG_H */ + +/****************************************************************************/ + +/* Define the AmigaOS specific varargs macros, + if didn't already define them. */ + +#ifndef va_startlinear + #define va_startlinear(AP,ARG) \ + va_start(AP,ARG) +#endif + +#ifndef va_getlinearva + #if defined(__GNUC__) && defined(__PPC__) + #define va_getlinearva(AP,TYPE) \ + ((TYPE)__builtin_getlinearva(AP)) + #else + #define va_getlinearva(AP,TYPE) \ + ((TYPE)(void *)(AP)) + #endif +#endif + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _SYS_AMIGAOS_VA_H */ diff --git a/library/include/sys/mount.h b/library/include/sys/mount.h new file mode 100644 index 0000000..a0b8fc8 --- /dev/null +++ b/library/include/sys/mount.h @@ -0,0 +1,121 @@ +/* + * $Id: mount.h,v 1.1.1.1 2004-07-26 16:32:58 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_MOUNT_H +#define _SYS_MOUNT_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _SYS_TYPES_H +#include +#endif /* _SYS_TYPES_H */ + +/****************************************************************************/ + +typedef struct { long val[2]; } fsid_t; /* file system id type */ + +/****************************************************************************/ + +#define MFSNAMELEN 16 /* length of fs type name, including nul */ +#define MNAMELEN 90 /* length of buffer for returned name */ + +/****************************************************************************/ + +struct statfs +{ + long f_bsize; /* fundamental file system block size */ + long f_iosize; /* optimal transfer block size */ + long f_blocks; /* total data blocks in file system */ + long f_bfree; /* free blocks in fs */ + long f_bavail; /* free blocks avail to non-superuser */ + long f_files; /* total file nodes in file system */ + long f_ffree; /* free file nodes in fs */ + fsid_t f_fsid; /* file system id */ + uid_t f_owner; /* user that mounted the file system */ + long f_flags; /* copy of mount flags */ + long f_syncwrites; /* count of sync writes since mount */ + long f_asyncwrites; /* count of async writes since mount */ + char f_fstypename[MFSNAMELEN]; /* fs type name */ + char f_mntonname[MNAMELEN]; /* directory on which mounted */ + char f_mntfromname[MNAMELEN]; /* mounted file system */ +}; + +/****************************************************************************/ + +#define MNT_RDONLY (1<<0) /* The filesystem is mounted read-only */ +#define MNT_NOEXEC 0 +#define MNT_NOSUID 0 +#define MNT_NODEV 0 +#define MNT_SYNCHRONOUS 0 +#define MNT_ASYNC 0 +#define MNT_UNION 0 +#define MNT_NOCOREDUMP 0 +#define MNT_NOATIME (1<<1) /* Never update access times */ +#define MNT_SYMPERM (1<<2) /* Recognize symbolic link permission */ +#define MNT_NODEVMTIME 0 +#define MNT_SOFTDEP 0 +#define MNT_LOCAL (1<<3) /* The filesystem resides locally */ +#define MNT_QUOTA 0 +#define MNT_ROOTFS 0 +#define MNT_EXRDONLY 0 +#define MNT_EXPORTED 0 +#define MNT_DEFEXPORTED 0 +#define MNT_EXPORTANON 0 +#define MNT_EXKERB 0 +#define MNT_EXNORESPORT 0 +#define MNT_EXPUBLIC 0 + +/****************************************************************************/ + +int statfs(const char *path, struct statfs *buf); +int fstatfs(int fd, struct statfs *buf); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _SYS_MOUNT_H */ diff --git a/library/include/sys/stat.h b/library/include/sys/stat.h new file mode 100644 index 0000000..fe2d7c1 --- /dev/null +++ b/library/include/sys/stat.h @@ -0,0 +1,135 @@ +/* + * $Id: stat.h,v 1.1.1.1 2004-07-26 16:32:58 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_STAT_H +#define _SYS_STAT_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _SYS_TYPES_H +#include +#endif /* _SYS_TYPES_H */ + +#ifndef _STDDEF_H +#include +#endif /* _STDDEF_H */ + +#ifndef _TIME_H +#include +#endif /* _TIME_H */ + +/****************************************************************************/ + +#define S_ISUID 0004000 /* set user id on execution */ +#define S_ISGID 0002000 /* set group id on execution */ +#define S_ISVTX 0001000 /* save swapped text even after use */ + +#define S_IRWXU 0000700 /* RWX mask for owner */ +#define S_IRUSR 0000400 /* R for owner */ +#define S_IWUSR 0000200 /* W for owner */ +#define S_IXUSR 0000100 /* X for owner */ + +#define S_IRWXG 0000070 /* RWX mask for group */ +#define S_IRGRP 0000040 /* R for group */ +#define S_IWGRP 0000020 /* W for group */ +#define S_IXGRP 0000010 /* X for group */ + +#define S_IRWXO 0000007 /* RWX mask for other */ +#define S_IROTH 0000004 /* R for other */ +#define S_IWOTH 0000002 /* W for other */ +#define S_IXOTH 0000001 /* X for other */ + +#define S_IFMT 0170000 /* type of file */ +#define S_IFIFO 0010000 /* named pipe (fifo) */ +#define S_IFDIR 0040000 /* directory */ +#define S_IFBLK 0060000 /* block special */ +#define S_IFREG 0100000 /* regular */ +#define S_IFLNK 0120000 /* symbolic link */ +#define S_IFSOCK 0140000 /* socket */ + +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) /* directory */ +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) /* regular file */ +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) /* symbolic link */ +#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) /* fifo */ +#define S_ISBLK(m) (0) /* block special */ +#define S_ISCHR(m) (0) /* character special */ + +/****************************************************************************/ + +struct stat +{ + mode_t st_mode; + ino_t st_ino; + dev_t st_dev; + dev_t st_rdev; + nlink_t st_nlink; + uid_t st_uid; + gid_t st_gid; + off_t st_size; + time_t st_atime; + time_t st_mtime; + time_t st_ctime; + long st_blksize; + long st_blocks; +}; + +/****************************************************************************/ + +extern int stat(const char * path_name, struct stat * buffer); +extern int fstat(int file_descriptor, struct stat * buffer); +extern int lstat(const char * path_name, struct stat * buffer); +extern int chmod(const char * path_name, mode_t mode); +extern int fchmod(int file_descriptor, mode_t mode); +extern int mkdir(const char * path_name, mode_t mode); +extern int rmdir(const char * path_name); +extern mode_t umask(mode_t new_mask); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _SYS_STAT_H */ diff --git a/library/include/sys/time.h b/library/include/sys/time.h new file mode 100644 index 0000000..08ecc4b --- /dev/null +++ b/library/include/sys/time.h @@ -0,0 +1,133 @@ +/* + * $Id: time.h,v 1.1.1.1 2004-07-26 16:32:58 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_TIME_H +#define _SYS_TIME_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +/* This is a tough one. Some code takes a bad turn if the + header file is pulled in, which rules out that the structure definitions + in are used. We are only interested in the timeval + structure and try to get by with this definition. Sometimes it works, + sometimes it doesn't. Not sure if there really is a good solution for + this problem... */ +#ifndef DEVICES_TIMER_H + +/****************************************************************************/ + +/* The V40 header files (OS 3.x) and below will always define the + 'struct timeval' in . But the V50 header + files and beyond will not define 'struct timeval' if it is + included from here. We start by checking which header files + are being used. */ +#ifndef EXEC_TYPES_H +#include +#endif /* EXEC_TYPES_H */ + +/****************************************************************************/ + +/* Which header file version is being used? */ +#if INCLUDE_VERSION < 50 + +/****************************************************************************/ + +/* This will define the 'struct timeval' */ +#include + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +/* We will have to make our own... */ +struct timeval +{ + unsigned long tv_secs; + unsigned long tv_micro; +}; + +/* Make sure that the 'struct timeval' is not redefined, should + get included again. */ +#define __TIMEVAL_ALREADY_DEFINED + +/****************************************************************************/ + +#endif /* INCLUDE_VERSION */ + +/****************************************************************************/ + +#endif /* DEVICES_TIMER_H */ + +/****************************************************************************/ + +#ifndef tv_sec +#define tv_sec tv_secs +#endif /* tv_sec */ + +#ifndef tv_usec +#define tv_usec tv_micro +#endif /* tv_usec */ + +/****************************************************************************/ + +struct timezone +{ + int tz_minuteswest; /* of Greenwich */ + int tz_dsttime; /* type of dst correction to apply */ +}; + +/****************************************************************************/ + +int gettimeofday(struct timeval *tp, struct timezone *tzp); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _SYS_TIME_H */ diff --git a/library/include/sys/types.h b/library/include/sys/types.h new file mode 100644 index 0000000..82c6552 --- /dev/null +++ b/library/include/sys/types.h @@ -0,0 +1,70 @@ +/* + * $Id: types.h,v 1.1.1.1 2004-07-26 16:32:59 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_TYPES_H +#define _SYS_TYPES_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +typedef char * caddr_t; +typedef unsigned int comp_t; +typedef unsigned long dev_t; +typedef unsigned int gid_t; +typedef unsigned int ino_t; +typedef unsigned int mode_t; +typedef unsigned int nlink_t; +typedef int off_t; +typedef int pid_t; +typedef unsigned int rlim_t; +typedef int ssize_t; +typedef unsigned int uid_t; + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _SYS_TYPES_H */ diff --git a/library/include/time.h b/library/include/time.h new file mode 100644 index 0000000..633c904 --- /dev/null +++ b/library/include/time.h @@ -0,0 +1,104 @@ +/* + * $Id: time.h,v 1.1.1.1 2004-07-26 16:32:56 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TIME_H +#define _TIME_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _STDDEF_H +#include +#endif /* _STDDEF_H */ + +/****************************************************************************/ + +/* + * Divide the number returned by clock() by CLOCKS_PER_SEC to obtain + * the elapsed time in seconds + */ +#define CLOCKS_PER_SEC 50 + +/****************************************************************************/ + +typedef unsigned long clock_t; +typedef unsigned long time_t; + +/****************************************************************************/ + +struct tm +{ + int tm_sec; /* Number of seconds past the minute (0..59) */ + int tm_min; /* Number of minutes past the hour (0..59) */ + int tm_hour; /* Number of hours past the day (0..23) */ + int tm_mday; /* Day of the month (1..31) */ + int tm_mon; /* Month number (0..11) */ + int tm_year; /* Year number minus 1900 */ + int tm_wday; /* Day of the week (0..6; 0 is Sunday) */ + int tm_yday; /* Day of the year (0..365) */ + int tm_isdst; /* Is this date using daylight savings time? */ +}; + +/****************************************************************************/ + +extern clock_t clock(void); +extern time_t time(time_t * t); +extern char *asctime(const struct tm *tm); +extern char *ctime(const time_t *t); +extern struct tm *gmtime(const time_t *t); +extern struct tm *localtime(const time_t *t); +extern time_t mktime(struct tm *tm); + +/****************************************************************************/ + +extern double difftime(time_t t1,time_t t0); + +/****************************************************************************/ + +extern size_t strftime(char *s, size_t maxsize, const char *format, + const struct tm *tm); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _TIME_H */ diff --git a/library/include/unistd.h b/library/include/unistd.h new file mode 100644 index 0000000..85349bc --- /dev/null +++ b/library/include/unistd.h @@ -0,0 +1,275 @@ +/* + * $Id: unistd.h,v 1.1.1.1 2004-07-26 16:32:56 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_H +#define _UNISTD_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _FCNTL_H +#include +#endif /* _FCNTL_H */ + +/****************************************************************************/ + +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 + +/****************************************************************************/ + +#define R_OK 0 +#define W_OK 1 +#define X_OK 2 +#define F_OK 4 + +/****************************************************************************/ + +extern int opterr; +extern int optind; +extern int optopt; +extern char * optarg; + +/****************************************************************************/ + +extern int isatty(int file_descriptor); +extern int dup(int file_descriptor); +extern int dup2(int file_descriptor1, int file_descriptor2); +extern int access(const char * path_name, int mode); +extern int chown(const char * path_name, uid_t owner, gid_t group); +extern int fchown(int file_descriptor, uid_t owner, gid_t group); +extern int lchown(const char * path_name, uid_t owner, gid_t group); +extern int truncate(const char * path_name, off_t length); +extern int ftruncate(int file_descriptor, off_t length); +extern int link(const char * existing_path,const char * new_path); +extern int unlink(const char * path_name); +extern int symlink(const char * actual_path, const char * symbolic_path); +extern int readlink(const char * path_name, char * buffer, int buffer_size); +extern int chdir(const char * path_name); +extern unsigned int sleep(unsigned int seconds); +extern int getopt(int argc, char * argv[], char *opts); +extern pid_t getpid(void); +extern char *realpath(const char *file_name, char *resolved_name); + +/****************************************************************************/ + +extern char * getcwd(char * buffer, size_t buffer_size); + +/* This is the version for use with memory debugging; do not call + it directly! */ +extern char * __getcwd(char * buffer,size_t buffer_size,const char *file,int line); + +#ifdef __MEM_DEBUG +#define getcwd(buffer,buffer_size) __getcwd((buffer),(buffer_size),__FILE__,__LINE__) +#endif /* __MEM_DEBUG */ + +/****************************************************************************/ + +/* + * The following may have been predefined by local TCP/IP header files. We + * don't want to be any trouble... + */ + +#if !defined(FD_SET) && !defined(__NO_NET_API) + +/****************************************************************************/ + +#ifndef _STRING_H +#include +#endif /* _STRING_H */ + +#ifndef _STDLIB_H +#include +#endif /* _STDLIB_H */ + +#ifndef _SYS_TIME_H +#include +#endif /* _SYS_TIME_H */ + +#ifndef _SYS_TYPES_H +#include +#endif /* _SYS_TYPES_H */ + +/****************************************************************************/ + +/* + * select() uses bit masks of file descriptors in longs. These macros + * manipulate such bit fields. + * + * FD_SETSIZE may be defined by the user, but the default here should + * be enough for most uses. + */ +#ifndef FD_SETSIZE +#define FD_SETSIZE 256 +#endif + +typedef struct +{ + unsigned long bits[(FD_SETSIZE + 31) / 32]; +} fd_set; + +#define FD_SET(n,p) ((void)((p)->bits[((unsigned long)n) >> 5] |= (1UL << (((unsigned long)n) & 31)))) +#define FD_CLR(n,p) ((void)((p)->bits[((unsigned long)n) >> 5] &= ~(1UL << (((unsigned long)n) & 31)))) +#define FD_ISSET(n,p) (((p)->bits[((unsigned long)n) >> 5] & (1UL << (((unsigned long)n) & 31))) != 0) +#define FD_COPY(f,t) ((void)memmove(t,f,sizeof(*(f)))) +#define FD_ZERO(p) ((void)memset(p,0,sizeof(*(p)))) + +/****************************************************************************/ + +/* Forward declarations for below... */ +struct hostent; +struct netent; +struct protoent; +struct servent; +struct passwd; +struct msghdr; +struct sockaddr; + +/****************************************************************************/ + +/* + * You might want to have included in place of + * this local definition. + */ +#if defined(__USE_NETINET_IN_H) + +#include + +#else + +/* + * These two symbols are typically defined by , which also + * happens to define 'struct in_addr'. We don't want to redefine it. + */ +#if !defined(_NETINET_IN_H) && !defined(IPPROTO_IP) + +/* Internet address (a structure for historical reasons) */ +struct in_addr +{ + unsigned long s_addr; +}; + +#endif /* !_NETINET_IN_H && !IPPROTO_IP */ + +#endif /* __USE_NETINET_IN_H */ + +/****************************************************************************/ + +extern int accept(int sockfd,struct sockaddr *cliaddr,int *addrlen); +extern int bind(int sockfd,struct sockaddr *name,int namelen); +extern int connect(int sockfd,struct sockaddr *name,int namelen); +extern struct hostent * gethostbyaddr(const char *addr, int len, int type); +extern struct hostent * gethostbyname(const char *name); +extern int gethostname(const char *name, int namelen); +extern struct netent * getnetbyname(const char *name); +extern int getpeername(int sockfd,struct sockaddr *name,int *namelen); +extern int getsockname(int sockfd,struct sockaddr *name,int *namelen); +extern int getsockopt(int sockfd,int level,int optname,void *optval,int *optlen); +extern unsigned long inet_addr(const char *addr); +extern char * inet_ntoa(struct in_addr in); +extern int ioctl(int fd,unsigned long request, ... /* char *arg */); +extern int listen(int sockfd,int backlog); +extern int recv(int fd,void *buff,size_t nbytes,int flags); +extern int recvfrom(int sockfd,void *buff,int len,int flags,struct sockaddr *from,int *fromlen); +extern int recvmsg(int socket,struct msghdr *msg,int flags); +extern int select(int num_fds,fd_set *read_fds,fd_set *write_fds,fd_set *except_fds,struct timeval *timeout); +extern int send(int fd,void *buff,size_t nbytes,int flags); +extern int sendmsg(int socket,struct msghdr *msg,int flags); +extern int sendto(int sockfd,void *buff,int len,int flags,struct sockaddr *to,int tolen); +extern int setsockopt(int sockfd,int level,int optname,void *optval,int optlen); +extern int shutdown(int socket, int how); +extern int socket(int domain,int type,int protocol); +extern long gethostid(void); +extern struct netent * getnetbyaddr(long net,int type); +extern struct servent * getservbyname(const char *name, const char *proto); +extern struct servent * getservbyport(int port, const char *proto); +extern struct protoent * getprotobyname(const char *name); +extern struct protoent * getprotobynumber(int proto); +extern int inet_aton(const char *cp, struct in_addr *addr); +extern unsigned long inet_lnaof(struct in_addr in); +extern struct in_addr inet_makeaddr(int net,int host); +extern unsigned long inet_netof(struct in_addr in); +extern unsigned long inet_network(const char *cp); + +/****************************************************************************/ + +extern char *crypt(const char *key, const char *salt); +extern gid_t getegid(void); +extern uid_t geteuid(void); +extern gid_t getgid(void); +extern struct group *getgrgid(gid_t gid); +extern struct group *getgrnam(const char *name); +extern int getgroups(int ngroups, gid_t *groups); +extern char *getpass(const char *prompt); +extern struct passwd *getpwnam(const char *name); +extern struct passwd *getpwuid(uid_t uid); +extern uid_t getuid(void); +extern int initgroups(const char *name, gid_t basegroup); +extern int setegid(gid_t g); +extern int seteuid(uid_t u); +extern int setgid(gid_t id); +extern int setgroups(int ngroups, const gid_t *groups); +extern int setregid(gid_t real, gid_t eff); +extern int setreuid(uid_t real, uid_t eff); +extern long setsid(void); +extern int setuid(uid_t id); +extern void endgrent(void); +extern void endpwent(void); +extern struct group *getgrent(void); +extern struct passwd *getpwent(void); +extern void setgrent(void); +extern void setpwent(void); + +/****************************************************************************/ + +#endif /* !FD_SET && !__NO_NET_API */ + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _UNISTD_H */ diff --git a/library/include/utime.h b/library/include/utime.h new file mode 100644 index 0000000..bc69ffd --- /dev/null +++ b/library/include/utime.h @@ -0,0 +1,73 @@ +/* + * $Id: utime.h,v 1.1.1.1 2004-07-26 16:32:56 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UTIME_H +#define _UTIME_H + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _TIME_H +#include +#endif /* _TIME_H */ + +/****************************************************************************/ + +struct utimbuf +{ + time_t actime; /* Access time */ + time_t modtime; /* Modification time */ +}; + +/****************************************************************************/ + +extern int utime(const char * path_name,const struct utimbuf * times); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _UTIME_H */ diff --git a/library/include/wchar.h b/library/include/wchar.h new file mode 100644 index 0000000..e6c923e --- /dev/null +++ b/library/include/wchar.h @@ -0,0 +1,171 @@ +/* + * $Id: wchar.h,v 1.1.1.1 2004-07-26 16:32:57 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_H +#define _WCHAR_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _STDDEF_H +#include +#endif /* _STDDEF_H */ + +#ifndef _STDIO_H +#include +#endif /* _STDIO_H */ + +#ifndef _STDARG_H +#include +#endif /* _STDARG_H */ + +#ifndef _TIME_H +#include +#endif /* _TIME_H */ + +/****************************************************************************/ + +#define WEOF (-1) +#define WCHAR_MAX 65535 +#define WCHAR_MIN 0 + +/****************************************************************************/ + +typedef long int wint_t; +typedef long mbstate_t; + +/****************************************************************************/ + +extern wint_t btowc(int c); +extern int wctob(wint_t c); +extern int mbsinit(const mbstate_t *ps); +extern size_t mbrlen(wchar_t *pwc, const char * s, size_t n, mbstate_t *ps); +extern size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps); +extern size_t mbsrtowcs(wchar_t *pwcs, const char **src, size_t n, mbstate_t *ps); +extern size_t wcsrtombs(char *s, const wchar_t **src, size_t n, mbstate_t *ps); + +/****************************************************************************/ + +extern wchar_t *wcscat(wchar_t *dest, const wchar_t *src); +extern wchar_t *wcsncat(wchar_t *dest, const wchar_t *src, size_t n); +extern int wcscmp(const wchar_t *s1, const wchar_t * s2); +extern int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n); +extern wchar_t * wcscpy(wchar_t *dest, const wchar_t *src); +extern wchar_t * wcsncpy(wchar_t *dest, const wchar_t *src, size_t n); +extern size_t wcslen(const wchar_t *s); +extern wchar_t * wcschr(const wchar_t *s, wchar_t c); +extern size_t wcsspn(const wchar_t *s, const wchar_t *set); +extern wchar_t wcspbrk(const wchar_t *s, const wchar_t *set); +extern wchar_t *wcstok(wchar_t *str, const wchar_t *set); +extern wchar_t *wcsstr(const wchar_t *src, const wchar_t *sub); + +/****************************************************************************/ + +extern double wcstod(const wchar_t *str, wchar_t **ptr); +extern long wcstol(const wchar_t *str, wchar_t **ptr, int base); +extern unsigned long wcstoul(const wchar_t *str, wchar_t **ptr, int base); + +/****************************************************************************/ + +extern int wscoll(const wchar_t *s1, const wchar_t *s2); +extern size_t wcsxfrm(wchar_t *dest, const wchar_t *src, size_t len); + +/****************************************************************************/ + +extern wchar_t *wmemchr(const wchar_t *ptr, wchar_t val, size_t len); +extern int wmemcmp(const wchar_t *ptr1, const wchar_t *ptr2, size_t len); +extern wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t len); +extern wchar_t *wmemmove(wchar_t *dest, const wchar_t * src, size_t len); +extern wchar_t *wmemset(wchar_t *ptr, int val, size_t len); + +/****************************************************************************/ + +extern int fwide(FILE *stream, int orient); + +/****************************************************************************/ + +extern wint_t fgetwc(FILE *stream); +extern wint_t getwc(FILE *stream); +extern wint_t getwchar(void); +extern wint_t ungetwc(wint_t c,FILE *stream); + +/****************************************************************************/ + +extern wchar_t *fgetws(wchar_t *s, int n, FILE *stream); + +/****************************************************************************/ + +extern int fwscanf(FILE *stream, const wchar_t *format, ...); +extern int wscanf(const wchar_t *format, ...); +extern int swscanf(wchar_t *s,const wchar_t *format, ...); + +/****************************************************************************/ + +extern wint_t fputwc(wchar_t c,FILE *stream); +extern wint_t putwc(wchar_t c,FILE *stream); +extern wint_t putwchar(wchar_t c); + +/****************************************************************************/ + +extern wint_t fputws(const wchar_t *s, FILE *stream); + +/****************************************************************************/ + +extern int fwprintf(FILE *stream,const wchar_t *format,...); +extern int wprintf(const wchar_t *format, ...); +extern int swprintf(wchar_t *s, const wchar_t *format, ...); + +/****************************************************************************/ + +extern int vfwprintf(FILE *stream,const wchar_t *format,va_list arg); +extern int vwprintf(const wchar_t *format,va_list arg); +extern int vswprintf(char *s, const wchar_t *format,va_list arg); + +/****************************************************************************/ + +extern size_t wcsftime(wchar_t *s, size_t maxsize, const wchar_t *format, const struct tm *timeptr); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _WCHAR_H */ diff --git a/library/include/wctype.h b/library/include/wctype.h new file mode 100644 index 0000000..e7b9716 --- /dev/null +++ b/library/include/wctype.h @@ -0,0 +1,93 @@ +/* + * $Id: wctype.h,v 1.1.1.1 2004-07-26 16:32:57 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCYTPE_H +#define _WCYTPE_H + +/****************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/****************************************************************************/ + +#ifndef _WCHAR_H +#include +#endif /* _WCHAR_H */ + +/****************************************************************************/ + +typedef long wctype_t; /* ZZZ */ +typedef long wctrans_t; /* ZZZ */ + +/****************************************************************************/ + +extern int iswalnum(wint_t c); +extern int iswalpha(wint_t c); +extern int iswcntrl(wint_t c); + +extern int iswdigit(wint_t c); +extern int iswxdigit(wint_t c); + +extern int iswgraph(wint_t c); +extern int iswpunc(wint_t c); +extern int iswprint(wint_t c); + +extern int iswlower(wint_t c); +extern int iswupper(wint_t c); + +extern int iswspace(wint_t c); + +extern wint_t towlower(wint_t c); +extern wint_t towupper(wint_t c); + +/****************************************************************************/ + +extern wctype_t wctype(const char *property); +extern int iswctype(wint_t c, wctype_t desc); + +/****************************************************************************/ + +extern wctrans_t wctrans(const char *property); +extern wint_t towctrans(wint_t c, wctrans_t desc); + +/****************************************************************************/ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +/****************************************************************************/ + +#endif /* _WCYTPE_H */ diff --git a/library/libgen_basename.c b/library/libgen_basename.c new file mode 100644 index 0000000..0fec9d9 --- /dev/null +++ b/library/libgen_basename.c @@ -0,0 +1,97 @@ +/* + * $Id: libgen_basename.c,v 1.1.1.1 2004-07-26 16:30:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +char * +basename(char *path) +{ + char * result; + + ENTER(); + + if(path == NULL) + SHOWPOINTER(path); + else + SHOWSTRING(path); + + if(path == NULL || path[0] == '\0') + { + result = "."; + } + else + { + int len,i; + + len = strlen(path); + + while(len > 0 && path[len-1] == '/') + len--; + + if(len > 0) + { + result = path; + + path[len] = '\0'; + + for(i = len-1 ; i >= 0 ; i--) + { + if(path[i] == '/') + { + result = &path[i+1]; + break; + } + } + } + else + { + result = "/"; + } + } + + SHOWSTRING(result); + + RETURN(result); + return(result); +} diff --git a/library/libgen_dirname.c b/library/libgen_dirname.c new file mode 100644 index 0000000..28b8d8a --- /dev/null +++ b/library/libgen_dirname.c @@ -0,0 +1,98 @@ +/* + * $Id: libgen_dirname.c,v 1.1.1.1 2004-07-26 16:30:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +/****************************************************************************/ + +#include "debug.h" + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +char * +dirname(char *path) +{ + char * result; + + ENTER(); + + if(path == NULL) + SHOWPOINTER(path); + else + SHOWSTRING(path); + + if(path == NULL || path[0] == '\0') + { + result = "."; + } + else + { + int len,i; + + len = strlen(path); + + while(len > 0 && path[len-1] == '/') + len--; + + if(len > 0) + { + result = "."; + + for(i = len-1 ; i >= 0 ; i--) + { + if(path[i] == '/') + { + path[i] = '\0'; + + result = path; + + break; + } + } + } + else + { + result = "/"; + } + } + + SHOWSTRING(result); + + RETURN(result); + return(result); +} diff --git a/library/locale_data.c b/library/locale_data.c new file mode 100644 index 0000000..d77ddc6 --- /dev/null +++ b/library/locale_data.c @@ -0,0 +1,45 @@ +/* + * $Id: locale_data.c,v 1.1.1.1 2004-07-26 16:30:35 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +struct Locale * __default_locale; +struct Locale * __locale_table[NUM_LOCALES]; + +/****************************************************************************/ + +char __locale_name_table[NUM_LOCALES][MAX_LOCALE_NAME_LEN]; diff --git a/library/locale_headers.h b/library/locale_headers.h new file mode 100644 index 0000000..6023fd4 --- /dev/null +++ b/library/locale_headers.h @@ -0,0 +1,85 @@ +/* + * $Id: locale_headers.h,v 1.1.1.1 2004-07-26 16:30:35 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOCALE_HEADERS_H +#define _LOCALE_HEADERS_H + +/****************************************************************************/ + +#include + +#include + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#include +#include +#include +#include + +/****************************************************************************/ + +#ifndef _STDLIB_LOCALE_UTILITY_H +#include "stdlib_locale_utility.h" +#endif /* _STDLIB_LOCALE_UTILITY_H */ + +/****************************************************************************/ + +#include "macros.h" +#include "debug.h" + +/****************************************************************************/ + +#define NUM_LOCALES (LC_TIME - LC_ALL + 1) +#define MAX_LOCALE_NAME_LEN 256 + +/****************************************************************************/ + +extern struct Locale * __default_locale; +extern struct Locale * __locale_table[NUM_LOCALES]; + +/****************************************************************************/ + +extern char __locale_name_table[NUM_LOCALES][MAX_LOCALE_NAME_LEN]; + +/****************************************************************************/ + +extern void __close_all_locales(void); + +/****************************************************************************/ + +#endif /* _LOCALE_HEADERS_H */ diff --git a/library/locale_init_exit.c b/library/locale_init_exit.c new file mode 100644 index 0000000..8d3139b --- /dev/null +++ b/library/locale_init_exit.c @@ -0,0 +1,149 @@ +/* + * $Id: locale_init_exit.c,v 1.1.1.1 2004-07-26 16:30:35 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +#include "stdlib_protos.h" + +/****************************************************************************/ + +void +__close_all_locales(void) +{ + if(__LocaleBase != NULL) + { + DECLARE_LOCALEBASE(); + + int i; + + for(i = 0 ; i < NUM_LOCALES ; i++) + { + if(i == LC_ALL) + continue; + + if(__locale_table[i] != NULL) + { + if(__locale_table[i] != __locale_table[LC_ALL]) + CloseLocale(__locale_table[i]); + + __locale_table[i] = NULL; + } + } + + CloseLocale(__locale_table[LC_ALL]); + __locale_table[LC_ALL] = NULL; + } +} + +/****************************************************************************/ + +void +__locale_exit(void) +{ + ENTER(); + + if(__LocaleBase != NULL) + { + DECLARE_LOCALEBASE(); + + __close_all_locales(); + + if(__default_locale != NULL) + { + CloseLocale(__default_locale); + __default_locale = NULL; + } + + #if defined(__amigaos4__) + { + if(__ILocale != NULL) + { + DropInterface((struct Interface *)__ILocale); + __ILocale = NULL; + } + } + #endif /* __amigaos4__ */ + + CloseLibrary(__LocaleBase); + __LocaleBase = NULL; + } + + LEAVE(); +} + +/****************************************************************************/ + +int +__locale_init(void) +{ + int i; + + ENTER(); + + for(i = 0 ; i < NUM_LOCALES ; i++) + strcpy(__locale_name_table[i],"C"); + + PROFILE_OFF(); + + __LocaleBase = OpenLibrary("locale.library",38); + + #if defined(__amigaos4__) + { + if (__LocaleBase != NULL) + { + __ILocale = (struct LocaleIFace *)GetInterface(__LocaleBase, "main", 1, 0); + if(__ILocale == NULL) + { + CloseLibrary(__LocaleBase); + __LocaleBase = NULL; + } + } + } + #endif /* __amigaos4__ */ + + if(__LocaleBase != NULL) + { + DECLARE_LOCALEBASE(); + + __default_locale = OpenLocale(NULL); + } + + PROFILE_ON(); + + RETURN(OK); + return(OK); +} diff --git a/library/locale_localeconv.c b/library/locale_localeconv.c new file mode 100644 index 0000000..76370a6 --- /dev/null +++ b/library/locale_localeconv.c @@ -0,0 +1,76 @@ +/* + * $Id: locale_localeconv.c,v 1.1.1.1 2004-07-26 16:30:35 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +struct lconv * +localeconv(void) +{ + static struct lconv loc; + struct Locale * numeric_locale = __locale_table[LC_NUMERIC]; + struct Locale * monetary_locale = __locale_table[LC_MONETARY]; + struct lconv * result; + + ENTER(); + + /* This makes up the current locale settings from the various + * components in use. + */ + loc.decimal_point = (numeric_locale != NULL) ? ((char *)numeric_locale->loc_DecimalPoint) : "."; + loc.thousands_sep = (numeric_locale != NULL) ? ((char *)numeric_locale->loc_GroupSeparator) : ""; + loc.grouping = (numeric_locale != NULL) ? ((char *)numeric_locale->loc_Grouping) : ""; + loc.int_curr_symbol = (monetary_locale != NULL) ? ((char *)monetary_locale->loc_MonIntCS) : ""; + loc.currency_symbol = (monetary_locale != NULL) ? ((char *)monetary_locale->loc_MonCS) : ""; + loc.mon_decimal_point = (monetary_locale != NULL) ? ((char *)monetary_locale->loc_MonDecimalPoint) : ""; + loc.mon_thousands_sep = (monetary_locale != NULL) ? ((char *)monetary_locale->loc_MonGroupSeparator) : ""; + loc.mon_grouping = (monetary_locale != NULL) ? ((char *)monetary_locale->loc_MonGrouping) : ""; + loc.positive_sign = (monetary_locale != NULL) ? ((char *)monetary_locale->loc_MonPositiveSign) : ""; + loc.negative_sign = (monetary_locale != NULL) ? ((char *)monetary_locale->loc_MonNegativeSign) : ""; + loc.int_frac_digits = (monetary_locale != NULL) ? monetary_locale->loc_MonIntFracDigits : CHAR_MAX; + loc.frac_digits = (monetary_locale != NULL) ? monetary_locale->loc_MonFracDigits : CHAR_MAX; + loc.p_cs_precedes = (monetary_locale != NULL) ? monetary_locale->loc_MonPositiveCSPos : CHAR_MAX; + loc.p_sep_by_space = (monetary_locale != NULL) ? monetary_locale->loc_MonPositiveSpaceSep : CHAR_MAX; + loc.n_cs_precedes = (monetary_locale != NULL) ? monetary_locale->loc_MonNegativeCSPos : CHAR_MAX; + loc.n_sep_by_space = (monetary_locale != NULL) ? monetary_locale->loc_MonNegativeSpaceSep : CHAR_MAX; + loc.p_sign_posn = (monetary_locale != NULL) ? monetary_locale->loc_MonPositiveSignPos : CHAR_MAX; + loc.n_sign_posn = (monetary_locale != NULL) ? monetary_locale->loc_MonNegativeSignPos : CHAR_MAX; + + result = &loc; + + RETURN(result); + return(result); +} diff --git a/library/locale_setlocale.c b/library/locale_setlocale.c new file mode 100644 index 0000000..27317ef --- /dev/null +++ b/library/locale_setlocale.c @@ -0,0 +1,160 @@ +/* + * $Id: locale_setlocale.c,v 1.1.1.1 2004-07-26 16:30:36 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +char * +setlocale(int category, const char *locale) +{ + DECLARE_LOCALEBASE(); + char * result = NULL; + + ENTER(); + + SHOWVALUE(category); + + if(locale == NULL) + SHOWPOINTER(locale); + else + SHOWSTRING(locale); + + if(category < LC_ALL || category > LC_TIME) + { + SHOWMSG("invalid category"); + + errno = EINVAL; + goto out; + } + + if(locale != NULL) + { + struct Locale * loc = NULL; + + /* We have to keep the locale name for later reference. + * On the Amiga this will be a path and file name so it + * can become rather long. But we can't store an arbitrarily + * long name either. + * + * ZZZ change this to dynamic allocation of the locale name. + */ + if(strlen(locale) >= MAX_LOCALE_NAME_LEN) + { + SHOWMSG("locale name is too long"); + + errno = ENAMETOOLONG; + goto out; + } + + /* Unless we are switching to the "C" locale, + * try to open a locale if we managed to open + * locale.library before. + */ + if(LocaleBase != NULL) + { + if(strcmp(locale,"C") != SAME) + { + SHOWMSG("this is not the 'C' locale"); + + PROFILE_OFF(); + + /* The empty string stands for the default locale. */ + if(locale[0] == '\0') + loc = OpenLocale(NULL); + else + loc = OpenLocale((STRPTR)locale); + + PROFILE_ON(); + + if(loc == NULL) + { + SHOWMSG("couldn't open the locale"); + + errno = ENOENT; + goto out; + } + } + } + + if(category == LC_ALL) + { + int i; + + SHOWMSG("closing all locales"); + + /* We have to replace all locales. We + * start by closing them all. + */ + __close_all_locales(); + + SHOWMSG("reinitializing all locales"); + + /* And this puts the new locale into all table entries. */ + for(i = 0 ; i < NUM_LOCALES ; i++) + { + __locale_table[i] = loc; + strcpy(__locale_name_table[i],locale); + } + } + else + { + SHOWMSG("closing the locale"); + + /* Close this single locale unless it's actually just a + * copy of the 'all' locale entry. + */ + if(__locale_table[category] != NULL && __locale_table[category] != __locale_table[LC_ALL]) + { + assert( LocaleBase != NULL ); + CloseLocale(__locale_table[category]); + } + + SHOWMSG("reinitializing the locale"); + + __locale_table[category] = loc; + strcpy(__locale_name_table[category],locale); + } + } + + result = __locale_name_table[category]; + + SHOWSTRING(result); + + out: + + RETURN(result); + return(result); +} diff --git a/library/m.lib_rev.c b/library/m.lib_rev.c new file mode 100644 index 0000000..3658c60 --- /dev/null +++ b/library/m.lib_rev.c @@ -0,0 +1,38 @@ +/* + * $Id: m.lib_rev.c,v 1.1.1.1 2004-07-26 16:30:36 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "m.lib_rev.h" + +/****************************************************************************/ + +char __m_lib_version[] = VERSTAG; diff --git a/library/m.lib_rev.h b/library/m.lib_rev.h new file mode 100644 index 0000000..3c51aca --- /dev/null +++ b/library/m.lib_rev.h @@ -0,0 +1,6 @@ +#define VERSION 1 +#define REVISION 165 +#define DATE "26.7.2004" +#define VERS "m.lib 1.165" +#define VSTRING "m.lib 1.165 (26.7.2004)\r\n" +#define VERSTAG "\0$VER: m.lib 1.165 (26.7.2004)" diff --git a/library/m.lib_rev.rev b/library/m.lib_rev.rev new file mode 100644 index 0000000..9e42f3e --- /dev/null +++ b/library/m.lib_rev.rev @@ -0,0 +1 @@ +165 diff --git a/library/m881.lib_rev.c b/library/m881.lib_rev.c new file mode 100644 index 0000000..f715f3b --- /dev/null +++ b/library/m881.lib_rev.c @@ -0,0 +1,38 @@ +/* + * $Id: m881.lib_rev.c,v 1.1.1.1 2004-07-26 16:30:36 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "m881.lib_rev.h" + +/****************************************************************************/ + +char __m881_lib_version[] = VERSTAG; diff --git a/library/m881.lib_rev.h b/library/m881.lib_rev.h new file mode 100644 index 0000000..5d5c618 --- /dev/null +++ b/library/m881.lib_rev.h @@ -0,0 +1,6 @@ +#define VERSION 1 +#define REVISION 165 +#define DATE "26.7.2004" +#define VERS "m881.lib 1.165" +#define VSTRING "m881.lib 1.165 (26.7.2004)\r\n" +#define VERSTAG "\0$VER: m881.lib 1.165 (26.7.2004)" diff --git a/library/m881.lib_rev.rev b/library/m881.lib_rev.rev new file mode 100644 index 0000000..9e42f3e --- /dev/null +++ b/library/m881.lib_rev.rev @@ -0,0 +1 @@ +165 diff --git a/library/macros.h b/library/macros.h new file mode 100644 index 0000000..1411f82 --- /dev/null +++ b/library/macros.h @@ -0,0 +1,198 @@ +/* + * $Id: macros.h,v 1.1.1.1 2004-07-26 16:30:36 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACROS_H +#define _MACROS_H + +/****************************************************************************/ + +#ifndef DOS_DOS_H +#include +#endif /* DOS_DOS_H */ + +/****************************************************************************/ + +#define CANNOT ! +#define DO_NOTHING ((void)0) +#define NO ! +#define NOT ! +#define DO_NOT ! +#define OK (0) +#define SAME (0) +#define SEEK_ERROR (-1) +#define ERROR (-1) + +/****************************************************************************/ + +#ifndef ZERO +#define ZERO ((BPTR)NULL) +#endif /* ZERO */ + +/****************************************************************************/ + +#define UNIX_TIME_OFFSET 252460800 + +/****************************************************************************/ + +#define NUM_ENTRIES(t) (sizeof(t) / sizeof(t[0])) + +/****************************************************************************/ + +#define FLAG_IS_SET(v,f) (((v) & (f)) == (f)) +#define FLAG_IS_CLEAR(v,f) (((v) & (f)) == 0 ) + +/****************************************************************************/ + +#define SET_FLAG(v,f) ((void)((v) |= (f))) +#define CLEAR_FLAG(v,f) ((void)((v) &= ~(f))) + +/****************************************************************************/ + +/* Macro to get longword-aligned stack space for a structure + * Uses ANSI token catenation to form a name for the char array + * based on the variable name, then creates an appropriately + * typed pointer to point to the first longword boundary in the + * char array allocated. + */ +#define D_S(type, name) \ + char a_##name[sizeof(type)+3]; \ + type *name = (type *)((LONG)(a_##name+3) & ~3) + +/****************************************************************************/ + +#ifndef AMIGA_COMPILER_H + +#ifdef __SASC + +#ifndef ASM +#define ASM __asm +#endif /* ASM */ + +#ifndef REG +#define REG(r,p) register __##r p +#endif /* REG */ + +#ifndef INTERRUPT +#define INTERRUPT __interrupt +#endif /* INTERRUPT */ + +#ifndef INLINE +#define INLINE __inline +#endif /* INLINE */ +#endif /* __SASC */ + +#ifdef __GNUC__ + +#ifndef ASM +#define ASM +#endif /* ASM */ + +#ifndef REG +#define REG(r,p) p __asm(#r) +#endif /* REG */ + +#ifndef INTERRUPT +#define INTERRUPT __attribute__((__interrupt__)) +#endif /* INTERRUPT */ + +#ifndef INLINE +#define INLINE __inline__ +#endif /* INLINE */ + +#endif /* __GNUC__ */ + +#endif /* AMIGA_COMPILER_H */ + +/****************************************************************************/ + +#ifndef WEAK +#ifdef __GNUC__ +#define WEAK __attribute__((weak)) +#else +#define WEAK /* WEAK */ +#endif +#endif /* WEAK */ + +/****************************************************************************/ + +#ifndef UNUSED +#ifdef __GNUC__ +#define UNUSED __attribute__((unused)) +#else +#define UNUSED /* UNUSED */ +#endif +#endif /* UNUSED */ + +/****************************************************************************/ + +#ifdef __SASC +#define CLIB_CONSTRUCTOR(name) int __stdargs _STI_500_##name(void) +#define CLIB_DESTRUCTOR(name) void __stdargs _STD_500_##name(void) +#define PROFILE_CONSTRUCTOR(name) int __stdargs _STI_150_##name(void) +#define PROFILE_DESTRUCTOR(name) void __stdargs _STD_150_##name(void) +#define CONSTRUCTOR_SUCCEED() return(0) +#define CONSTRUCTOR_FAIL() return(1) +#endif /* __SASC */ + +#ifdef __GNUC__ +#define CLIB_CONSTRUCTOR(name) static void __attribute__((constructor)) name##_ctor(void) +#define CLIB_DESTRUCTOR(name) static void __attribute__((destructor)) name##_dtor(void) +#define PROFILE_CONSTRUCTOR(name) static void __attribute__((constructor)) name##_ctor(void) +#define PROFILE_DESTRUCTOR(name) static void __attribute__((destructor)) name##_dtor(void) +#define CONSTRUCTOR_SUCCEED() return +#define CONSTRUCTOR_FAIL() exit(20) /* ZZZ not a nice thing to do; fix the constructor invocation code! */ +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#ifdef __SASC +extern void ASM _PROLOG(REG(a0,char *)); +extern void ASM _EPILOG(REG(a0,char *)); + +#if _PROFILE +#define PROFILE_OFF() _PROLOG(0L) +#define PROFILE_ON() _EPILOG(0L) +#else +#define PROFILE_OFF() ((void)0) +#define PROFILE_ON() ((void)0) +#endif /* _PROFILE */ +#endif /* __SASC */ + +#ifdef __GNUC__ +#define PROFILE_OFF() ((void)0) +#define PROFILE_ON() ((void)0) +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* _MACROS_H */ diff --git a/library/make_ctype_table.c b/library/make_ctype_table.c new file mode 100644 index 0000000..d013876 --- /dev/null +++ b/library/make_ctype_table.c @@ -0,0 +1,297 @@ +/* + * $Id: make_ctype_table.c,v 1.1.1.1 2004-07-26 16:30:37 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +/****************************************************************************/ + +#define __CTYPE_CONTROL 0x01 +#define __CTYPE_DIGIT 0x02 +#define __CTYPE_HEX_DIGIT 0x04 +#define __CTYPE_PUNCTUATION 0x08 +#define __CTYPE_PRINTABLE 0x10 +#define __CTYPE_WHITE_SPACE 0x20 +#define __CTYPE_LOWER_CASE 0x40 +#define __CTYPE_UPPER_CASE 0x80 + +/****************************************************************************/ + +unsigned char __ctype_table[128]; + +/****************************************************************************/ + +struct { char * name; int flag; } tab[] = +{ + + { "__CTYPE_CONTROL", __CTYPE_CONTROL }, + { "__CTYPE_DIGIT", __CTYPE_DIGIT }, + { "__CTYPE_HEX_DIGIT", __CTYPE_HEX_DIGIT }, + { "__CTYPE_PUNCTUATION", __CTYPE_PUNCTUATION }, + { "__CTYPE_PRINTABLE", __CTYPE_PRINTABLE }, + { "__CTYPE_WHITE_SPACE", __CTYPE_WHITE_SPACE }, + { "__CTYPE_LOWER_CASE", __CTYPE_LOWER_CASE }, + { "__CTYPE_UPPER_CASE", __CTYPE_UPPER_CASE }, + { NULL, 0 } + +}; + +/****************************************************************************/ + +#define _isalnum(c) ((__ctype_table[c] & (__CTYPE_DIGIT|__CTYPE_LOWER_CASE|__CTYPE_UPPER_CASE)) != 0) +#define _isalpha(c) ((__ctype_table[c] & (__CTYPE_LOWER_CASE|__CTYPE_UPPER_CASE)) != 0) +#define _iscntrl(c) ((__ctype_table[c] & __CTYPE_CONTROL) != 0) +#define _isdigit(c) ((__ctype_table[c] & __CTYPE_DIGIT) != 0) +#define _isxdigit(c) ((__ctype_table[c] & __CTYPE_HEX_DIGIT) != 0) +#define _isgraph(c) ((__ctype_table[c] & (__CTYPE_DIGIT|__CTYPE_PUNCTUATION|__CTYPE_LOWER_CASE|__CTYPE_UPPER_CASE)) != 0) +#define _ispunct(c) ((__ctype_table[c] & __CTYPE_PUNCTUATION) != 0) +#define _isprint(c) ((__ctype_table[c] & __CTYPE_PRINTABLE) != 0) +#define _islower(c) ((__ctype_table[c] & __CTYPE_LOWER_CASE) != 0) +#define _isupper(c) ((__ctype_table[c] & __CTYPE_UPPER_CASE) != 0) +#define _isspace(c) ((__ctype_table[c] & __CTYPE_WHITE_SPACE) != 0) + +/****************************************************************************/ + +void +dump_table(void) +{ + int i; + + printf("const unsigned char __ctype_table[128] =\n{\n"); + + for(i = 0 ; i < 128 ; i++) + { + printf("\t/* %3d",i); + + if(' ' <= i && i <= '~') + printf(", '%c'",i); + else + printf(" "); + + printf(" */ "); + + if(__ctype_table[i] != 0) + { + int j,k; + + for(j = k = 0 ; tab[j].name != NULL ; j++) + { + if(__ctype_table[i] & tab[j].flag) + { + if(k++ > 0) + printf("|"); + + printf("%s",tab[j].name); + } + } + } + else + { + printf("0"); + } + + if(i < 127) + printf(","); + + printf("\n"); + } + + printf("};\n"); +} + +/****************************************************************************/ + +int +main(void) +{ + int i,a,b; + + /* Rebuild the contents of the character type table. */ + memset(__ctype_table,0,sizeof(__ctype_table)); + + for(i = 0 ; i < 128 ; i++) + { + if(iscntrl(i)) + __ctype_table[i] |= __CTYPE_CONTROL; + + if(isdigit(i)) + __ctype_table[i] |= __CTYPE_DIGIT; + + if(isxdigit(i)) + __ctype_table[i] |= __CTYPE_HEX_DIGIT; + + if(ispunct(i)) + __ctype_table[i] |= __CTYPE_PUNCTUATION; + + if(isspace(i)) + __ctype_table[i] |= __CTYPE_WHITE_SPACE; + + if(islower(i)) + __ctype_table[i] |= __CTYPE_LOWER_CASE; + + if(isupper(i)) + __ctype_table[i] |= __CTYPE_UPPER_CASE; + + if(isprint(i)) + __ctype_table[i] |= __CTYPE_PRINTABLE; + } + + /* Verify that the table contents match the functional + definitions. */ + for(i = 0 ; i < 128 ; i++) + { + a = ( isalnum(i) != 0); + b = (_isalnum(i) != 0); + + if(a != b) + { + printf("isalnum(%d) %d != %d\n",i,a,b); + abort(); + } + } + + for(i = 0 ; i < 128 ; i++) + { + a = ( isalpha(i) != 0); + b = (_isalpha(i) != 0); + + if(a != b) + { + printf("isalpha(%d) %d != %d\n",i,a,b); + abort(); + } + } + + for(i = 0 ; i < 128 ; i++) + { + a = ( iscntrl(i) != 0); + b = (_iscntrl(i) != 0); + + if(a != b) + { + printf("iscntrl(%d) %d != %d\n",i,a,b); + abort(); + } + } + + for(i = 0 ; i < 128 ; i++) + { + a = ( isdigit(i) != 0); + b = (_isdigit(i) != 0); + + if(a != b) + { + printf("isdigit(%d) %d != %d\n",i,a,b); + abort(); + } + } + + for(i = 0 ; i < 128 ; i++) + { + a = ( isgraph(i) != 0); + b = (_isgraph(i) != 0); + + if(a != b) + { + printf("isgraph(%d) %d != %d\n",i,a,b); + abort(); + } + } + + for(i = 0 ; i < 128 ; i++) + { + a = ( ispunct(i) != 0); + b = (_ispunct(i) != 0); + + if(a != b) + { + printf("ispunct(%d) %d != %d\n",i,a,b); + abort(); + } + } + + for(i = 0 ; i < 128 ; i++) + { + a = ( isprint(i) != 0); + b = (_isprint(i) != 0); + + if(a != b) + { + printf("isprint(%d) %d != %d\n",i,a,b); + abort(); + } + } + + for(i = 0 ; i < 128 ; i++) + { + a = ( islower(i) != 0); + b = (_islower(i) != 0); + + if(a != b) + { + printf("islower(%d) %d != %d\n",i,a,b); + abort(); + } + } + + for(i = 0 ; i < 128 ; i++) + { + a = ( isupper(i) != 0); + b = (_isupper(i) != 0); + + if(a != b) + { + printf("isupper(%d) %d != %d\n",i,a,b); + abort(); + } + } + + for(i = 0 ; i < 128 ; i++) + { + a = ( isspace(i) != 0); + b = (_isspace(i) != 0); + + if(a != b) + { + printf("isspace(%d) %d != %d\n",i,a,b); + abort(); + } + } + + /* If that went well, dump the table as is. */ + dump_table(); + + return(0); +} diff --git a/library/math_acos.c b/library/math_acos.c new file mode 100644 index 0000000..d920ff5 --- /dev/null +++ b/library/math_acos.c @@ -0,0 +1,238 @@ +/* + * $Id: math_acos.c,v 1.1.1.1 2004-07-26 16:30:37 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __acos(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___acos + +___acos: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-120:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__acos(double x) +{ + double result; + + result = IEEEDPAcos(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__acos(double x) +{ + double result; + + __asm ("facos%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +static const double +one= 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ +pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */ +pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */ +pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */ +pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ +pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ +pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ +pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */ +pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */ +pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */ +qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */ +qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */ +qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ +qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ + +INLINE static const double +__acos(double x) +{ + double z,p,q,r,w,s,c,df; + int hx,ix; + + GET_HIGH_WORD(hx,x); + ix = hx&0x7fffffff; + + if(ix>=0x3ff00000) /* |x| >= 1 */ + { + unsigned int lx; + GET_LOW_WORD(lx,x); + if(((ix-0x3ff00000)|lx)==0) /* |x|==1 */ + { + if(hx>0) + return 0.0; /* acos(1) = 0 */ + else + return pi+2.0*pio2_lo; /* acos(-1)= pi */ + } + return (x-x)/(x-x); /* acos(|x|>1) is NaN */ + } + if(ix<0x3fe00000) /* |x| < 0.5 */ + { + if(ix<=0x3c600000) + return pio2_hi+pio2_lo; /*if|x|<2**-57*/ + + z = x*x; + p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); + q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); + r = p/q; + return pio2_hi - (x - (pio2_lo-x*r)); + } + else if (hx<0) /* x < -0.5 */ + { + z = (one+x)*0.5; + p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); + q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); + s = sqrt(z); + r = p/q; + w = r*s-pio2_lo; + return pi - 2.0*(s+w); + } + else /* x > 0.5 */ + { + z = (one-x)*0.5; + s = sqrt(z); + df = s; + SET_LOW_WORD(df,0); + c = (z-df*df)/(s+df); + p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); + q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4))); + r = p/q; + w = r*s+c; + return 2.0*(df+w); + } +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +acos(double x) +{ + double result; + + if(-1.0 <= x && x <= 1.0) + { + result = __acos(x); + } + else + { + result = HUGE_VAL; + errno = EDOM; + } + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_adddf3.c b/library/math_adddf3.c new file mode 100644 index 0000000..6b4a4d5 --- /dev/null +++ b/library/math_adddf3.c @@ -0,0 +1,75 @@ +/* + * $Id: math_adddf3.c,v 1.1.1.1 2004-07-26 16:30:37 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___adddf3 + +___adddf3: + + moveml d2/d3/a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(16),d0/d1/d2/d3 + jsr a6@(-66:W) + moveml sp@+,d2/d3/a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_addsf3.c b/library/math_addsf3.c new file mode 100644 index 0000000..9c6aceb --- /dev/null +++ b/library/math_addsf3.c @@ -0,0 +1,56 @@ +/* + * $Id: math_addsf3.c,v 1.1.1.1 2004-07-26 16:30:38 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +float +__addsf3(float x,float y) +{ + float result; + + result = IEEESPAdd(x,y); + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_asin.c b/library/math_asin.c new file mode 100644 index 0000000..8237047 --- /dev/null +++ b/library/math_asin.c @@ -0,0 +1,249 @@ +/* + * $Id: math_asin.c,v 1.1.1.1 2004-07-26 16:30:38 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +double __asin(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___asin + +___asin: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-114:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__asin(double x) +{ + double result; + + result = IEEEDPAsin(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__asin(double x) +{ + double result; + + __asm ("fasin%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +static const double +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ +huge = 1.000e+300, +pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */ +pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */ +pio4_hi = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */ + /* coefficient for R(x^2) */ +pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ +pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ +pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ +pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */ +pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */ +pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */ +qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */ +qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */ +qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ +qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ + + +INLINE static const double +__asin(double x) +{ + double t,w,p,q,c,r,s; + int hx,ix; + + GET_HIGH_WORD(hx,x); + + ix = hx&0x7fffffff; + + if(ix>= 0x3ff00000) /* |x|>= 1 */ + { + unsigned int lx; + GET_LOW_WORD(lx,x); + + if(((ix-0x3ff00000)|lx)==0) /* asin(1)=+-pi/2 with inexact */ + return x*pio2_hi+x*pio2_lo; + + return (x-x)/(x-x); /* asin(|x|>1) is NaN */ + } + else if (ix<0x3fe00000) /* |x|<0.5 */ + { + if(ix<0x3e400000) /* if |x| < 2**-27 */ + { + if(huge+x>one) + return x; /* return x with inexact if x!=0*/ + } + else + { + t = x*x; + p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); + q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); + w = p/q; + return x+x*w; + } + } + + /* 1> |x|>= 0.5 */ + w = one-fabs(x); + t = w*0.5; + p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5))))); + q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4))); + s = sqrt(t); + + if(ix>=0x3FEF3333) /* if |x| > 0.975 */ + { + w = p/q; + t = pio2_hi-(2.0*(s+s*w)-pio2_lo); + } + else + { + w = s; + SET_LOW_WORD(w,0); + c = (t-w*w)/(s+w); + r = p/q; + p = 2.0*s*r-(pio2_lo-2.0*c); + q = pio4_hi-2.0*w; + t = pio4_hi-(p-q); + } + + if(hx>0) + return t; + else + return -t; +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +asin(double x) +{ + double result; + + if(-1.0 <= x && x <= 1.0) + { + result = __asin(x); + } + else + { + result = HUGE_VAL; + errno = EDOM; + } + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_atan.c b/library/math_atan.c new file mode 100644 index 0000000..1b34cb7 --- /dev/null +++ b/library/math_atan.c @@ -0,0 +1,273 @@ +/* + * $Id: math_atan.c,v 1.1.1.1 2004-07-26 16:30:38 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __atan(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___atan + +___atan: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-30:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__atan(double x) +{ + double result; + + result = IEEEDPAtan(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__atan(double x) +{ + double result; + + __asm ("fatan%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +static const double atanhi[] = { + 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */ + 7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */ + 9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */ + 1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */ +}; + +static const double atanlo[] = { + 2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */ + 3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */ + 1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */ + 6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */ +}; + +static const double aT[] = { + 3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */ + -1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */ + 1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */ + -1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */ + 9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */ + -7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */ + 6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */ + -5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */ + 4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */ + -3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */ + 1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */ +}; + +static const double +one = 1.0, +huge = 1.0e300; + +INLINE static const double +__atan(double x) +{ + double w,s1,s2,z; + int ix,hx,id; + + GET_HIGH_WORD(hx,x); + + ix = hx&0x7fffffff; + + if(ix>=0x44100000) /* if |x| >= 2^66 */ + { + unsigned int low; + + GET_LOW_WORD(low,x); + + if(ix>0x7ff00000|| (ix==0x7ff00000&&(low!=0))) + return x+x; /* NaN */ + + if(hx>0) + return atanhi[3]+atanlo[3]; + else + return -atanhi[3]-atanlo[3]; + } + + if (ix < 0x3fdc0000) /* |x| < 0.4375 */ + { + if (ix < 0x3e200000) /* |x| < 2^-29 */ + { + if(huge+x>one) + return x; /* raise inexact */ + } + id = -1; + } + else + { + x = fabs(x); + if (ix < 0x3ff30000) /* |x| < 1.1875 */ + { + if (ix < 0x3fe60000) /* 7/16 <=|x|<11/16 */ + { + id = 0; + x = (2.0*x-one)/(2.0+x); + } + else /* 11/16<=|x|< 19/16 */ + { + id = 1; + x = (x-one)/(x+one); + } + } + else + { + if (ix < 0x40038000) /* |x| < 2.4375 */ + { + id = 2; + x = (x-1.5)/(one+1.5*x); + } + else /* 2.4375 <= |x| < 2^66 */ + { + id = 3; + x = -1.0/x; + } + } + } + + /* end of argument reduction */ + z = x*x; + w = z*z; + + /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ + s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10]))))); + s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9])))); + + if (id<0) + { + return x - x*(s1+s2); + } + else + { + z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x); + return (hx<0)? -z:z; + } +} + +#endif /* PPC_FLOATIN_POINT_SUPPORT */ + + +/****************************************************************************/ + +double +atan(double x) +{ + double result; + + result = __atan(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_atan2.c b/library/math_atan2.c new file mode 100644 index 0000000..00a8ae7 --- /dev/null +++ b/library/math_atan2.c @@ -0,0 +1,344 @@ +/* + * $Id: math_atan2.c,v 1.1.1.1 2004-07-26 16:30:39 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) +extern double __atan(double x); +#else +#define __atan(x) IEEEDPAtan(x) +#endif /* __GNUC__ */ + +/****************************************************************************/ + +INLINE static const double +__atan2(double x,double y) +{ + const double pi = 3.14159265358979323846; + const double pi_over_2 = pi / 2.0; + double result; + + if(x > 0.0) + { + if(y > 0.0) + { + if(x > y) + result = __atan(y / x); + else + result = pi_over_2 - __atan(x / y); + } + else + { + if(x > -y) + result = __atan(y / x); + else + result = -(pi_over_2 + __atan(x / y)); + } + } + else + { + if(y > 0.0) + { + if((-x) > y) + result = pi + __atan (y / x); + else + result = pi_over_2 - __atan(x / y); + } + else + { + if((-x) > (-y)) + { + result = -(pi - __atan(y / x)); + } + else if (y < 0.0) + { + result = -(pi_over_2 + __atan(x / y)); + } + else + { + result = HUGE_VAL; + errno = EDOM; + } + } + } + + return(result); +} + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__atan(double x) +{ + double result; + + __asm ("fatan%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +INLINE static const double +__atan2(double x,double y) +{ + double pi,pi_over_2; + double result; + + __asm ("fmovecr%.x %#0,%0" /* extended precision pi */ + : "=f" (pi) + : /* no inputs */ ); + + __asm ("fscale%.b %#-1,%0" /* no loss of accuracy */ + : "=f" (pi_over_2) + : "0" (pi)); + + if(x > 0.0) + { + if(y > 0.0) + { + if(x > y) + result = __atan(y / x); + else + result = pi_over_2 - __atan(x / y); + } + else + { + if(x > -y) + result = __atan(y / x); + else + result = -(pi_over_2 + __atan(x / y)); + } + } + else + { + if(y > 0.0) + { + if((-x) > y) + result = pi + __atan (y / x); + else + result = pi_over_2 - __atan(x / y); + } + else + { + if((-x) > (-y)) + { + result = -(pi - __atan(y / x)); + } + else if (y < 0.0) + { + result = -(pi_over_2 + __atan(x / y)); + } + else + { + result = HUGE_VAL; + errno = EDOM; + } + } + } + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + + + + +static const double +tiny = 1.0e-300, +zero = 0.0, +pi_o_4 = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */ +pi_o_2 = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */ +pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */ +pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */ + +INLINE static const double +__atan2(double x,double y) +{ + double z; + int k,m,hx,hy,ix,iy; + unsigned int lx,ly; + + EXTRACT_WORDS(hx,lx,x); + ix = hx&0x7fffffff; + + EXTRACT_WORDS(hy,ly,y); + iy = hy&0x7fffffff; + + if( ((ix|((lx|-lx)>>31))>0x7ff00000) || ((iy|((ly|-ly)>>31))>0x7ff00000) ) /* x or y is NaN */ + return x+y; + + if((hx-0x3ff00000|lx)==0) + return atan(y); /* x=1.0 */ + + m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */ + + /* when y = 0 */ + if((iy|ly)==0) + { + switch(m) + { + case 0: + case 1: + return y; /* atan(+-0,+anything)=+-0 */ + case 2: + return pi+tiny; /* atan(+0,-anything) = pi */ + case 3: + return -pi-tiny; /* atan(-0,-anything) =-pi */ + } + } + + /* when x = 0 */ + if((ix|lx)==0) + return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; + + /* when x is INF */ + if(ix==0x7ff00000) + { + if(iy==0x7ff00000) + { + switch(m) + { + case 0: + return pi_o_4+tiny; /* atan(+INF,+INF) */ + case 1: + return -pi_o_4-tiny; /* atan(-INF,+INF) */ + case 2: + return 3.0*pi_o_4+tiny; /*atan(+INF,-INF)*/ + case 3: + return -3.0*pi_o_4-tiny; /*atan(-INF,-INF)*/ + } + } + else + { + switch(m) + { + case 0: + return zero ; /* atan(+...,+INF) */ + case 1: + return -zero ; /* atan(-...,+INF) */ + case 2: + return pi+tiny ; /* atan(+...,-INF) */ + case 3: + return -pi-tiny ; /* atan(-...,-INF) */ + } + } + } + + /* when y is INF */ + if(iy==0x7ff00000) + return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; + + /* compute y/x */ + k = (iy-ix)>>20; + if(k > 60) + z=pi_o_2+0.5*pi_lo; /* |y/x| > 2**60 */ + else + if(hx<0&&k<-60) + z=0.0; /* |y|/x < -2**60 */ + else + z=atan(fabs(y/x)); /* safe to do y/x */ + + switch (m) + { + case 0: + return z; /* atan(+,+) */ + case 1: + { + unsigned int zh; + GET_HIGH_WORD(zh,z); + SET_HIGH_WORD(z,zh ^ 0x80000000); + } + return z; /* atan(-,+) */ + case 2: + return pi-(z-pi_lo); /* atan(+,-) */ + default: + return (z-pi_lo)-pi; /* atan(-,-) */ + } +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +atan2(double x,double y) +{ + double result; + + if(x != 0.0 && y != 0.0) + { + result = __atan2(x,y); + } + else + { + result = HUGE_VAL; + errno = EDOM; + } + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_ceil.c b/library/math_ceil.c new file mode 100644 index 0000000..3da9c5f --- /dev/null +++ b/library/math_ceil.c @@ -0,0 +1,250 @@ +/* + * $Id: math_ceil.c,v 1.1.1.1 2004-07-26 16:30:39 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __ceil(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___ceil + +___ceil: + + movel a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-96:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__ceil(double x) +{ + double result; + + result = IEEEDPCeil(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__ceil(double x) +{ + int rounding_mode, round_up; + double result; + + __asm __volatile ("fmove%.l fpcr,%0" + : "=dm" (rounding_mode) + : /* no inputs */ ); + + round_up = rounding_mode | 0x30; + + __asm __volatile ("fmove%.l %0,fpcr" + : /* no outputs */ + : "dmi" (round_up)); + __asm __volatile ("fint%.x %1,%0" + : "=f" (result) + : "f" (x)); + __asm __volatile ("fmove%.l %0,fpcr" + : /* no outputs */ + : "dmi" (rounding_mode)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + + +static const double huge = 1.0e300; + +INLINE static const double +__ceil(double x) +{ + int i0,i1,j0; + unsigned int i,j; + + EXTRACT_WORDS(i0,i1,x); + + j0 = ((i0>>20)&0x7ff)-0x3ff; + + if(j0<20) + { + if(j0<0) + { + if(huge+x>0.0) + { + if(i0<0) + { + i0=0x80000000; + i1=0; + } + else if((i0|i1)!=0) + { + i0=0x3ff00000; + i1=0; + } + } + } + else + { + i = (0x000fffff)>>j0; + if(((i0&i)|i1)==0) + return x; + if(huge+x>0.0) + { + if(i0>0) + i0 += (0x00100000)>>j0; + i0 &= (~i); i1=0; + } + } + } + else if (j0>51) + { + if(j0==0x400) + return x+x; + else + return x; + } + else + { + i = ((unsigned int)(0xffffffff))>>(j0-20); + + if((i1&i)==0) + return x; + + if(huge+x>0.0) + { + + if(i0>0) + { + if(j0==20) + i0+=1; + else + { + j = i1 + (1<<(52-j0)); + if(j + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __cos(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___cos + +___cos: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-42:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__cos(double x) +{ + double result; + + result = IEEEDPCos(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__cos(double x) +{ + double result; + + __asm ("fcos%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +INLINE static const double +__cos(double x) +{ + double y[2],z=0.0; + int n,ix; + + /* High word of x. */ + GET_HIGH_WORD(ix,x); + + /* |x| ~< pi/4 */ + ix &= 0x7fffffff; + if(ix <= 0x3fe921fb) + return __kernel_cos(x,z); + + /* cos(Inf or NaN) is NaN */ + else if (ix>=0x7ff00000) + return x-x; + + /* argument reduction needed */ + else + { + n = __rem_pio2(x,y); + switch(n&3) + { + case 0: + return __kernel_cos(y[0],y[1]); + case 1: + return -__kernel_sin(y[0],y[1],1); + case 2: + return -__kernel_cos(y[0],y[1]); + default: + return __kernel_sin(y[0],y[1],1); + } + } +} +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +cos(double x) +{ + double result; + + result = __cos(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_cosh.c b/library/math_cosh.c new file mode 100644 index 0000000..3542763 --- /dev/null +++ b/library/math_cosh.c @@ -0,0 +1,207 @@ +/* + * $Id: math_cosh.c,v 1.1.1.1 2004-07-26 16:30:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __cosh(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___cosh + +___cosh: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-66:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__cosh(double x) +{ + double result; + + result = IEEEDPCosh(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__cosh(double x) +{ + double result; + + __asm ("fcosh%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +static const double one = 1.0, half=0.5, huge = 1.0e300; + +INLINE static const double +__cosh(double x) +{ + double t,w; + int ix; + unsigned int lx; + + /* High word of |x|. */ + GET_HIGH_WORD(ix,x); + ix &= 0x7fffffff; + + /* x is INF or NaN */ + if(ix>=0x7ff00000) + return x*x; + + /* |x| in [0,0.5*ln2], return 1+__expm1(|x|)^2/(2*exp(|x|)) */ + if(ix<0x3fd62e43) + { + t = __expm1(fabs(x)); + w = one+t; + if (ix<0x3c800000) + return w; /* cosh(tiny) = 1 */ + return one+(t*t)/(w+w); + } + + /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */ + if (ix < 0x40360000) + { + t = exp(fabs(x)); + return half*t+half/t; + } + + /* |x| in [22, log(maxdouble)] return half*exp(|x|) */ + if (ix < 0x40862E42) + return half*exp(fabs(x)); + + /* |x| in [log(maxdouble), overflowthresold] */ + GET_LOW_WORD(lx,x); + if (ix<0x408633CE || (ix==0x408633ce && lx<=(unsigned int)0x8fb9f87d)) + { + w = exp(half*fabs(x)); + t = half*w; + return t*w; + } + + /* |x| > overflowthresold, cosh(x) overflow */ + return huge*huge; +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +cosh(double x) +{ + double result; + + result = __cosh(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_data.c b/library/math_data.c new file mode 100644 index 0000000..c946510 --- /dev/null +++ b/library/math_data.c @@ -0,0 +1,50 @@ +/* + * $Id: math_data.c,v 1.1.1.1 2004-07-26 16:30:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +struct Library * MathIeeeSingBasBase; +struct Library * MathIeeeDoubBasBase; +struct Library * MathIeeeDoubTransBase; + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double __huge_val; diff --git a/library/math_divdf3.c b/library/math_divdf3.c new file mode 100644 index 0000000..d6ee80a --- /dev/null +++ b/library/math_divdf3.c @@ -0,0 +1,75 @@ +/* + * $Id: math_divdf3.c,v 1.1.1.1 2004-07-26 16:30:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___divdf3 + +___divdf3: + + moveml d2/d3/a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(16),d0/d1/d2/d3 + jsr a6@(-84:W) + moveml sp@+,d2/d3/a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_divsf3.c b/library/math_divsf3.c new file mode 100644 index 0000000..4c721bb --- /dev/null +++ b/library/math_divsf3.c @@ -0,0 +1,56 @@ +/* + * $Id: math_divsf3.c,v 1.1.1.1 2004-07-26 16:30:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +float +__divsf3(float x,float y) +{ + float result; + + result = IEEESPDiv(x,y); + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_eqdf2.c b/library/math_eqdf2.c new file mode 100644 index 0000000..d72941f --- /dev/null +++ b/library/math_eqdf2.c @@ -0,0 +1,75 @@ +/* + * $Id: math_eqdf2.c,v 1.1.1.1 2004-07-26 16:30:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___eqdf2 + +___eqdf2: + + moveml d2/d3/a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(16),d0/d1/d2/d3 + jsr a6@(-42:W) + moveml sp@+,d2/d3/a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_eqsf2.c b/library/math_eqsf2.c new file mode 100644 index 0000000..39b1ed9 --- /dev/null +++ b/library/math_eqsf2.c @@ -0,0 +1,56 @@ +/* + * $Id: math_eqsf2.c,v 1.1.1.1 2004-07-26 16:30:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +float +__eqsf2(float x,float y) +{ + float result; + + result = IEEESPCmp(x,y); + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_exp.c b/library/math_exp.c new file mode 100644 index 0000000..a6bdf67 --- /dev/null +++ b/library/math_exp.c @@ -0,0 +1,252 @@ +/* + * $Id: math_exp.c,v 1.1.1.1 2004-07-26 16:30:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __exp(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___exp + +___exp: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-78:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__exp(double x) +{ + double result; + + result = IEEEDPExp(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__exp(double x) +{ + double result; + + __asm ("fetox%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +static const double +one = 1.0, +halF[2] = {0.5,-0.5,}, +huge = 1.0e+300, +twom1000= 9.33263618503218878990e-302, /* 2**-1000=0x01700000,0*/ +o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */ +u_threshold= -7.45133219101941108420e+02, /* 0xc0874910, 0xD52D3051 */ +ln2HI[2] ={ 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ + -6.93147180369123816490e-01,}, /* 0xbfe62e42, 0xfee00000 */ +ln2LO[2] ={ 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */ + -1.90821492927058770002e-10,}, /* 0xbdea39ef, 0x35793c76 */ +invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */ +P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ +P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ +P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ +P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ +P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ + +INLINE static const double +__exp(double x) +{ + double y,hi,lo,c,t; + int k,xsb; + unsigned int hx; + + GET_HIGH_WORD(hx,x); + xsb = (hx>>31)&1; /* sign bit of x */ + hx &= 0x7fffffff; /* high word of |x| */ + + /* filter out non-finite argument */ + if(hx >= 0x40862E42) + { /* if |x|>=709.78... */ + if(hx>=0x7ff00000) + { + unsigned int lx; + + GET_LOW_WORD(lx,x); + if(((hx&0xfffff)|lx)!=0) + return x+x; /* NaN */ + else + return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */ + } + if(x > o_threshold) + return huge*huge; /* overflow */ + if(x < u_threshold) + return twom1000*twom1000; /* underflow */ + } + + /* argument reduction */ + if(hx > 0x3fd62e42) + { /* if |x| > 0.5 ln2 */ + if(hx < 0x3FF0A2B2) + { /* and |x| < 1.5 ln2 */ + hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb; + } + else + { + k = invln2*x+halF[xsb]; + t = k; + hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */ + lo = t*ln2LO[0]; + } + x = hi - lo; + } + else if(hx < 0x3e300000) + { /* when |x|<2**-28 */ + if(huge+x>one) + return one+x; /* trigger inexact */ + } + else + k = 0; + + /* x is now in primary range */ + t = x*x; + c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); + if(k==0) + return one-((x*c)/(c-2.0)-x); + else + y = one-((lo-(x*c)/(2.0-c))-hi); + + if(k >= -1021) + { + unsigned int hy; + GET_HIGH_WORD(hy,y); + SET_HIGH_WORD(y,hy+(k<<20)); /* add k to y's exponent */ + return y; + } + else + { + unsigned int hy; + GET_HIGH_WORD(hy,y); + SET_HIGH_WORD(y,hy+((k+1000)<<20)); /* add k to y's exponent */ + return y*twom1000; + } +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +exp(double x) +{ + double result; + + result = __exp(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_extendsfdf2.c b/library/math_extendsfdf2.c new file mode 100644 index 0000000..8e6f972 --- /dev/null +++ b/library/math_extendsfdf2.c @@ -0,0 +1,75 @@ +/* + * $Id: math_extendsfdf2.c,v 1.1.1.1 2004-07-26 16:30:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___extendsfdf2 + +___extendsfdf2: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + movel sp@(8),d0 + jsr a6@(-108:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_fabs.c b/library/math_fabs.c new file mode 100644 index 0000000..ce10d23 --- /dev/null +++ b/library/math_fabs.c @@ -0,0 +1,160 @@ +/* + * $Id: math_fabs.c,v 1.1.1.1 2004-07-26 16:30:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __fabs(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___fabs + +___fabs: + + movel a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-54:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__fabs(double x) +{ + double result; + + result = IEEEDPAbs(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__fabs(double x) +{ + double result; + + __asm ("fabs%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +INLINE static const double +__fabs(double x) +{ + double res; + + __asm volatile ("fabs %0, %1" + : "=f" (res) + : "f" (x)); + + return res; + +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +fabs(double x) +{ + double result; + + result = __fabs(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_fixdfsi.c b/library/math_fixdfsi.c new file mode 100644 index 0000000..37ddba0 --- /dev/null +++ b/library/math_fixdfsi.c @@ -0,0 +1,75 @@ +/* + * $Id: math_fixdfsi.c,v 1.1.1.1 2004-07-26 16:30:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___fixdfsi + +___fixdfsi: + + movel a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-30:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_fixsfsi.c b/library/math_fixsfsi.c new file mode 100644 index 0000000..b80136e --- /dev/null +++ b/library/math_fixsfsi.c @@ -0,0 +1,56 @@ +/* + * $Id: math_fixsfsi.c,v 1.1.1.1 2004-07-26 16:30:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +signed long +__fixsfsi(float x) +{ + signed long result; + + result = IEEESPFix(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_fixunsdfsi.c b/library/math_fixunsdfsi.c new file mode 100644 index 0000000..3bf7ab5 --- /dev/null +++ b/library/math_fixunsdfsi.c @@ -0,0 +1,61 @@ +/* + * $Id: math_fixunsdfsi.c,v 1.1.1.1 2004-07-26 16:30:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +unsigned long +__fixunsdfsi(double x) +{ + signed long result; + + if(x < 0.0) + result = 0; + else if (x >= 0x80000000UL) + result = (signed long)(x - 0x80000000UL) + 0x80000000UL; + else + result = (signed long)x; + + return((unsigned long)result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_fixunssfsi.c b/library/math_fixunssfsi.c new file mode 100644 index 0000000..0bc3d86 --- /dev/null +++ b/library/math_fixunssfsi.c @@ -0,0 +1,61 @@ +/* + * $Id: math_fixunssfsi.c,v 1.1.1.1 2004-07-26 16:30:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +unsigned long +__fixunssfsi(float x) +{ + signed long result; + + if(x < 0.0) + result = 0; + else if (x >= 0x80000000UL) + result = (signed long)(x - 0x80000000UL) + 0x80000000UL; + else + result = (signed long)x; + + return((unsigned long)result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_floatsidf.c b/library/math_floatsidf.c new file mode 100644 index 0000000..172dc90 --- /dev/null +++ b/library/math_floatsidf.c @@ -0,0 +1,75 @@ +/* + * $Id: math_floatsidf.c,v 1.1.1.1 2004-07-26 16:30:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___floatsidf + +___floatsidf: + + movel a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + movel sp@(8),d0 + jsr a6@(-36:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_floatsisf.c b/library/math_floatsisf.c new file mode 100644 index 0000000..b4b06ca --- /dev/null +++ b/library/math_floatsisf.c @@ -0,0 +1,56 @@ +/* + * $Id: math_floatsisf.c,v 1.1.1.1 2004-07-26 16:30:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +float +__floatsisf(signed long x) +{ + float result; + + result = IEEESPFlt(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_floor.c b/library/math_floor.c new file mode 100644 index 0000000..df66505 --- /dev/null +++ b/library/math_floor.c @@ -0,0 +1,250 @@ +/* + * $Id: math_floor.c,v 1.1.1.1 2004-07-26 16:30:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __floor(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___floor + +___floor: + + movel a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-90:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__floor(double x) +{ + double result; + + result = IEEEDPFloor(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__floor(double x) +{ + int rounding_mode, round_down; + double result; + + __asm __volatile ("fmove%.l fpcr,%0" + : "=dm" (rounding_mode) + : /* no inputs */ ); + + round_down = (rounding_mode & ~0x10) | 0x20; + + __asm __volatile ("fmove%.l %0,fpcr" + : /* no outputs */ + : "dmi" (round_down)); + + __asm __volatile ("fint%.x %1,%0" + : "=f" (result) + : "f" (x)); + + __asm __volatile ("fmove%.l %0,fpcr" + : /* no outputs */ + : "dmi" (rounding_mode)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +static const double huge = 1.0e300; +INLINE static const double +__floor(double x) +{ + int i0,i1,j0; + unsigned int i,j; + + EXTRACT_WORDS(i0,i1,x); + + j0 = ((i0>>20)&0x7ff)-0x3ff; + + if(j0<20) + { + if(j0<0) + { + if(huge+x>0.0) + { + if(i0>=0) + { + i0=i1=0; + } + else if(((i0&0x7fffffff)|i1)!=0) + { + i0=0xbff00000; + i1=0; + } + } + } + else + { + i = (0x000fffff)>>j0; + + if(((i0&i)|i1)==0) + return x; + + if(huge+x>0.0) + { + if(i0<0) + i0 += (0x00100000)>>j0; + i0 &= (~i); i1=0; + } + } + } + else if (j0>51) + { + if(j0==0x400) + return x+x; + else + return x; + } + else + { + i = ((unsigned int)(0xffffffff))>>(j0-20); + + if((i1&i)==0) + return x; + + if(huge+x>0.0) + { + if(i0<0) + { + if(j0==20) + i0+=1; + else + { + j = i1+(1<<(52-j0)); + if(j + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +INLINE static const double +__fmod(double x,double y) +{ + double q,p,result; + + q = x / y; + + if(q < 0.0) + p = ceil(q) - q; + else + p = q - floor(q); + + result = p * y; + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__fmod(double x,double y) +{ + double result; + + __asm ("fmod%.x %2,%0" + : "=f" (result) + : "0" (x), + "f" (y)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +static const double +one = 1.0, +Zero[] = {0.0, -0.0,}; + +INLINE static const double +__fmod(double x,double y) +{ + int n,hx,hy,hz,ix,iy,sx,i; + unsigned int lx,ly,lz; + + EXTRACT_WORDS(hx,lx,x); + EXTRACT_WORDS(hy,ly,y); + + sx = hx&0x80000000; /* sign of x */ + hx ^=sx; /* |x| */ + hy &= 0x7fffffff; /* |y| */ + + /* purge off exception values */ + if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */ + ((hy|((ly|-ly)>>31))>0x7ff00000)) /* or y is NaN */ + return (x*y)/(x*y); + if(hx<=hy) + { + if((hx>31]; /* |x|=|y| return x*0*/ + } + + /* determine ix = ilogb(x) */ + if(hx<0x00100000) /* subnormal x */ + { + if(hx==0) + { + for (ix = -1043, i=lx; i>0; i<<=1) + ix -=1; + } + else + { + for (ix = -1022,i=(hx<<11); i>0; i<<=1) + ix -=1; + } + } + else + ix = (hx>>20)-1023; + + /* determine iy = ilogb(y) */ + if(hy<0x00100000) /* subnormal y */ + { + if(hy==0) + { + for (iy = -1043, i=ly; i>0; i<<=1) + iy -=1; + } + else + { + for (iy = -1022,i=(hy<<11); i>0; i<<=1) + iy -=1; + } + } + else + iy = (hy>>20)-1023; + + /* set up {hx,lx}, {hy,ly} and align y to x */ + if(ix >= -1022) + hx = 0x00100000|(0x000fffff&hx); + else /* subnormal x, shift x to normal */ + { + n = -1022-ix; + if(n<=31) + { + hx = (hx<>(32-n)); + lx <<= n; + } + else + { + hx = lx<<(n-32); + lx = 0; + } + } + + if(iy >= -1022) + hy = 0x00100000|(0x000fffff&hy); + else /* subnormal y, shift y to normal */ + { + n = -1022-iy; + if(n<=31) + { + hy = (hy<>(32-n)); + ly <<= n; + } + else + { + hy = ly<<(n-32); + ly = 0; + } + } + + /* fix point fmod */ + n = ix - iy; + while(n--) + { + hz=hx-hy;lz=lx-ly; + if(lx>31); + lx = lx+lx; + } + else + { + if((hz|lz)==0) /* return sign(x)*0 */ + return Zero[(unsigned int)sx>>31]; + hx = hz+hz+(lz>>31); + lx = lz+lz; + } + } + + hz=hx-hy; + lz=lx-ly; + + if(lx=0) + { + hx=hz; + lx=lz; + } + + /* convert back to floating value and restore the sign */ + if((hx|lx)==0) /* return sign(x)*0 */ + return Zero[(unsigned int)sx>>31]; + while(hx<0x00100000) /* normalize x */ + { + hx = hx+hx+(lx>>31); + lx = lx+lx; + iy -= 1; + } + + if(iy>= -1022) /* normalize output */ + { + hx = ((hx-0x00100000)|((iy+1023)<<20)); + INSERT_WORDS(x,hx|sx,lx); + } + else + { /* subnormal output */ + n = -1022 - iy; + if(n<=20) + { + lx = (lx>>n)|((unsigned int)hx<<(32-n)); + hx >>= n; + } + else + if (n<=31) + { + lx = (hx<<(32-n))|(lx>>n); + hx = sx; + } + else + { + lx = hx>>(n-32); hx = sx; + } + + INSERT_WORDS(x,hx|sx,lx); + x *= one; /* create necessary signal */ + } + return x; /* exact output */ +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +fmod(double x,double y) +{ + double result; + + if(y != 0.0) + { + result = __fmod(x,y); + } + else + { + result = HUGE_VAL; + errno = EDOM; + } + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_fp_support.h b/library/math_fp_support.h new file mode 100644 index 0000000..0357493 --- /dev/null +++ b/library/math_fp_support.h @@ -0,0 +1,45 @@ +/* + * $Id: math_fp_support.h,v 1.1.1.1 2004-07-26 16:30:44 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_FP_SUPPORT_H +#define _MATH_FP_SUPPORT_H + +/****************************************************************************/ + +#if (defined(IEEE_FLOATING_POINT_SUPPORT) || defined(M68881_FLOATING_POINT_SUPPORT) || defined(PPC_FLOATING_POINT_SUPPORT)) +#define FLOATING_POINT_SUPPORT +#endif + +/****************************************************************************/ + +#endif /* _MATH_FP_SUPPORT_H */ diff --git a/library/math_frexp.c b/library/math_frexp.c new file mode 100644 index 0000000..bce35e6 --- /dev/null +++ b/library/math_frexp.c @@ -0,0 +1,217 @@ +/* + * $Id: math_frexp.c,v 1.1.1.1 2004-07-26 16:30:44 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +INLINE static const double +__frexp(double x,int * nptr) +{ + int int_exponent = 0; + BOOL is_negative; + + if(x < 0) + { + is_negative = TRUE; + + x = (-x); + } + else + { + is_negative = FALSE; + } + + if(x >= 1) + { + while(x >= 1) + { + int_exponent++; + x /= 2; + } + } + else if (0 < x && x < 0.5) + { + while(x < 0.5) + { + int_exponent--; + x *= 2; + } + } + + (*nptr) = int_exponent; + + if(is_negative) + x = (-x); + + return(x); +} + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__frexp(double x,int * nptr) +{ + double float_exponent; + int int_exponent; + double mantissa; + + __asm ("fgetexp%.x %1,%0" + : "=f" (float_exponent) /* integer-valued float */ + : "f" (x)); + + int_exponent = (int)float_exponent; + + __asm ("fgetman%.x %1,%0" + : "=f" (mantissa) /* 1.0 <= mantissa < 2.0 */ + : "f" (x)); + + if (mantissa != 0) + { + __asm ("fscale%.b %#-1,%0" + : "=f" (mantissa) /* mantissa /= 2.0 */ + : "0" (mantissa)); + + int_exponent += 1; + } + + (*nptr) = int_exponent; + + return(mantissa); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +static const double +two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */ + +INLINE static const double +__frexp(double x,int * eptr) +{ + int hx, ix, lx; + + EXTRACT_WORDS(hx,lx,x); + + ix = 0x7fffffff&hx; + *eptr = 0; + + if(ix>=0x7ff00000||((ix|lx)==0)) + return x; /* 0,inf,nan */ + if (ix<0x00100000) /* subnormal */ + { + x *= two54; + GET_HIGH_WORD(hx,x); + ix = hx&0x7fffffff; + *eptr = -54; + } + + *eptr += (ix>>20)-1022; + + hx = (hx&0x800fffff)|0x3fe00000; + SET_HIGH_WORD(x,hx); + + return x; +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +frexp(double x,int *nptr) +{ + double result; + + assert( nptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(nptr == NULL) + { + result = HUGE_VAL; + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(x != 0.0) + { + result = __frexp(x,nptr); + } + else + { + result = 0.0; + + (*nptr) = 0; + } + + out: + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_gedf2.c b/library/math_gedf2.c new file mode 100644 index 0000000..11cb360 --- /dev/null +++ b/library/math_gedf2.c @@ -0,0 +1,75 @@ +/* + * $Id: math_gedf2.c,v 1.1.1.1 2004-07-26 16:30:44 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___gedf2 + +___gedf2: + + moveml d2/d3/a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(16),d0/d1/d2/d3 + jsr a6@(-42:W) + moveml sp@+,d2/d3/a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_gesf2.c b/library/math_gesf2.c new file mode 100644 index 0000000..8597eab --- /dev/null +++ b/library/math_gesf2.c @@ -0,0 +1,56 @@ +/* + * $Id: math_gesf2.c,v 1.1.1.1 2004-07-26 16:30:44 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +float +__gesf2(float x,float y) +{ + float result; + + result = IEEESPCmp(x,y); + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_gtdf2.c b/library/math_gtdf2.c new file mode 100644 index 0000000..d00f30f --- /dev/null +++ b/library/math_gtdf2.c @@ -0,0 +1,75 @@ +/* + * $Id: math_gtdf2.c,v 1.1.1.1 2004-07-26 16:30:45 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___gtdf2 + +___gtdf2: + + moveml d2/d3/a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(16),d0/d1/d2/d3 + jsr a6@(-42:W) + moveml sp@+,d2/d3/a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_gtsf2.c b/library/math_gtsf2.c new file mode 100644 index 0000000..6d18a72 --- /dev/null +++ b/library/math_gtsf2.c @@ -0,0 +1,56 @@ +/* + * $Id: math_gtsf2.c,v 1.1.1.1 2004-07-26 16:30:45 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +float +__gtsf2(float x,float y) +{ + float result; + + result = IEEESPCmp(x,y); + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_headers.h b/library/math_headers.h new file mode 100644 index 0000000..7cd574b --- /dev/null +++ b/library/math_headers.h @@ -0,0 +1,167 @@ +/* + * $Id: math_headers.h,v 1.1.1.1 2004-07-26 16:30:45 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#define _MATH_HEADERS_H + +/****************************************************************************/ + +#include +#include +#include + +/****************************************************************************/ + +#include "macros.h" +#include "debug.h" + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#include +#include +#include + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +#define FLT_UWORD_IS_ZERO(x) ((x)==0) +#define FLT_UWORD_IS_SUBNORMAL(x) ((x)<0x00800000L) +#define FLT_UWORD_MIN 0x00000001 +#define FLT_UWORD_EXP_MIN 0x43160000 +#define FLT_UWORD_LOG_MIN 0x42cff1b5 +#define FLT_SMALLEST_EXP -22 + +typedef union +{ + double value; + struct + { + unsigned int msw; + unsigned int lsw; + } parts; +} ieee_double_shape_type; + +#define EXTRACT_WORDS(ix0,ix1,d) \ +do { \ + ieee_double_shape_type ew_u; \ + ew_u.value = (d); \ + (ix0) = ew_u.parts.msw; \ + (ix1) = ew_u.parts.lsw; \ +} while (0) + +/* Get the more significant 32 bit int from a double. */ + +#define GET_HIGH_WORD(i,d) \ +do { \ + ieee_double_shape_type gh_u; \ + gh_u.value = (d); \ + (i) = gh_u.parts.msw; \ +} while (0) + +/* Get the less significant 32 bit int from a double. */ + +#define GET_LOW_WORD(i,d) \ +do { \ + ieee_double_shape_type gl_u; \ + gl_u.value = (d); \ + (i) = gl_u.parts.lsw; \ +} while (0) + +/* Set a double from two 32 bit ints. */ + +#define INSERT_WORDS(d,ix0,ix1) \ +do { \ + ieee_double_shape_type iw_u; \ + iw_u.parts.msw = (ix0); \ + iw_u.parts.lsw = (ix1); \ + (d) = iw_u.value; \ +} while (0) + +/* Set the more significant 32 bits of a double from an int. */ + +#define SET_HIGH_WORD(d,v) \ +do { \ + ieee_double_shape_type sh_u; \ + sh_u.value = (d); \ + sh_u.parts.msw = (v); \ + (d) = sh_u.value; \ +} while (0) + +/* Set the less significant 32 bits of a double from an int. */ + +#define SET_LOW_WORD(d,v) \ +do { \ + ieee_double_shape_type sl_u; \ + sl_u.value = (d); \ + sl_u.parts.lsw = (v); \ + (d) = sl_u.value; \ +} while (0) + +extern double __kernel_cos(double x, double y); +extern double __kernel_sin(double x, double y, int iy); +extern int __rem_pio2(double x, double *y); +extern double __kernel_tan(double x, double y, int iy); +extern double __expm1(double x); +extern double __scalbn(double x, int n); + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#ifndef _MATH_FP_SUPPORT_H +#include "math_fp_support.h" +#endif /* _MATH_FP_SUPPORT_H */ + +/****************************************************************************/ + +#endif /* _MATH_HEADERS_H */ diff --git a/library/math_init_exit.c b/library/math_init_exit.c new file mode 100644 index 0000000..b81facd --- /dev/null +++ b/library/math_init_exit.c @@ -0,0 +1,169 @@ +/* + * $Id: math_init_exit.c,v 1.1.1.1 2004-07-26 16:30:46 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#include "stdlib_protos.h" + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +void +__math_exit(void) +{ + #if defined(IEEE_FLOATING_POINT_SUPPORT) + { + if(MathIeeeSingBasBase != NULL) + { + CloseLibrary(MathIeeeSingBasBase); + MathIeeeSingBasBase = NULL; + } + + if(MathIeeeDoubBasBase != NULL) + { + CloseLibrary(MathIeeeDoubBasBase); + MathIeeeDoubBasBase = NULL; + } + + if(MathIeeeDoubTransBase != NULL) + { + CloseLibrary(MathIeeeDoubTransBase); + MathIeeeDoubTransBase = NULL; + } + } + #endif /* IEEE_FLOATING_POINT_SUPPORT */ +} + +/****************************************************************************/ + +int +__math_init(void) +{ + int result = ERROR; + + #if defined(IEEE_FLOATING_POINT_SUPPORT) + { + char * failed_library = NULL; + + PROFILE_OFF(); + + /* Try to get the soft floating point libraries open. */ + MathIeeeSingBasBase = OpenLibrary("mathieeesingbas.library",33); + MathIeeeDoubBasBase = OpenLibrary("mathieeedoubbas.library",33); + MathIeeeDoubTransBase = OpenLibrary("mathieeedoubtrans.library",33); + + PROFILE_ON(); + + if(MathIeeeSingBasBase == NULL) + failed_library = "mathieeesingbas.library"; + else if (MathIeeeDoubBasBase == NULL) + failed_library = "mathieeedoubbas.library"; + else if (MathIeeeDoubTransBase == NULL) + failed_library = "mathieeedoubtrans.library"; + + if(failed_library != NULL) + { + char message[60]; + + strcpy(message,failed_library); + strcat(message," could not be opened."); + + __show_error(message); + + goto out; + } + } + #endif /* IEEE_FLOATING_POINT_SUPPORT */ + + /* Now fill in the HUGE_VAL constant, which is set to + * +Infinity. + */ + if(sizeof(__huge_val) == 4) /* single precision */ + { + static const unsigned long infinity[] = + { + 0x7F800000 + }; + + assert( sizeof(infinity) == sizeof(__huge_val) ); + + memmove((void *)&__huge_val,infinity,sizeof(infinity)); + } + else if (sizeof(__huge_val) == 8) /* double precision */ + { + static const unsigned long infinity[] = + { + 0x7FF00000,0x00000000 + }; + + assert( sizeof(infinity) == sizeof(__huge_val) ); + + memmove((void *)&__huge_val,infinity,sizeof(infinity)); + } + else if (sizeof(__huge_val) == 12) /* extended precision */ + { + static const unsigned long infinity[] = + { + 0x7FFF0000,0x00000000,0x00000000 + }; + + assert( sizeof(infinity) == sizeof(__huge_val) ); + + memmove((void *)&__huge_val,infinity,sizeof(infinity)); + } + + result = OK; + + out: + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_kernel_cos.c b/library/math_kernel_cos.c new file mode 100644 index 0000000..89126c2 --- /dev/null +++ b/library/math_kernel_cos.c @@ -0,0 +1,90 @@ +/* + * $Id: math_kernel_cos.c,v 1.1.1.1 2004-07-26 16:30:46 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) && defined(PPC_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +static const double +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ +C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */ +C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */ +C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */ +C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */ +C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */ +C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */ + +double __kernel_cos(double x, double y) +{ + double a,hz,z,r,qx; + int ix; + + GET_HIGH_WORD(ix,x); + ix &= 0x7fffffff; /* ix = |x|'s high word*/ + if(ix<0x3e400000) { /* if x < 2**27 */ + if(((int)x)==0) return one; /* generate inexact */ + } + z = x*x; + r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6))))); + if(ix < 0x3FD33333) /* if |x| < 0.3 */ + return one - (0.5*z - (z*r - x*y)); + else { + if(ix > 0x3fe90000) { /* x > 0.78125 */ + qx = 0.28125; + } else { + INSERT_WORDS(qx,ix-0x00200000,0); /* x/4 */ + } + hz = 0.5*z-qx; + a = one-qx; + return a - (hz - (z*r-x*y)); + } +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT && PPC_FLOATING_POINT_SUPPORT */ diff --git a/library/math_kernel_expm1.c b/library/math_kernel_expm1.c new file mode 100644 index 0000000..dfccc95 --- /dev/null +++ b/library/math_kernel_expm1.c @@ -0,0 +1,162 @@ +/* + * $Id: math_kernel_expm1.c,v 1.1.1.1 2004-07-26 16:30:46 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) && defined(PPC_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +static const double +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ +huge = 1.0e+300, +tiny = 1.0e-300, +o_threshold = 7.09782712893383973096e+02,/* 0x40862E42, 0xFEFA39EF */ +ln2_hi = 6.93147180369123816490e-01,/* 0x3fe62e42, 0xfee00000 */ +ln2_lo = 1.90821492927058770002e-10,/* 0x3dea39ef, 0x35793c76 */ +invln2 = 1.44269504088896338700e+00,/* 0x3ff71547, 0x652b82fe */ + /* scaled coefficients related to __expm1 */ +Q1 = -3.33333333333331316428e-02, /* BFA11111 111110F4 */ +Q2 = 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */ +Q3 = -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */ +Q4 = 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */ +Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */ + +double __expm1(double x) +{ + double y,hi,lo,c,t,e,hxs,hfx,r1; + int k,xsb; + unsigned int hx; + + GET_HIGH_WORD(hx,x); + xsb = hx&0x80000000; /* sign bit of x */ + if(xsb==0) y=x; else y= -x; /* y = |x| */ + hx &= 0x7fffffff; /* high word of |x| */ + + /* filter out huge and non-finite argument */ + if(hx >= 0x4043687A) { /* if |x|>=56*ln2 */ + if(hx >= 0x40862E42) { /* if |x|>=709.78... */ + if(hx>=0x7ff00000) { + unsigned int low; + GET_LOW_WORD(low,x); + if(((hx&0xfffff)|low)!=0) + return x+x; /* NaN */ + else return (xsb==0)? x:-1.0;/* exp(+-inf)={inf,-1} */ + } + if(x > o_threshold) return huge*huge; /* overflow */ + } + if(xsb!=0) { /* x < -56*ln2, return -1.0 with inexact */ + if(x+tiny<0.0) /* raise inexact */ + return tiny-one; /* return -1 */ + } + } + + /* argument reduction */ + if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ + if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ + if(xsb==0) + {hi = x - ln2_hi; lo = ln2_lo; k = 1;} + else + {hi = x + ln2_hi; lo = -ln2_lo; k = -1;} + } else { + k = invln2*x+((xsb==0)?0.5:-0.5); + t = k; + hi = x - t*ln2_hi; /* t*ln2_hi is exact here */ + lo = t*ln2_lo; + } + x = hi - lo; + c = (hi-x)-lo; + } + else if(hx < 0x3c900000) { /* when |x|<2**-54, return x */ + t = huge+x; /* return x with inexact flags when x!=0 */ + return x - (t-(huge+x)); + } + else k = 0; + + /* x is now in primary range */ + hfx = 0.5*x; + hxs = x*hfx; + r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5)))); + t = 3.0-r1*hfx; + e = hxs*((r1-t)/(6.0 - x*t)); + if(k==0) return x - (x*e-hxs); /* c is 0 */ + else { + e = (x*(e-c)-c); + e -= hxs; + if(k== -1) return 0.5*(x-e)-0.5; + if(k==1) { + if(x < -0.25) return -2.0*(e-(x+0.5)); + else return one+2.0*(x-e); + } + if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */ + unsigned int high; + y = one-(e-x); + GET_HIGH_WORD(high,y); + SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */ + return y-one; + } + t = one; + if(k<20) { + unsigned int high; + SET_HIGH_WORD(t,0x3ff00000 - (0x200000>>k)); /* t=1-2^-k */ + y = t-(e-x); + GET_HIGH_WORD(high,y); + SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */ + } else { + unsigned int high; + SET_HIGH_WORD(t,((0x3ff-k)<<20)); /* 2^-k */ + y = x-(e+t); + y += one; + GET_HIGH_WORD(high,y); + SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */ + } + } + return y; +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT && PPC_FLOATING_POINT_SUPPORT */ diff --git a/library/math_kernel_rem_pio2.c b/library/math_kernel_rem_pio2.c new file mode 100644 index 0000000..628e1cd --- /dev/null +++ b/library/math_kernel_rem_pio2.c @@ -0,0 +1,351 @@ +/* + * $Id: math_kernel_rem_pio2.c,v 1.1.1.1 2004-07-26 16:30:47 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) && defined(PPC_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +static const int init_jk[] = {2,3,4,6}; /* initial value for jk */ +static const double PIo2[] = { + 1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */ + 7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */ + 5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */ + 3.28200341580791294123e422, /* 0x3B78CC51, 0x60000000 */ + 1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */ + 1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */ + 2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */ + 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */ +}; + +static const double +zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ +half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */ +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ +two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */ +twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */ + +INLINE static int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int *ipio2) +{ + int jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih; + double z,fw,f[20],fq[20],q[20]; + + /* initialize jk*/ + jk = init_jk[prec]; + jp = jk; + + /* determine jx,jv,q0, note that 3>q0 */ + jx = nx-1; + jv = (e0-3)/24; if(jv<0) jv=0; + q0 = e0-24*(jv+1); + + /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */ + j = jv-jx; m = jx+jk; + for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j]; + + /* compute q[0],q[1],...q[jk] */ + for (i=0;i<=jk;i++) { + for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw; + } + + jz = jk; +recompute: + /* distill q[] into iq[] reversingly */ + for(i=0,j=jz,z=q[jz];j>0;i++,j--) { + fw = (double)((int)(twon24* z)); + iq[i] = (int)(z-two24*fw); + z = q[j-1]+fw; + } + + /* compute n */ + z = __scalbn(z,(int)q0); /* actual value of z */ + z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */ + n = (int) z; + z -= (double)n; + ih = 0; + if(q0>0) { /* need iq[jz-1] to determine n */ + i = (iq[jz-1]>>(24-q0)); n += i; + iq[jz-1] -= i<<(24-q0); + ih = iq[jz-1]>>(23-q0); + } + else if(q0==0) ih = iq[jz-1]>>23; + else if(z>=0.5) ih=2; + + if(ih>0) { /* q > 0.5 */ + n += 1; carry = 0; + for(i=0;i0) { /* rare case: chance is 1 in 12 */ + switch(q0) { + case 1: + iq[jz-1] &= 0x7fffff; break; + case 2: + iq[jz-1] &= 0x3fffff; break; + } + } + if(ih==2) { + z = one - z; + if(carry!=0) z -= __scalbn(one,(int)q0); + } + } + + /* check if recomputation is needed */ + if(z==zero) { + j = 0; + for (i=jz-1;i>=jk;i--) j |= iq[i]; + if(j==0) { /* need recomputation */ + for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */ + + for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */ + f[jx+i] = (double) ipio2[jv+i]; + for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; + q[i] = fw; + } + jz += k; + goto recompute; + } + } + + /* chop off zero terms */ + if(z==0.0) { + jz -= 1; q0 -= 24; + while(iq[jz]==0) { jz--; q0-=24;} + } else { /* break z into 24-bit if necessary */ + z = __scalbn(z,-(int)q0); + if(z>=two24) { + fw = (double)((int)(twon24*z)); + iq[jz] = (int)(z-two24*fw); + jz += 1; q0 += 24; + iq[jz] = (int) fw; + } else iq[jz] = (int) z ; + } + + /* convert integer "bit" chunk to floating-point value */ + fw = __scalbn(one,(int)q0); + for(i=jz;i>=0;i--) { + q[i] = fw*(double)iq[i]; fw*=twon24; + } + + /* compute PIo2[0,...,jp]*q[jz,...,0] */ + for(i=jz;i>=0;i--) { + for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k]; + fq[jz-i] = fw; + } + + /* compress fq[] into y[] */ + switch(prec) { + case 0: + fw = 0.0; + for (i=jz;i>=0;i--) fw += fq[i]; + y[0] = (ih==0)? fw: -fw; + break; + case 1: + case 2: + fw = 0.0; + for (i=jz;i>=0;i--) fw += fq[i]; + y[0] = (ih==0)? fw: -fw; + fw = fq[0]-fw; + for (i=1;i<=jz;i++) fw += fq[i]; + y[1] = (ih==0)? fw: -fw; + break; + case 3: /* painful */ + for (i=jz;i>0;i--) { + fw = fq[i-1]+fq[i]; + fq[i] += fq[i-1]-fw; + fq[i-1] = fw; + } + for (i=jz;i>1;i--) { + fw = fq[i-1]+fq[i]; + fq[i] += fq[i-1]-fw; + fq[i-1] = fw; + } + for (fw=0.0,i=jz;i>=2;i--) fw += fq[i]; + if(ih==0) { + y[0] = fq[0]; y[1] = fq[1]; y[2] = fw; + } else { + y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw; + } + } + return n&7; +} + +static const int two_over_pi[] = { +0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, +0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, +0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, +0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, +0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, +0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, +0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, +0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, +0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, +0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, +0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, +}; + +static const int npio2_hw[] = { +0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C, +0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C, +0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A, +0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C, +0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB, +0x404858EB, 0x404921FB, +}; + +static const double +invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ +pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */ +pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */ +pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */ +pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */ +pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */ +pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ + +int __rem_pio2(double x, double *y) +{ + double z,w,t,r,fn; + double tx[3]; + int i,j,n,ix,hx; + int e0,nx; + unsigned int low; + + GET_HIGH_WORD(hx,x); /* high word of x */ + ix = hx&0x7fffffff; + if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */ + {y[0] = x; y[1] = 0; return 0;} + if(ix<0x4002d97c) { /* |x| < 3pi/4, special case with n=+-1 */ + if(hx>0) { + z = x - pio2_1; + if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */ + y[0] = z - pio2_1t; + y[1] = (z-y[0])-pio2_1t; + } else { /* near pi/2, use 33+33+53 bit pi */ + z -= pio2_2; + y[0] = z - pio2_2t; + y[1] = (z-y[0])-pio2_2t; + } + return 1; + } else { /* negative x */ + z = x + pio2_1; + if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */ + y[0] = z + pio2_1t; + y[1] = (z-y[0])+pio2_1t; + } else { /* near pi/2, use 33+33+53 bit pi */ + z += pio2_2; + y[0] = z + pio2_2t; + y[1] = (z-y[0])+pio2_2t; + } + return -1; + } + } + if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */ + t = fabs(x); + n = (int) (t*invpio2+half); + fn = (double)n; + r = t-fn*pio2_1; + w = fn*pio2_1t; /* 1st round good to 85 bit */ + if(n<32&&ix!=npio2_hw[n-1]) { + y[0] = r-w; /* quick check no cancellation */ + } else { + unsigned int high; + j = ix>>20; + y[0] = r-w; + GET_HIGH_WORD(high,y[0]); + i = j-((high>>20)&0x7ff); + if(i>16) { /* 2nd iteration needed, good to 118 */ + t = r; + w = fn*pio2_2; + r = t-w; + w = fn*pio2_2t-((t-r)-w); + y[0] = r-w; + GET_HIGH_WORD(high,y[0]); + i = j-((high>>20)&0x7ff); + if(i>49) { /* 3rd iteration need, 151 bits acc */ + t = r; /* will cover all possible cases */ + w = fn*pio2_3; + r = t-w; + w = fn*pio2_3t-((t-r)-w); + y[0] = r-w; + } + } + } + y[1] = (r-y[0])-w; + if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} + else return n; + } + /* + * all other (large) arguments + */ + if(ix>=0x7ff00000) { /* x is inf or NaN */ + y[0]=y[1]=x-x; return 0; + } + /* set z = __scalbn(|x|,ilogb(x)-23) */ + GET_LOW_WORD(low,x); + SET_LOW_WORD(z,low); + e0 = (int)((ix>>20)-1046); /* e0 = ilogb(z)-23; */ + SET_HIGH_WORD(z, ix - ((int)e0<<20)); + for(i=0;i<2;i++) { + tx[i] = (double)((int)(z)); + z = (z-tx[i])*two24; + } + tx[2] = z; + nx = 3; + while(tx[nx-1]==zero) nx--; /* skip zero term */ + n = __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi); + if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;} + return n; +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT && PPC_FLOATING_POINT_SUPPORT */ diff --git a/library/math_kernel_scalbn.c b/library/math_kernel_scalbn.c new file mode 100644 index 0000000..b4b4aa6 --- /dev/null +++ b/library/math_kernel_scalbn.c @@ -0,0 +1,99 @@ +/* + * $Id: math_kernel_scalbn.c,v 1.1.1.1 2004-07-26 16:30:47 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) && defined(PPC_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +INLINE static double copysign(double x, double y) +{ + unsigned int hx,hy; + + GET_HIGH_WORD(hx,x); + GET_HIGH_WORD(hy,y); + SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000)); + + return x; +} + +static const double +huge = 1.0e+300, +tiny = 1.0e-300, +two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ +twom54 = 5.55111512312578270212e-17; /* 0x3C900000, 0x00000000 */ + +double __scalbn (double x, int n) +{ + int k,hx,lx; + EXTRACT_WORDS(hx,lx,x); + k = (hx&0x7ff00000)>>20; /* extract exponent */ + if (k==0) { /* 0 or subnormal x */ + if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */ + x *= two54; + GET_HIGH_WORD(hx,x); + k = ((hx&0x7ff00000)>>20) - 54; + if (n< -50000) return tiny*x; /*underflow*/ + } + if (k==0x7ff) return x+x; /* NaN or Inf */ + k = k+n; + if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */ + if (k > 0) /* normal result */ + {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;} + if (k <= -54) { + if (n > 50000) /* in case integer overflow in n+k */ + return huge*copysign(huge,x); /*overflow*/ + else return tiny*copysign(tiny,x); /*underflow*/ + } + k += 54; /* subnormal result */ + SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); + return x*twom54; +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT && PPC_FLOATING_POINT_SUPPORT */ diff --git a/library/math_kernel_sin.c b/library/math_kernel_sin.c new file mode 100644 index 0000000..853c101 --- /dev/null +++ b/library/math_kernel_sin.c @@ -0,0 +1,82 @@ +/* + * $Id: math_kernel_sin.c,v 1.1.1.1 2004-07-26 16:30:47 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) && defined(PPC_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +static const double +zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ +half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */ +S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */ +S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */ +S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */ +S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */ +S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */ +S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */ + +double __kernel_sin(double x, double y, int iy) +{ + double z,r,v; + int ix; + + GET_HIGH_WORD(ix,x); + + ix &= 0x7fffffff; /* high word of x */ + if(ix<0x3e400000) /* |x| < 2**-27 */ + {if((int)x==0) return x;} /* generate inexact */ + z = x*x; + v = z*x; + r = S2+z*(S3+z*(S4+z*(S5+z*S6))); + if(iy==0) return x+v*(S1+z*r); + else return x-((z*(half*y-v*r)-y)-v*S1); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT && PPC_FLOATING_POINT_SUPPORT */ diff --git a/library/math_kernel_tan.c b/library/math_kernel_tan.c new file mode 100644 index 0000000..aadaf4c --- /dev/null +++ b/library/math_kernel_tan.c @@ -0,0 +1,127 @@ +/* + * $Id: math_kernel_tan.c,v 1.1.1.1 2004-07-26 16:30:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) && defined(PPC_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +static const double +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ +pio4 = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */ +pio4lo= 3.06161699786838301793e-17, /* 0x3C81A626, 0x33145C07 */ +T[] = { + 3.33333333333334091986e-01, /* 0x3FD55555, 0x55555563 */ + 1.33333333333201242699e-01, /* 0x3FC11111, 0x1110FE7A */ + 5.39682539762260521377e-02, /* 0x3FABA1BA, 0x1BB341FE */ + 2.18694882948595424599e-02, /* 0x3F9664F4, 0x8406D637 */ + 8.86323982359930005737e-03, /* 0x3F8226E3, 0xE96E8493 */ + 3.59207910759131235356e-03, /* 0x3F6D6D22, 0xC9560328 */ + 1.45620945432529025516e-03, /* 0x3F57DBC8, 0xFEE08315 */ + 5.88041240820264096874e-04, /* 0x3F4344D8, 0xF2F26501 */ + 2.46463134818469906812e-04, /* 0x3F3026F7, 0x1A8D1068 */ + 7.81794442939557092300e-05, /* 0x3F147E88, 0xA03792A6 */ + 7.14072491382608190305e-05, /* 0x3F12B80F, 0x32F0A7E9 */ + -1.85586374855275456654e-05, /* 0xBEF375CB, 0xDB605373 */ + 2.59073051863633712884e-05, /* 0x3EFB2A70, 0x74BF7AD4 */ +}; + +double __kernel_tan(double x, double y, int iy) +{ + double z,r,v,w,s; + int ix,hx; + GET_HIGH_WORD(hx,x); + ix = hx&0x7fffffff; /* high word of |x| */ + if(ix<0x3e300000) /* x < 2**-28 */ + { + if((int)x==0) { /* generate inexact */ + unsigned int low; + GET_LOW_WORD(low,x); + if(((ix|low)|(iy+1))==0) return one/fabs(x); + else return (iy==1)? x: -one/x; + } + } + if(ix>=0x3FE59428) { /* |x|>=0.6744 */ + if(hx<0) {x = -x; y = -y;} + z = pio4-x; + w = pio4lo-y; + x = z+w; y = 0.0; + } + z = x*x; + w = z*z; + /* Break x^5*(T[1]+x^2*T[2]+...) into + * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) + + * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12])) + */ + r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11])))); + v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12]))))); + s = z*x; + r = y + z*(s*(r+v)+y); + r += T[0]*s; + w = x+r; + if(ix>=0x3FE59428) { + v = (double)iy; + return (double)(1-((hx>>30)&2))*(v-2.0*(x-(w*w/(w+v)-r))); + } + if(iy==1) return w; + else { /* if allow error up to 2 ulp, + simply return -1.0/(x+r) here */ + /* compute -1.0/(x+r) accurately */ + double a,t; + z = w; + SET_LOW_WORD(z,0); + v = r-(z - x); /* z+v = r+x */ + t = a = -1.0/w; /* a = -1.0/w */ + SET_LOW_WORD(t,0); + s = 1.0+t*z; + return t+a*(s+t*v); + } +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT && PPC_FLOATING_POINT_SUPPORT */ diff --git a/library/math_ldexp.c b/library/math_ldexp.c new file mode 100644 index 0000000..f35c161 --- /dev/null +++ b/library/math_ldexp.c @@ -0,0 +1,175 @@ +/* + * $Id: math_ldexp.c,v 1.1.1.1 2004-07-26 16:30:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +#define MANT_MASK 0x800FFFFF /* Mantissa extraction mask */ +#define ZPOS_MASK 0x3FF00000 /* Positive # mask for exp = 0 */ +#define ZNEG_MASK 0x3FF00000 /* Negative # mask for exp = 0 */ + +#define EXP_MASK 0x7FF00000 /* Mask for exponent */ +#define EXP_SHIFTS 20 /* Shifts to get into LSB's */ +#define EXP_BIAS 1023 /* Exponent bias */ + +union dtol +{ + double dval; + long ival[2]; +}; + +INLINE static const double +__ldexp(double x,int n) +{ + union dtol number; + long *iptr, cn; + + number.dval = x; + + iptr = &number.ival[0]; + + cn = (((*iptr) & EXP_MASK) >> EXP_SHIFTS) - EXP_BIAS; + + (*iptr) &= ~EXP_MASK; + + n += EXP_BIAS; + + /* ZZZ we can't just muck with the exponent, we + * have to check for underflow and overflow, too! + */ + (*iptr) |= ((n + cn) << EXP_SHIFTS) & EXP_MASK; + + return(number.dval); +} + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__ldexp(double x,int n) +{ + double result; + + __asm ("fscale%.l %2,%0" + : "=f" (result) + : "0" (x), + "dmi" (n)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +#define MANT_MASK 0x800FFFFF /* Mantissa extraction mask */ +#define ZPOS_MASK 0x3FF00000 /* Positive # mask for exp = 0 */ +#define ZNEG_MASK 0x3FF00000 /* Negative # mask for exp = 0 */ + +#define EXP_MASK 0x7FF00000 /* Mask for exponent */ +#define EXP_SHIFTS 20 /* Shifts to get into LSB's */ +#define EXP_BIAS 1023 /* Exponent bias */ + +union dtol +{ + double dval; + long ival[2]; +}; + +INLINE static const double +__ldexp(double x,int n) +{ + union dtol number; + long *iptr, cn; + + number.dval = x; + + iptr = &number.ival[0]; + + cn = (((*iptr) & EXP_MASK) >> EXP_SHIFTS) - EXP_BIAS; + + (*iptr) &= ~EXP_MASK; + + n += EXP_BIAS; + + /* ZZZ we can't just muck with the exponent, we + * have to check for underflow and overflow, too! + */ + (*iptr) |= ((n + cn) << EXP_SHIFTS) & EXP_MASK; + + return(number.dval); +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +ldexp(double x,int n) +{ + double result; + + if(x != 0.0) + result = __ldexp(x,n); + else + result = 0.0; + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_ledf2.c b/library/math_ledf2.c new file mode 100644 index 0000000..abe749b --- /dev/null +++ b/library/math_ledf2.c @@ -0,0 +1,75 @@ +/* + * $Id: math_ledf2.c,v 1.1.1.1 2004-07-26 16:30:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___ledf2 + +___ledf2: + + moveml d2/d3/a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(16),d0/d1/d2/d3 + jsr a6@(-42:W) + moveml sp@+,d2/d3/a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_lesf2.c b/library/math_lesf2.c new file mode 100644 index 0000000..4bfa59a --- /dev/null +++ b/library/math_lesf2.c @@ -0,0 +1,56 @@ +/* + * $Id: math_lesf2.c,v 1.1.1.1 2004-07-26 16:30:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +float +__lesf2(float x,float y) +{ + float result; + + result = IEEESPCmp(x,y); + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_log.c b/library/math_log.c new file mode 100644 index 0000000..ae3f700 --- /dev/null +++ b/library/math_log.c @@ -0,0 +1,267 @@ +/* + * $Id: math_log.c,v 1.1.1.1 2004-07-26 16:30:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __log(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___log + +___log: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-84:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__log(double x) +{ + double result; + + result = IEEEDPLog(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__log(double x) +{ + double result; + + __asm ("flogn%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +static const double +ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ +ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ +two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ +Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ +Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ +Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ +Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ +Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ +Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ +Lg7 = 1.479819860511658591e-01, /* 3FC2F112 DF3E5244 */ +zero = 0.0; + +INLINE static const double +__log(double x) +{ + double hfsq,f,s,z,R,w,t1,t2,dk; + int k,hx,i,j; + unsigned int lx; + + EXTRACT_WORDS(hx,lx,x); + + k=0; + if (hx < 0x00100000) /* x < 2**-1022 */ + { + if (((hx&0x7fffffff)|lx)==0) + return -two54/zero; /* log(+-0)=-inf */ + if (hx<0) + return (x-x)/zero; /* log(-#) = NaN */ + k -= 54; + x *= two54; /* subnormal number, scale up x */ + GET_HIGH_WORD(hx,x); + } + + if (hx >= 0x7ff00000) + return x+x; + + k += (hx>>20)-1023; + hx &= 0x000fffff; + i = (hx+0x95f64)&0x100000; + + SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */ + + k += (i>>20); + f = x-1.0; + + if((0x000fffff&(2+hx))<3) /* |f| < 2**-20 */ + { + if(f==zero) + { + if(k==0) + return zero; + else + { + dk=(double)k; + return dk*ln2_hi+dk*ln2_lo; + } + } + + R = f*f*(0.5-0.33333333333333333*f); + + if(k==0) + return f-R; + else + { + dk=(double)k; + return dk*ln2_hi-((R-dk*ln2_lo)-f); + } + } + + s = f/(2.0+f); + dk = (double)k; + z = s*s; + i = hx-0x6147a; + w = z*z; + j = 0x6b851-hx; + t1= w*(Lg2+w*(Lg4+w*Lg6)); + t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); + i |= j; + R = t2+t1; + + if(i>0) + { + hfsq=0.5*f*f; + if(k==0) + return f-(hfsq-s*(hfsq+R)); + else + return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f); + } + else + { + if(k==0) + return f-s*(f-R); + else + return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f); + } +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +log(double x) +{ + double result; + + /* ZZZ when do we consider 'x' to be invalid? If it's close + * enough to zero or negative. How large is epsilon, and how + * do we return minus infinity? + */ + if(x > 0.0) + { + result = __log(x); + } + else + { + /* ZZZ this should be minus infinity */ + result = -HUGE_VAL; + errno = ERANGE; + } + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_log10.c b/library/math_log10.c new file mode 100644 index 0000000..0cf1bbf --- /dev/null +++ b/library/math_log10.c @@ -0,0 +1,209 @@ +/* + * $Id: math_log10.c,v 1.1.1.1 2004-07-26 16:30:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __log10(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___log10 + +___log10: + + movel a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-126:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__log10(double x) +{ + double result; + + result = IEEEDPLog10(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__log10(double x) +{ + double result; + + __asm ("flog10%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +static const double +two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ +ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */ +log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */ +log10_2lo = 3.69423907715893078616e-13, /* 0x3D59FEF3, 0x11F12B36 */ +zero = 0.0; + +INLINE static const double +__log10(double x) +{ + double y,z; + int i,k,hx; + unsigned int lx; + + EXTRACT_WORDS(hx,lx,x); + + k=0; + if (hx < 0x00100000) /* x < 2**-1022 */ + { + if (((hx&0x7fffffff)|lx)==0) + return -two54/zero; /* log(+-0)=-inf */ + if (hx<0) + return (x-x)/zero; /* log(-#) = NaN */ + k -= 54; x *= two54; /* subnormal number, scale up x */ + GET_HIGH_WORD(hx,x); + } + + if (hx >= 0x7ff00000) + return x+x; + + k += (hx>>20)-1023; + i = ((unsigned int)k&0x80000000)>>31; + hx = (hx&0x000fffff)|((0x3ff-i)<<20); + y = (double)(k+i); + SET_HIGH_WORD(x,hx); + z = y*log10_2lo + ivln10*log(x); + + return z+y*log10_2hi; +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +log10(double x) +{ + double result; + + /* ZZZ when do we consider 'x' to be invalid? If it's close + * enough to zero or negative. How large is epsilon, and how + * do we return minus infinity? + */ + if(x > 0.0) + { + result = __log10(x); + } + else + { + /* ZZZ this should be minus infinity */ + result = -HUGE_VAL; + errno = ERANGE; + } + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_ltdf2.c b/library/math_ltdf2.c new file mode 100644 index 0000000..caa5e74 --- /dev/null +++ b/library/math_ltdf2.c @@ -0,0 +1,75 @@ +/* + * $Id: math_ltdf2.c,v 1.1.1.1 2004-07-26 16:30:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___ltdf2 + +___ltdf2: + + moveml d2/d3/a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(16),d0/d1/d2/d3 + jsr a6@(-42:W) + moveml sp@+,d2/d3/a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_ltsf2.c b/library/math_ltsf2.c new file mode 100644 index 0000000..26eddf2 --- /dev/null +++ b/library/math_ltsf2.c @@ -0,0 +1,56 @@ +/* + * $Id: math_ltsf2.c,v 1.1.1.1 2004-07-26 16:30:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +float +__ltsf2(float x,float y) +{ + float result; + + result = IEEESPCmp(x,y); + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_modf.c b/library/math_modf.c new file mode 100644 index 0000000..a5fba12 --- /dev/null +++ b/library/math_modf.c @@ -0,0 +1,169 @@ +/* + * $Id: math_modf.c,v 1.1.1.1 2004-07-26 16:30:50 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +INLINE static const double +__modf(double x,double *nptr) +{ + double int_n; + double result; + + if(x < 0.0) + { + int_n = ceil(x); + + result = int_n - x; + } + else + { + int_n = floor(x); + + result = x - int_n; + } + + (*nptr) = int_n; + + return(result); +} + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__modf(double x,double *nptr) +{ + double result; + double temp; + + __asm ("fintrz%.x %1,%0" + : "=f" (temp) /* integer-valued float */ + : "f" (x)); + + (*nptr) = temp; + + result = x - temp; + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +INLINE static const double +__modf(double x,double *nptr) +{ + double int_n; + double result; + + if(x < 0.0) + { + int_n = ceil(x); + + result = int_n - x; + } + else + { + int_n = floor(x); + + result = x - int_n; + } + + (*nptr) = int_n; + + return(result); +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +modf(double x,double *nptr) +{ + double result; + + assert( nptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(nptr == NULL) + { + errno = EFAULT; + result = HUGE_VAL; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + result = __modf(x,nptr); + + out: + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_muldf3.c b/library/math_muldf3.c new file mode 100644 index 0000000..a15b2fc --- /dev/null +++ b/library/math_muldf3.c @@ -0,0 +1,75 @@ +/* + * $Id: math_muldf3.c,v 1.1.1.1 2004-07-26 16:30:50 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___muldf3 + +___muldf3: + + moveml d2/d3/a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(16),d0/d1/d2/d3 + jsr a6@(-78:W) + moveml sp@+,d2/d3/a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_mulsf3.c b/library/math_mulsf3.c new file mode 100644 index 0000000..22c2fc1 --- /dev/null +++ b/library/math_mulsf3.c @@ -0,0 +1,56 @@ +/* + * $Id: math_mulsf3.c,v 1.1.1.1 2004-07-26 16:30:50 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +float +__mulsf3(float x,float y) +{ + float result; + + result = IEEESPMul(x,y); + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_nedf2.c b/library/math_nedf2.c new file mode 100644 index 0000000..b606c2f --- /dev/null +++ b/library/math_nedf2.c @@ -0,0 +1,75 @@ +/* + * $Id: math_nedf2.c,v 1.1.1.1 2004-07-26 16:30:50 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___nedf2 + +___nedf2: + + moveml d2/d3/a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(16),d0/d1/d2/d3 + jsr a6@(-42:W) + moveml sp@+,d2/d3/a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_negdf2.c b/library/math_negdf2.c new file mode 100644 index 0000000..55cb823 --- /dev/null +++ b/library/math_negdf2.c @@ -0,0 +1,75 @@ +/* + * $Id: math_negdf2.c,v 1.1.1.1 2004-07-26 16:30:50 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___negdf2 + +___negdf2: + + movel a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-60:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_negsf2.c b/library/math_negsf2.c new file mode 100644 index 0000000..1bec6ab --- /dev/null +++ b/library/math_negsf2.c @@ -0,0 +1,56 @@ +/* + * $Id: math_negsf2.c,v 1.1.1.1 2004-07-26 16:30:51 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +float +__negsf2(float x) +{ + float result; + + result = IEEESPNeg(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_nesf2.c b/library/math_nesf2.c new file mode 100644 index 0000000..b9d38f2 --- /dev/null +++ b/library/math_nesf2.c @@ -0,0 +1,56 @@ +/* + * $Id: math_nesf2.c,v 1.1.1.1 2004-07-26 16:30:51 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +float +__nesf2(float x,float y) +{ + float result; + + result = IEEESPCmp(x,y); + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_pow.c b/library/math_pow.c new file mode 100644 index 0000000..4958b2a --- /dev/null +++ b/library/math_pow.c @@ -0,0 +1,468 @@ +/* + * $Id: math_pow.c,v 1.1.1.1 2004-07-26 16:30:52 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __pow(double x,double y); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___pow + +___pow: + + moveml d2/d3/a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(16),d0/d1 | Note that the parameters + moveml sp@(24),d2/d3 | are reversed! + jsr a6@(-90:W) + moveml sp@+,d2/d3/a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__pow(double x,double y) +{ + double result; + + /* NOTE: order of parameters is reversed! */ + result = IEEEDPPow(y,x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__exp(double x) +{ + double result; + + __asm ("fetox%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +INLINE static const double +__log(double x) +{ + double result; + + __asm ("flogn%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +INLINE static const double +__pow(double x,double y) +{ + double result; + + if(x > 0) + { + result = __exp(y * __log(x)); + } + else + { + int i = (int)y; + + if((i & 1) == 0) /* even */ + result = __exp(y) * __log(-x); + else + result = -(__exp(y) * __log(-x)); + } + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +static const double +bp[] = {1.0, 1.5,}, +dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */ +dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */ +zero = 0.0, +one = 1.0, +two = 2.0, +two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */ +huge = 1.0e300, +tiny = 1.0e-300, + /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ +L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */ +L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */ +L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */ +L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */ +L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */ +L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */ +P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ +P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ +P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ +P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ +P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */ +lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ +lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */ +lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */ +ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */ +cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */ +cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */ +cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/ +ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */ +ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/ +ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/ + +INLINE static const double +__pow(double x,double y) +{ + double z,ax,z_h,z_l,p_h,p_l; + double y1,t1,t2,r,s,t,u,v,w; + int i,j,k,yisint,n; + int hx,hy,ix,iy; + unsigned int lx,ly; + + EXTRACT_WORDS(hx,lx,x); + EXTRACT_WORDS(hy,ly,y); + ix = hx&0x7fffffff; iy = hy&0x7fffffff; + + /* y==zero: x**0 = 1 */ + if((iy|ly)==0) return one; + + /* +-NaN return x+y */ + if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) || + iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0))) + return x+y; + + /* determine if y is an odd int when x < 0 + * yisint = 0 ... y is not an integer + * yisint = 1 ... y is an odd int + * yisint = 2 ... y is an even int + */ + yisint = 0; + if(hx<0) { + if(iy>=0x43400000) yisint = 2; /* even integer y */ + else if(iy>=0x3ff00000) { + k = (iy>>20)-0x3ff; /* exponent */ + if(k>20) { + j = ly>>(52-k); + if((j<<(52-k))==ly) yisint = 2-(j&1); + } else if(ly==0) { + j = iy>>(20-k); + if((j<<(20-k))==iy) yisint = 2-(j&1); + } + } + } + + /* special value of y */ + if(ly==0) { + if (iy==0x7ff00000) { /* y is +-inf */ + if(((ix-0x3ff00000)|lx)==0) + return y - y; /* inf**+-1 is NaN */ + else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */ + return (hy>=0)? y: zero; + else /* (|x|<1)**-,+inf = inf,0 */ + return (hy<0)?-y: zero; + } + if(iy==0x3ff00000) { /* y is +-1 */ + if(hy<0) return one/x; else return x; + } + if(hy==0x40000000) return x*x; /* y is 2 */ + if(hy==0x3fe00000) { /* y is 0.5 */ + if(hx>=0) /* x >= +0 */ + return sqrt(x); + } + } + + ax = fabs(x); + /* special value of x */ + if(lx==0) { + if(ix==0x7ff00000||ix==0||ix==0x3ff00000){ + z = ax; /*x is +-0,+-inf,+-1*/ + if(hy<0) z = one/z; /* z = (1/|x|) */ + if(hx<0) { + if(((ix-0x3ff00000)|yisint)==0) { + z = (z-z)/(z-z); /* (-1)**non-int is NaN */ + } else if(yisint==1) + z = -z; /* (x<0)**odd = -(|x|**odd) */ + } + return z; + } + } + + /* (x<0)**(non-int) is NaN */ + /* REDHAT LOCAL: This used to be + if((((hx>>31)+1)|yisint)==0) return (x-x)/(x-x); + but ANSI C says a right shift of a signed negative quantity is + implementation defined. */ + if(((((unsigned int)hx>>31)-1)|yisint)==0) return (x-x)/(x-x); + + /* |y| is huge */ + if(iy>0x41e00000) { /* if |y| > 2**31 */ + if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */ + if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny; + if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny; + } + /* over/underflow if x is not close to one */ + if(ix<0x3fefffff) return (hy<0)? huge*huge:tiny*tiny; + if(ix>0x3ff00000) return (hy>0)? huge*huge:tiny*tiny; + /* now |1-x| is tiny <= 2**-20, suffice to compute + log(x) by x-x^2/2+x^3/3-x^4/4 */ + t = ax-1; /* t has 20 trailing zeros */ + w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25)); + u = ivln2_h*t; /* ivln2_h has 21 sig. bits */ + v = t*ivln2_l-w*ivln2; + t1 = u+v; + SET_LOW_WORD(t1,0); + t2 = v-(t1-u); + } else { + double s2,s_h,s_l,t_h,t_l; + n = 0; + /* take care subnormal number */ + if(ix<0x00100000) + {ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); } + n += ((ix)>>20)-0x3ff; + j = ix&0x000fffff; + /* determine interval */ + ix = j|0x3ff00000; /* normalize ix */ + if(j<=0x3988E) k=0; /* |x|>1)|0x20000000)+0x00080000+(k<<18)); + t_l = ax - (t_h-bp[k]); + s_l = v*((u-s_h*t_h)-s_h*t_l); + /* compute log(ax) */ + s2 = s*s; + r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6))))); + r += s_l*(s_h+s); + s2 = s_h*s_h; + t_h = 3.0+s2+r; + SET_LOW_WORD(t_h,0); + t_l = r-((t_h-3.0)-s2); + /* u+v = s*(1+...) */ + u = s_h*t_h; + v = s_l*t_h+t_l*s; + /* 2/(3log2)*(s+...) */ + p_h = u+v; + SET_LOW_WORD(p_h,0); + p_l = v-(p_h-u); + z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */ + z_l = cp_l*p_h+p_l*cp+dp_l[k]; + /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */ + t = (double)n; + t1 = (((z_h+z_l)+dp_h[k])+t); + SET_LOW_WORD(t1,0); + t2 = z_l-(((t1-t)-dp_h[k])-z_h); + } + + s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ + if(((((unsigned int)hx>>31)-1)|(yisint-1))==0) + s = -one;/* (-ve)**(odd int) */ + + /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ + y1 = y; + SET_LOW_WORD(y1,0); + p_l = (y-y1)*t1+y*t2; + p_h = y1*t1; + z = p_l+p_h; + EXTRACT_WORDS(j,i,z); + if (j>=0x40900000) { /* z >= 1024 */ + if(((j-0x40900000)|i)!=0) /* if z > 1024 */ + return s*huge*huge; /* overflow */ + else { + if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */ + } + } else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */ + if(((j-0xc090cc00)|i)!=0) /* z < -1075 */ + return s*tiny*tiny; /* underflow */ + else { + if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */ + } + } + /* + * compute 2**(p_h+p_l) + */ + i = j&0x7fffffff; + k = (i>>20)-0x3ff; + n = 0; + if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */ + n = j+(0x00100000>>(k+1)); + k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */ + t = zero; + SET_HIGH_WORD(t,n&~(0x000fffff>>k)); + n = ((n&0x000fffff)|0x00100000)>>(20-k); + if(j<0) n = -n; + p_h -= t; + } + t = p_l+p_h; + SET_LOW_WORD(t,0); + u = t*lg2_h; + v = (p_l-(t-p_h))*lg2+t*lg2_l; + z = u+v; + w = v-(z-u); + t = z*z; + t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); + r = (z*t1)/(t1-two)-(w+z*w); + z = one-(r-z); + GET_HIGH_WORD(j,z); + j += (n<<20); + if((j>>20)<=0) z = __scalbn(z,(int)n); /* subnormal output */ + else SET_HIGH_WORD(z,j); + return s*z; +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +pow(double x,double y) +{ + double result; + + if(x == 0.0 && y < 0.0) + { + result = HUGE_VAL; + errno = EDOM; + goto out; + } + + if(x < 0.0) + { + double abs_y; + + abs_y = fabs(y); + if(floor(abs_y) != abs_y) + { + result = HUGE_VAL; + errno = EDOM; + goto out; + } + } + + if(x != 0.0 && y == 0.0) + { + result = 1.0; + } + else if (x == 0.0 && y > 0.0) + { + result = 0.0; + } + else + { + result = __pow(x,y); + } + + out: + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_sin.c b/library/math_sin.c new file mode 100644 index 0000000..c864b81 --- /dev/null +++ b/library/math_sin.c @@ -0,0 +1,186 @@ +/* + * $Id: math_sin.c,v 1.1.1.1 2004-07-26 16:30:52 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __sin(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___sin + +___sin: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-36:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__sin(double x) +{ + double result; + + result = IEEEDPSin(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__sin(double x) +{ + double result; + + __asm ("fsin%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +INLINE static const double +__sin(double x) +{ + double y[2],z=0.0; + int n,ix; + + /* High word of x. */ + GET_HIGH_WORD(ix,x); + + /* |x| ~< pi/4 */ + ix &= 0x7fffffff; + if(ix <= 0x3fe921fb) + return __kernel_sin(x,z,0); + + /* sin(Inf or NaN) is NaN */ + else if (ix>=0x7ff00000) return x-x; + + /* argument reduction needed */ + else { + n = __rem_pio2(x,y); + switch(n&3) { + case 0: return __kernel_sin(y[0],y[1],1); + case 1: return __kernel_cos(y[0],y[1]); + case 2: return -__kernel_sin(y[0],y[1],1); + default: + return -__kernel_cos(y[0],y[1]); + } + } +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +sin(double x) +{ + double result; + + result = __sin(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_sinh.c b/library/math_sinh.c new file mode 100644 index 0000000..7b9dbcd --- /dev/null +++ b/library/math_sinh.c @@ -0,0 +1,198 @@ +/* + * $Id: math_sinh.c,v 1.1.1.1 2004-07-26 16:30:52 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __sinh(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___sinh + +___sinh: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-60:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__sinh(double x) +{ + double result; + + result = IEEEDPSinh(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__sinh(double x) +{ + double result; + + __asm ("fsinh%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +static const double one = 1.0, shuge = 1.0e307; + +INLINE static const double +__sinh(double x) +{ + double t,w,h; + int ix,jx; + unsigned int lx; + + /* High word of |x|. */ + GET_HIGH_WORD(jx,x); + ix = jx&0x7fffffff; + + /* x is INF or NaN */ + if(ix>=0x7ff00000) return x+x; + + h = 0.5; + if (jx<0) h = -h; + /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ + if (ix < 0x40360000) { /* |x|<22 */ + if (ix<0x3e300000) /* |x|<2**-28 */ + if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ + t = __expm1(fabs(x)); + if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one)); + return h*(t+t/(t+one)); + } + + /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ + if (ix < 0x40862E42) return h*exp(fabs(x)); + + /* |x| in [log(maxdouble), overflowthresold] */ + GET_LOW_WORD(lx,x); + if (ix<0x408633CE || (ix==0x408633ce && lx<=(unsigned int)0x8fb9f87d)) { + w = exp(0.5*fabs(x)); + t = h*w; + return t*w; + } + + /* |x| > overflowthresold, sinh(x) overflow */ + return x*shuge; +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +sinh(double x) +{ + double result; + + result = __sinh(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_sqrt.c b/library/math_sqrt.c new file mode 100644 index 0000000..59b5bae --- /dev/null +++ b/library/math_sqrt.c @@ -0,0 +1,263 @@ +/* + * $Id: math_sqrt.c,v 1.1.1.1 2004-07-26 16:30:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __sqrt(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___sqrt + +___sqrt: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-96:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__sqrt(double x) +{ + double result; + + result = IEEEDPSqrt(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__sqrt(double x) +{ + double result; + + __asm ("fsqrt%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +static const double one = 1.0, tiny=1.0e-300; + +INLINE static const double +__sqrt(double x) +{ + double z; + int sign = (int)0x80000000; + unsigned int r,t1,s1,ix1,q1; + int ix0,s0,q,m,t,i; + + EXTRACT_WORDS(ix0,ix1,x); + + /* take care of Inf and NaN */ + if((ix0&0x7ff00000)==0x7ff00000) { + return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf + sqrt(-inf)=sNaN */ + } + /* take care of zero */ + if(ix0<=0) { + if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */ + else if(ix0<0) + return (x-x)/(x-x); /* sqrt(-ve) = sNaN */ + } + /* normalize x */ + m = (ix0>>20); + if(m==0) { /* subnormal x */ + while(ix0==0) { + m -= 21; + ix0 |= (ix1>>11); ix1 <<= 21; + } + for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1; + m -= i-1; + ix0 |= (ix1>>(32-i)); + ix1 <<= i; + } + m -= 1023; /* unbias exponent */ + ix0 = (ix0&0x000fffff)|0x00100000; + if(m&1){ /* odd m, double x to make it even */ + ix0 += ix0 + ((ix1&sign)>>31); + ix1 += ix1; + } + m >>= 1; /* m = [m/2] */ + + /* generate sqrt(x) bit by bit */ + ix0 += ix0 + ((ix1&sign)>>31); + ix1 += ix1; + q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */ + r = 0x00200000; /* r = moving bit from right to left */ + + while(r!=0) { + t = s0+r; + if(t<=ix0) { + s0 = t+r; + ix0 -= t; + q += r; + } + ix0 += ix0 + ((ix1&sign)>>31); + ix1 += ix1; + r>>=1; + } + + r = sign; + while(r!=0) { + t1 = s1+r; + t = s0; + if((t>31); + ix1 += ix1; + r>>=1; + } + + /* use floating add to find out rounding direction */ + if((ix0|ix1)!=0) { + z = one-tiny; /* trigger inexact flag */ + if (z>=one) { + z = one+tiny; + if (q1==(unsigned int)0xffffffff) { q1=0; q += 1;} + else if (z>one) { + if (q1==(unsigned int)0xfffffffe) q+=1; + q1+=2; + } else + q1 += (q1&1); + } + } + ix0 = (q>>1)+0x3fe00000; + ix1 = q1>>1; + if ((q&1)==1) ix1 |= sign; + ix0 += (m <<20); + INSERT_WORDS(z,ix0,ix1); + return z; +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +sqrt(double x) +{ + double result; + + if(x >= 0.0) + { + result = __sqrt(x); + } + else + { + result = HUGE_VAL; + errno = EDOM; + } + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_subdf3.c b/library/math_subdf3.c new file mode 100644 index 0000000..82b6d9c --- /dev/null +++ b/library/math_subdf3.c @@ -0,0 +1,75 @@ +/* + * $Id: math_subdf3.c,v 1.1.1.1 2004-07-26 16:30:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubBasBase + .globl ___subdf3 + +___subdf3: + + moveml d2/d3/a6,sp@- + movel "A4(_MathIeeeDoubBasBase)",a6 + moveml sp@(16),d0/d1/d2/d3 + jsr a6@(-72:W) + moveml sp@+,d2/d3/a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_subsf3.c b/library/math_subsf3.c new file mode 100644 index 0000000..7b44c53 --- /dev/null +++ b/library/math_subsf3.c @@ -0,0 +1,56 @@ +/* + * $Id: math_subsf3.c,v 1.1.1.1 2004-07-26 16:30:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +float +__subsf3(float x,float y) +{ + float result; + + result = IEEESPSub(x,y); + + return(result); +} + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/math_tan.c b/library/math_tan.c new file mode 100644 index 0000000..1250523 --- /dev/null +++ b/library/math_tan.c @@ -0,0 +1,179 @@ +/* + * $Id: math_tan.c,v 1.1.1.1 2004-07-26 16:30:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __tan(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___tan + +___tan: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-48:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__tan(double x) +{ + double result; + + result = IEEEDPTan(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__tan(double x) +{ + double result; + + __asm ("ftan%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +INLINE static const double +__tan(double x) +{ + double y[2],z=0.0; + int n,ix; + + /* High word of x. */ + GET_HIGH_WORD(ix,x); + + /* |x| ~< pi/4 */ + ix &= 0x7fffffff; + if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1); + + /* tan(Inf or NaN) is NaN */ + else if (ix>=0x7ff00000) return x-x; /* NaN */ + + /* argument reduction needed */ + else { + n = __rem_pio2(x,y); + return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even + -1 -- n odd */ + } +} +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +tan(double x) +{ + double result; + + result = __tan(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_tanh.c b/library/math_tanh.c new file mode 100644 index 0000000..29f5938 --- /dev/null +++ b/library/math_tanh.c @@ -0,0 +1,192 @@ +/* + * $Id: math_tanh.c,v 1.1.1.1 2004-07-26 16:30:54 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +extern double __tanh(double x); + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___tanh + +___tanh: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-72:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +INLINE static const double +__tanh(double x) +{ + double result; + + result = IEEEDPTanh(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(M68881_FLOATING_POINT_SUPPORT) + +INLINE static const double +__tanh(double x) +{ + double result; + + __asm ("ftanh%.x %1,%0" + : "=f" (result) + : "f" (x)); + + return(result); +} + +#endif /* M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +static const double one=1.0, two=2.0, tiny = 1.0e-300; + +INLINE static const double +__tanh(double x) +{ + double t,z; + int jx,ix; + + /* High word of |x|. */ + GET_HIGH_WORD(jx,x); + ix = jx&0x7fffffff; + + /* x is INF or NaN */ + if(ix>=0x7ff00000) { + if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */ + else return one/x-one; /* tanh(NaN) = NaN */ + } + + /* |x| < 22 */ + if (ix < 0x40360000) { /* |x|<22 */ + if (ix<0x3c800000) /* |x|<2**-55 */ + return x*(one+x); /* tanh(small) = small */ + if (ix>=0x3ff00000) { /* |x|>=1 */ + t = __expm1(two*fabs(x)); + z = one - two/(t+two); + } else { + t = __expm1(-two*fabs(x)); + z= -t/(t+two); + } + /* |x| > 22, return +-1 */ + } else { + z = one - tiny; /* raised inexact flag */ + } + return (jx>=0)? z: -z; +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +tanh(double x) +{ + double result; + + result = __tanh(x); + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/math_truncdfsf2.c b/library/math_truncdfsf2.c new file mode 100644 index 0000000..e9484d8 --- /dev/null +++ b/library/math_truncdfsf2.c @@ -0,0 +1,75 @@ +/* + * $Id: math_truncdfsf2.c,v 1.1.1.1 2004-07-26 16:30:54 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) && defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl _MathIeeeDoubTransBase + .globl ___truncdfsf2 + +___truncdfsf2: + + movel a6,sp@- + movel "A4(_MathIeeeDoubTransBase)",a6 + moveml sp@(8),d0/d1 + jsr a6@(-102:W) + movel sp@+,a6 + rts + +"); + +/****************************************************************************/ + +#endif /* IEEE_FLOATING_POINT_SUPPORT */ diff --git a/library/mount_convertinfo.c b/library/mount_convertinfo.c new file mode 100644 index 0000000..9d60794 --- /dev/null +++ b/library/mount_convertinfo.c @@ -0,0 +1,101 @@ +/* + * $Id: mount_convertinfo.c,v 1.1.1.1 2004-07-26 16:30:54 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MOUNT_HEADERS_H +#include "mount_headers.h" +#endif /* _MOUNT_HEADERS_H */ + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +void +__convert_info_to_statfs(struct InfoData * id,struct statfs * f) +{ + LONG num_blocks,num_blocks_used,bytes_per_block; + + ENTER(); + + assert( id != NULL && f != NULL ); + + SHOWVALUE(id->id_NumSoftErrors); + SHOWVALUE(id->id_UnitNumber); + SHOWVALUE(id->id_DiskState); + SHOWVALUE(id->id_NumBlocks); + SHOWVALUE(id->id_NumBlocksUsed); + SHOWVALUE(id->id_BytesPerBlock); + SHOWVALUE(id->id_DiskType); + SHOWVALUE(id->id_VolumeNode); + SHOWVALUE(id->id_InUse); + + memset(f,0,sizeof(*f)); + + if(id->id_NumBlocks > 0) + { + num_blocks = id->id_NumBlocks; + num_blocks_used = id->id_NumBlocksUsed; + } + else + { + num_blocks = 1; + num_blocks_used = 1; + } + + if(id->id_BytesPerBlock > 0) + bytes_per_block = id->id_BytesPerBlock; + else + bytes_per_block = 512; + + f->f_bsize = bytes_per_block; + f->f_blocks = num_blocks; + f->f_bfree = num_blocks - num_blocks_used; + f->f_iosize = f->f_bsize; + f->f_bavail = f->f_bfree; + f->f_ffree = LONG_MAX; + f->f_flags = MNT_NOATIME|MNT_SYMPERM|MNT_LOCAL; + + if(id->id_DiskType != ID_VALIDATED) + SET_FLAG(f->f_flags,MNT_RDONLY); + + SHOWVALUE(f->f_bsize); + SHOWVALUE(f->f_blocks); + SHOWVALUE(f->f_bfree); + SHOWVALUE(f->f_iosize); + SHOWVALUE(f->f_bavail); + SHOWVALUE(f->f_ffree); + SHOWVALUE(f->f_flags); + + LEAVE(); +} diff --git a/library/mount_fstatfs.c b/library/mount_fstatfs.c new file mode 100644 index 0000000..5142449 --- /dev/null +++ b/library/mount_fstatfs.c @@ -0,0 +1,115 @@ +/* + * $Id: mount_fstatfs.c,v 1.1.1.1 2004-07-26 16:30:54 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _MOUNT_HEADERS_H +#include "mount_headers.h" +#endif /* _MOUNT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +fstatfs(int file_descriptor, struct statfs *buf) +{ + DECLARE_UTILITYBASE(); + struct file_hook_message message; + D_S(struct InfoData,id); + int result = -1; + struct fd * fd; + + ENTER(); + + SHOWVALUE(file_descriptor); + SHOWPOINTER(buf); + + assert( buf != NULL ); + assert( UtilityBase != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(buf == NULL) + { + SHOWMSG("invalid buffer parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( file_descriptor >= 0 && file_descriptor < __num_fd ); + assert( __fd[file_descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + errno = EBADF; + goto out; + } + + SHOWMSG("calling the hook"); + + message.action = file_hook_action_info; + message.info_data = id; + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + + result = message.result; + if(result != 0) + { + errno = message.error; + goto out; + } + + __convert_info_to_statfs(id,buf); + + out: + + RETURN(result); + return(result); +} diff --git a/library/mount_headers.h b/library/mount_headers.h new file mode 100644 index 0000000..738c4b7 --- /dev/null +++ b/library/mount_headers.h @@ -0,0 +1,53 @@ +/* + * $Id: mount_headers.h,v 1.1.1.1 2004-07-26 16:30:54 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MOUNT_HEADERS_H +#define _MOUNT_HEADERS_H + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +extern void __convert_info_to_statfs(struct InfoData * id,struct statfs * f); + +/****************************************************************************/ + +#endif /* _MOUNT_HEADERS_H */ diff --git a/library/mount_statfs.c b/library/mount_statfs.c new file mode 100644 index 0000000..49a2dc7 --- /dev/null +++ b/library/mount_statfs.c @@ -0,0 +1,156 @@ +/* + * $Id: mount_statfs.c,v 1.1.1.1 2004-07-26 16:30:55 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _MOUNT_HEADERS_H +#include "mount_headers.h" +#endif /* _MOUNT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +statfs(const char *path, struct statfs *buf) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info path_nti; + #endif /* UNIX_PATH_SEMANTICS */ + D_S(struct InfoData,id); + LONG status; + BPTR lock = ZERO; + int result = -1; + + ENTER(); + + SHOWSTRING(path); + SHOWPOINTER(buf); + + if(__check_abort_enabled) + __check_abort(); + + assert( path != NULL && buf != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path == NULL || buf == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&path,&path_nti) != 0) + goto out; + + SHOWSTRING(path); + + /* The pseudo root directory is a very special case indeed. + * We make up some pseudo data for it. + */ + if(path_nti.is_root) + { + SHOWMSG("returning data for / directory"); + + memset(buf,0,sizeof(*buf)); + + buf->f_bsize = 512; + buf->f_blocks = 1; + buf->f_bfree = 1; + buf->f_iosize = buf->f_bsize; + buf->f_bavail = buf->f_bfree; + buf->f_flags = MNT_NOATIME|MNT_SYMPERM|MNT_LOCAL|MNT_RDONLY; + + result = 0; + + goto out; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + D(("trying to get a lock on '%s'",path)); + + PROFILE_OFF(); + lock = Lock((STRPTR)path,SHARED_LOCK); + PROFILE_ON(); + + if(lock == ZERO) + { + SHOWMSG("that didn't work"); + + __translate_access_io_error_to_errno(IoErr(),&errno); + goto out; + } + + PROFILE_OFF(); + status = Info(lock,id); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("didn't get the info"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + __convert_info_to_statfs(id,buf); + + result = 0; + + out: + + PROFILE_OFF(); + + UnLock(lock); + + PROFILE_ON(); + + RETURN(result); + return(result); +} diff --git a/library/ncrt0.S b/library/ncrt0.S new file mode 100644 index 0000000..70ba6af --- /dev/null +++ b/library/ncrt0.S @@ -0,0 +1,116 @@ +| +| $Id: ncrt0.S,v 1.1.1.1 2004-07-26 16:30:55 obarthel Exp $ +| +| :ts=4 +| +| Portable ISO 'C' (1994) runtime library for the Amiga computer +| Copyright (c) 2002-2004 by Olaf Barthel +| All rights reserved. +| +| Redistribution and use in source and binary forms, with or without +| modification, are permitted provided that the following conditions +| are met: +| +| - Redistributions of source code must retain the above copyright +| notice, this list of conditions and the following disclaimer. +| +| - Neither the name of Olaf Barthel nor the names of contributors +| may be used to endorse or promote products derived from this +| software without specific prior written permission. +| +| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +| ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +| POSSIBILITY OF SUCH DAMAGE. +| + +|----------------------------------------------------------------------------- + + .text + + .globl __main + +|----------------------------------------------------------------------------- + +#if defined(SMALL_DATA) + + jbsr _geta4 + + movel #___bss_size,d1 + beqs no_bss + lea a4@(__edata:W),a1 + +clear_bss: + + clrl a1@+ + subql #4,d1 + bnes clear_bss + +no_bss: + +#endif /* SMALL_DATA */ + +|----------------------------------------------------------------------------- + +#if defined(SMALL_DATA32) + + jbsr _geta4 + + movel #___bss_size,d1 + beqs no_bss + lea a4@(__edata:L),a1 + +clear_bss: + + clrl a1@+ + subql #4,d1 + bnes clear_bss + +no_bss: + +#endif /* SMALL_DATA32 */ + +|----------------------------------------------------------------------------- + + jmp __main + +|----------------------------------------------------------------------------- + + .globl _geta4 + +_geta4: + +#if defined(SMALL_DATA) + lea ___a4_init,a4 +#endif /* SMALL_DATA */ + +#if defined(SMALL_DATA32) + lea ___a4_init,a4 +#endif /* SMALL_DATA32 */ + + rts + +|----------------------------------------------------------------------------- + + .globl ___get_a4 + +___get_a4: + + movel a4,d0 + rts + +|----------------------------------------------------------------------------- + + .globl ___set_a4 + +___set_a4: + + movel sp@(4),a4 + rts diff --git a/library/net.lib_rev.c b/library/net.lib_rev.c new file mode 100644 index 0000000..99ea55b --- /dev/null +++ b/library/net.lib_rev.c @@ -0,0 +1,38 @@ +/* + * $Id: net.lib_rev.c,v 1.1.1.1 2004-07-26 16:30:55 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "net.lib_rev.h" + +/****************************************************************************/ + +char __net_lib_version[] = VERSTAG; diff --git a/library/net.lib_rev.h b/library/net.lib_rev.h new file mode 100644 index 0000000..2db86e4 --- /dev/null +++ b/library/net.lib_rev.h @@ -0,0 +1,6 @@ +#define VERSION 1 +#define REVISION 165 +#define DATE "26.7.2004" +#define VERS "net.lib 1.165" +#define VSTRING "net.lib 1.165 (26.7.2004)\r\n" +#define VERSTAG "\0$VER: net.lib 1.165 (26.7.2004)" diff --git a/library/net.lib_rev.rev b/library/net.lib_rev.rev new file mode 100644 index 0000000..9e42f3e --- /dev/null +++ b/library/net.lib_rev.rev @@ -0,0 +1 @@ +165 diff --git a/library/nrcrt0.S b/library/nrcrt0.S new file mode 100644 index 0000000..eb7c33c --- /dev/null +++ b/library/nrcrt0.S @@ -0,0 +1,182 @@ +| +| $Id: nrcrt0.S,v 1.1.1.1 2004-07-26 16:30:55 obarthel Exp $ +| +| :ts=4 +| +| Portable ISO 'C' (1994) runtime library for the Amiga computer +| Copyright (c) 2002-2004 by Olaf Barthel +| All rights reserved. +| +| Redistribution and use in source and binary forms, with or without +| modification, are permitted provided that the following conditions +| are met: +| +| - Redistributions of source code must retain the above copyright +| notice, this list of conditions and the following disclaimer. +| +| - Neither the name of Olaf Barthel nor the names of contributors +| may be used to endorse or promote products derived from this +| software without specific prior written permission. +| +| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +| ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +| POSSIBILITY OF SUCH DAMAGE. +| + +|----------------------------------------------------------------------------- + +LVOAllocMem = -0xc6 +LVOFreeMem = -0xd2 +LVOFindTask = -0x126 +LVOCopyMem = -0x270 + +|----------------------------------------------------------------------------- + +pr_Result2 = 148 +pr_CLI = 172 + +|----------------------------------------------------------------------------- + +RETURN_FAIL = 20 +ERROR_NO_FREE_STORE = 103 + +|----------------------------------------------------------------------------- + +MEMF_CLEAR = 65536 + +|----------------------------------------------------------------------------- + + .text + + .globl __main + .globl ___is_resident + +|----------------------------------------------------------------------------- + + movel 4:W,a6 + + subal a1,a1 + jsr a6@(LVOFindTask:W) + + movel d0,a2 + tstl a2@(pr_CLI:W) + bnes from_shell + +|----------------------------------------------------------------------------- + + lea ___a4_init,a4 + + movel #___bss_size,d1 + beqs no_bss + +#if defined(SMALL_DATA) + lea a4@(__edata:W),a1 +#endif /* SMALL_DATA */ + +#if defined(SMALL_DATA32) + lea a4@(__edata:L),a1 +#endif /* SMALL_DATA32 */ + +clear_bss: + + clrl a1@+ + subql #4,d1 + bnes clear_bss + +no_bss: + + jmp __main + +|----------------------------------------------------------------------------- + +from_shell: + + movel #___data_size,d5 + movel #___bss_size,d0 + addl d5,d0 + movel #MEMF_CLEAR,d1 + jsr a6@(LVOAllocMem:W) + tstl d0 + beqs fail + + movel d0,a4 + + lea ___a4_init-0x7ffe,a5 + movel d5,d0 + movel a5,a0 + movel a4,a1 + jsr a6@(LVOCopyMem:W) + + lea ___datadata_relocs,a0 + movel a0@+,d0 + beqs no_reloc + + movel a5,d1 + subl a4,d1 + +do_reloc: + + movel a0@+,a1 + subl d1,a4@(a1:l) + subql #1,d0 + bnes do_reloc + +no_reloc: + + lea a4@(0x7ffe:W),a4 + +#if defined(SMALL_DATA) + lea a4@(___is_resident:W),a2 +#endif /* SMALL_DATA */ + +#if defined(SMALL_DATA32) + lea a4@(___is_resident:L),a2 +#endif /* SMALL_DATA32 */ + + movew #1,a2@ + + jbsr __main + movel d0,d2 + + movel 4:W,a6 + movel #___data_size,d0 + addl #___bss_size,d0 + lea a4@(-0x7ffe:W),a1 + jsr a6@(LVOFreeMem:W) + + movel d2,d0 + + rts + +fail: + + movel #ERROR_NO_FREE_STORE,a2@(pr_Result2:W) + moveql #RETURN_FAIL,d0 + + rts + +|----------------------------------------------------------------------------- + + .globl ___get_a4 + +___get_a4: + + movel a4,d0 + rts + +|----------------------------------------------------------------------------- + + .globl ___set_a4 + +___set_a4: + + movel sp@(4),a4 + rts diff --git a/library/profile__mcount.c b/library/profile__mcount.c new file mode 100644 index 0000000..1381283 --- /dev/null +++ b/library/profile__mcount.c @@ -0,0 +1,103 @@ +#include "profile_gmon.h" +#include +#include +#include + +void +__mcount(uint32 frompc, uint32 selfpc) +{ + uint16 *frompcindex; + struct tostruct *top, *prevtop; + struct gmonparam *p; + + int32 toindex; + + p = &_gmonparam; + + if (p->state != kGmonProfOn) return; + + p->state = kGmonProfBusy; + + /* + * Check if the PC is inside our text segment. + * Really should be... + */ + frompc -= p->lowpc; + selfpc -= p->lowpc; + if (frompc > p->textsize) goto done; + +#if (HASHFRACTION & (HASHFRACTION-1)) == 0 + if (p->hashfraction == HASHFRACTION) + { + frompcindex = &p->froms[(size_t)(frompc / (HASHFRACTION * + sizeof(*p->froms)))]; + } + else +#endif + { + frompcindex = &p->froms[(size_t)(frompc / (p->hashfraction * + sizeof(*p->froms)))]; + } + + toindex = *frompcindex; + + if (toindex == 0) + { + /* first time down this arc */ + toindex = ++p->tos[0].link; + if (toindex >= p->tolimit) + /* Ouch! Overflow */ + goto overflow; + + *frompcindex = (uint16)toindex; + top = &p->tos[toindex]; + top->selfpc = selfpc; + top->count = 1; + top->link = 0; + goto done; + } + + top = &p->tos[toindex]; + if (top->selfpc == selfpc) + { + /* arc at front of chain */ + top->count++; + goto done; + } + + for (;;) + { + if (top->link == 0) + { + toindex = ++p->tos[0].link; + if (toindex >= p->tolimit) + goto overflow; + + top = &p->tos[toindex]; + top->selfpc = selfpc; + top->count = 1; + top->link = *frompcindex; + *frompcindex = (uint16)toindex; + goto done; + } + prevtop = top; + top = &p->tos[top->link]; + if (top->selfpc == selfpc) + { + top->count++; + toindex = prevtop->link; + prevtop->link = top->link; + top->link = *frompcindex; + *frompcindex = (uint16)toindex; + goto done; + } + } + +done: + p->state = kGmonProfOn; + return; + +overflow: + p->state = kGmonProfError; + return; +} diff --git a/library/profile_gmon.c b/library/profile_gmon.c new file mode 100644 index 0000000..9bd1676 --- /dev/null +++ b/library/profile_gmon.c @@ -0,0 +1,281 @@ +#include +#include +#include +#include +#include +#include +#include + +#define SCALE_1_TO_1 0x10000L + +#include "profile_gmon.h" +#undef DebugPrintF +#define dprintf(format, args...)((struct ExecIFace *)((*(struct ExecBase **)4)->MainInterface))->DebugPrintF("[%s] " format, __PRETTY_FUNCTION__ , ## args) + +struct gmonparam _gmonparam = {kGmonProfOn}; +static unsigned int s_scale; + +void moncontrol(int); +void monstartup(uint32, uint32); +void moncleanup(void); +void mongetpcs(uint32* lowpc, uint32 *highpc); + +extern int profil(uint16 *buffer, uint32 bufSize, + uint32 offset, uint32 scale); + +void +monstartup(uint32 low_pc, uint32 high_pc) +{ + uint8 *cp; + uint32 lowpc, highpc; + struct gmonparam *p = &_gmonparam; + dprintf("in monstartup)\n"); + /* + * If we don't get proper lowpc and highpc, then + * we'll try to get them from the elf handle. + */ + if (low_pc == 0 && high_pc == 0) + { + mongetpcs(&lowpc, &highpc); + } + else + { + lowpc = low_pc; + highpc = high_pc; + } + + /* + * Round lowpc and highpc to multiples of the density + * to prevent using floating point scaling + */ + p->lowpc = ROUNDDOWN(lowpc, HISTFRACTION * sizeof(HISTCOUNTER)); + p->highpc = ROUNDUP(highpc, HISTFRACTION * sizeof(HISTCOUNTER)); + + /* Size of the text segment */ + p->textsize = p->highpc - p->lowpc; + + /* + * Size of the histogram. Due to the nature of PowerPC code, + * we can safely use a histogram fraction of at least 4, since + * every instruction is exactly one word wide and always aligned. + */ + p->kcountsize = p->textsize / HISTFRACTION; + + /* + * The hash table size + */ + p->hashfraction = HASHFRACTION; + p->fromssize = p->textsize / p->hashfraction; + + p->tolimit = p->textsize * ARCDENSITY / 100; + if (p->tolimit < MINARCS) + p->tolimit = MINARCS; + else if (p->tolimit > MAXARCS) + p->tolimit = MAXARCS; + + p->tossize = p->tolimit * sizeof(struct tostruct); + + dprintf("lowpc = %p, highpc = %p\n", lowpc, highpc); + dprintf("textsize = %d\n", p->textsize); + dprintf("kcountsize = %d\n", p->kcountsize); + dprintf("fromssize = %d\n", p->fromssize); + dprintf("tolimit = %d, tossize = %d\n", p->tolimit, p->tossize); + + cp = (uint8*)AllocMem(p->kcountsize + p->fromssize + p->tossize, + MEMF_CLEAR); + if (!cp) + { + p->state = kGmonProfError; + return; + } + + p->memory = cp; + p->tos = (struct tostruct *)cp; + cp += p->tossize; + + p->kcount = (uint16 *)cp; + cp += p->kcountsize; + + p->froms = (uint16 *)cp; + + p->tos[0].link = 0; + + /* Verify granularity for sampling */ + if (p->kcountsize < p->textsize) + /* FIXME Avoid floating point */ + s_scale = ((float)p->kcountsize / p->textsize) * SCALE_1_TO_1; + else + s_scale = SCALE_1_TO_1; + + s_scale >>= 1; + dprintf("Enabling monitor\n"); + moncontrol(1); +} + +void +moncontrol(int mode) +{ + struct gmonparam *p = &_gmonparam; + + if (mode) + { + /* Start profiling. */ + profil((uint16 *)p->kcount, (size_t)p->kcountsize, + p->lowpc, s_scale); + p->state = kGmonProfOn; + } + else + { + /* Stop Profiling. */ + profil(NULL, 0, (uint32)0, 0); + p->state = kGmonProfOff; + } +} + +void +moncleanup(void) +{ + BPTR fd; + int fromindex; + int endfrom; + uint32 frompc; + int toindex; + struct rawarc rawarc; + struct gmonparam *p = &_gmonparam; + struct gmonhdr gmonhdr, *hdr; +#ifdef DEBUG + FILE *log; +#endif + + moncontrol(0); + + if (p->state == kGmonProfError) + { + fprintf(stderr, "WARNING: Overflow during profiling\n"); + } + + fd = Open("gmon.out", MODE_NEWFILE); + if (!fd) + { + fprintf(stderr, "ERROR: could not open gmon.out\n"); + return; + } + + hdr = (struct gmonhdr *)&gmonhdr; + + hdr->lpc = 0; //p->lowpc; + hdr->hpc = p->highpc - p->lowpc; + hdr->ncnt = (int)p->kcountsize + sizeof(gmonhdr); + hdr->version = GMONVERSION; + hdr->profrate = 100; //FIXME:!! + + Write(fd, hdr, sizeof(*hdr)); + Write(fd, p->kcount, p->kcountsize); + + endfrom = p->fromssize / sizeof(*p->froms); + +#ifdef DEBUG + log = fopen("gmon.log", "w"); +#endif + + for (fromindex = 0; fromindex < endfrom; fromindex++) + { + if (p->froms[fromindex] == 0) continue; + + frompc = 0; /* FIXME: was p->lowpc; needs to be 0 and assumes + -Ttext=0 on compile. Better idea? */ + frompc += fromindex * p->hashfraction * sizeof (*p->froms); + for (toindex = p->froms[fromindex]; toindex != 0; + toindex = p->tos[toindex].link) + { +#ifdef DEBUG + if (log) fprintf(log, "%p called from %p: %d times\n", frompc, + p->tos[toindex].selfpc, + p->tos[toindex].count); +#endif + rawarc.raw_frompc = frompc; + rawarc.raw_selfpc = p->tos[toindex].selfpc; + rawarc.raw_count = p->tos[toindex].count; + Write(fd, &rawarc, sizeof(rawarc)); + } + } + +#ifdef DEBUG + if (log) fclose(log); +#endif + Close(fd); + +} + +void +mongetpcs(uint32* lowpc, uint32 *highpc) +{ + struct Library *ElfBase = NULL; + struct ElfIFace *IElf = NULL; + struct Process *self; + BPTR seglist; + Elf32_Handle elfHandle; + uint32 i; + Elf32_Shdr *shdr; + uint32 numSections; + + *lowpc = 0; + *highpc = 0; + + ElfBase = OpenLibrary("elf.library", 0L); + if (!ElfBase) goto out; + + IElf = (struct ElfIFace *)GetInterface(ElfBase, "main", 1, NULL); + if (!IElf) goto out; + + self = (struct Process *)FindTask(0); + seglist = GetProcSegList(self); + + GetSegListInfoTags(seglist, + GSLI_ElfHandle, &elfHandle, + TAG_DONE); + + elfHandle = OpenElfTags( + OET_ElfHandle, elfHandle, + TAG_DONE); + + if (!elfHandle) goto out; + + GetElfAttrsTags(elfHandle, EAT_NumSections, &numSections, TAG_DONE); + + for (i = 0; i < numSections; i++) + { + shdr = GetSectionHeaderTags(elfHandle, + GST_SectionIndex, i, + TAG_DONE); + if (shdr && (shdr->sh_flags & SWF_EXECINSTR)) + { + uint32 base = (uint32)GetSectionTags(elfHandle, + GST_SectionIndex, i, + TAG_DONE); + *lowpc = base; + *highpc = base + shdr->sh_size; + break; + } + } + + CloseElfTags(elfHandle, CET_ReClose, TRUE, TAG_DONE); + +out: + if (IElf) DropInterface((struct Interface *)IElf); + if (ElfBase) CloseLibrary(ElfBase); +} + + +#include "macros.h" + +int __profiler_init(void) +{ + monstartup(0,0); + return OK; +} + +void __profiler_exit(void) +{ + moncleanup(); +} \ No newline at end of file diff --git a/library/profile_gmon.h b/library/profile_gmon.h new file mode 100644 index 0000000..9805b9e --- /dev/null +++ b/library/profile_gmon.h @@ -0,0 +1,81 @@ +#ifndef _GMON_H +#define _GMON_H + +#include + +struct gmonhdr +{ + uint32 lpc; + uint32 hpc; + int ncnt; + int version; + int profrate; + int reserved[3]; +}; + +#define GMONVERSION 0x00051879 + +#define HISTCOUNTER uint16 +// I am sure we can make these bigger +#define HISTFRACTION 2 +#define HASHFRACTION 4 + +#define ARCDENSITY 2 +#define MINARCS 50 +#define MAXARCS ((1 << (8 * sizeof(HISTCOUNTER)))-2) + +struct tostruct +{ + uint32 selfpc; + int32 count; + uint16 link; + uint16 pad; +}; + +struct rawarc +{ + uint32 raw_frompc; + uint32 raw_selfpc; + int32 raw_count; +}; + +#define ROUNDDOWN(x,y) (((x)/(y))*(y)) +#define ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y)) + +struct gmonparam +{ + int state; + uint16 * kcount; + uint32 kcountsize; + uint16 * froms; + uint32 fromssize; + struct tostruct * tos; + uint32 tossize; + int32 tolimit; + uint32 lowpc; + uint32 highpc; + uint32 textsize; + uint32 hashfraction; + uint8 * memory; +}; + +extern struct gmonparam _gmonparam; + +enum +{ + kGmonProfOn = 0, + kGmonProfBusy = 1, + kGmonProfError = 2, + kGmonProfOff = 3 +}; + +enum +{ + kGprofState = 0, + kGprofCount = 1, + kGprofFroms = 2, + kGprofTos = 3, + kGprofGmonParam = 4 +}; + +#endif diff --git a/library/profile_mcount.S b/library/profile_mcount.S new file mode 100644 index 0000000..ac33ef8 --- /dev/null +++ b/library/profile_mcount.S @@ -0,0 +1,35 @@ + .globl _mcount + .type _mcount,@function +_mcount: + stwu r1,-64(r1) + stw r3,16(r1) + stw r4,20(r1) + stw r5,24(r1) + stw r6,28(r1) + stw r7,32(r1) + stw r8,36(r1) + stw r9,40(r1) + stw r10,44(r1) + + mflr r4 + stw r4,48(r1) + lwz r3,68(r1) + + bl __mcount + lwz r3,68(r1) + mtlr r3 + lwz r4,48(r1) + mtctr r4 + + lwz r3,16(r1) + lwz r4,20(r1) + lwz r5,24(r1) + lwz r6,28(r1) + lwz r7,32(r1) + lwz r8,36(r1) + lwz r9,40(r1) + lwz r10,44(r1) + addi r1,r1,64 + bctr +_mcount_end: + .size _mcount,_mcount_end-_mcount \ No newline at end of file diff --git a/library/profile_profil.c b/library/profile_profil.c new file mode 100644 index 0000000..96808fd --- /dev/null +++ b/library/profile_profil.c @@ -0,0 +1,122 @@ +#include +#include +#include + +static struct PerformanceMonitorIFace *IPM; +static struct Interrupt CounterInt; + +#undef DebugPrintF +#define dprintf(format, args...)((struct ExecIFace *)((*(struct ExecBase **)4)->MainInterface))->DebugPrintF("[%s] " format, __PRETTY_FUNCTION__ , ## args) + +static struct IntData +{ + struct PerformanceMonitorIFace *IPM; + uint16 *Buffer; + uint32 BufferSize; + uint32 Offset; + uint32 Scale; + uint32 CounterStart; +} ProfileData; + + +uint32 +GetCounterStart(void) +{ + uint64 fsb; + double bit0time; + uint32 count; + + GetCPUInfoTags( + GCIT_FrontsideSpeed, &fsb, + TAG_DONE); + + /* Timebase ticks at 1/4 of FSB */ + bit0time = 8.0 / (double)fsb; + count = (uint32)(0.01 / bit0time); + + return 0x80000000 - count; +} + +uint32 +CounterIntFn(struct ExceptionContext *ctx, struct ExecBase *ExecBase, + struct IntData *ProfileData) +{ + uint32 sia = (uint32)ProfileData->IPM->GetSampledAddress(); + dprintf(".\n"); + sia = ((sia - ProfileData->Offset) * ProfileData->Scale) >> 16; + + if (sia <= (ProfileData->BufferSize>>1)) + { + //if (ProfileData->Buffer[sia] != 0xffff) + ProfileData->Buffer[sia]++; + } + + IPM->CounterControl(1, ProfileData->CounterStart, PMCI_Transition); + + return 1; +} + + +int +profil(uint16 *buffer, uint32 bufSize, uint32 offset, uint32 scale) +{ + APTR Stack; + + if (buffer == 0) + { + Stack = SuperState(); + IPM->EventControlTags( + PMECT_Disable, PMEC_MasterInterrupt, + TAG_DONE); + + IPM->SetInterruptVector(1, 0); + + IPM->Unmark(0); + IPM->Release(); + if (Stack) UserState(Stack); + + return 0; + } + + IPM = (struct PerformanceMonitorIFace *) + OpenResource("performancemonitor.resource"); + + if (!IPM || IPM->Obtain() != 1) + { + dprintf("No performance monitor\n"); + return 0; + } + + Stack = SuperState(); + + /* Init IntData */ + ProfileData.IPM = IPM; + ProfileData.Buffer = buffer; + ProfileData.BufferSize = bufSize; + ProfileData.Offset = offset; + ProfileData.Scale = scale; + ProfileData.CounterStart = GetCounterStart(); + + /* Set interrupt vector */ + CounterInt.is_Code = (void (*)())CounterIntFn; + CounterInt.is_Data = &ProfileData; + IPM->SetInterruptVector(1, &CounterInt); + + /* Prepare Performance Monitor */ + IPM->MonitorControlTags( + PMMCT_FreezeCounters, PMMC_Unmarked, + PMMCT_RTCBitSelect, PMMC_BIT0, + TAG_DONE); + IPM->CounterControl(1, ProfileData.CounterStart, PMCI_Transition); + + IPM->EventControlTags( + PMECT_Enable, 1, + PMECT_Enable, PMEC_MasterInterrupt, + TAG_DONE); + + IPM->Mark(0); + + if (Stack) UserState(Stack); + + return 0; +} diff --git a/library/releasenotes b/library/releasenotes new file mode 100644 index 0000000..3bc288c --- /dev/null +++ b/library/releasenotes @@ -0,0 +1,3036 @@ +c.lib 1.165 (26.7.2004) + +- In printf(), if the precision is 0 and the value to be printed for + the %d, %i, %u, %o and %x conversion types is 0, no output should + be produced. Fixed. + +- Fixed the rounding for %g (again). The maximum number of significant + digits produced by a precision given for %g is different for numbers + < 1.0 and those >= 1.0: the leading 0 for numbers < 1.0 does not count + as a significant digit. + +- The calculation of the number of leading digits in a floating point + number now uses a mixture of log10() and a fall-back just in case + log10() returns gunk. + +- For floating point numbers, the sign, the digits, trailing zeroes + and the exponent are now set up and 'assembled' separately. This + removes the artificial limitation of floating point numbers to + a maximum of 78 digits to follow the decimal point. + + +c.lib 1.164 (25.7.2004) + +- The precision given for the printf() %g conversion types determines the + number of digits to generate, not the number of digits to follow the + decimal point. Fixed. The GCC FPU code generation now works again. + Previously, the floating point number conversion crashed cc1 since the + output amounted to 32 digits plus a terminating NUL, which overran the + 30 byte buffer sprintf() stored the output in. My, this was very hard + to find :( + +- Restored the floor() loop to figure out the size of the integer part + of a floating point number. For some strange reason, the log10() function + can return HUGE_VAL for numbers >= MAX_INT if mathieeedoubtrans.library + is involved. This crashes the conversion, which has the effect of making + the number come out as 0 rather than MAX_INT. Now that was nasty, too :( + + +c.lib 1.163 (25.7.2004) + +- Simplified the %e/%f/%g conversion some more. We now call log10 and pow + instead of looping and scaling the floating point number to be printed. + + +c.lib 1.162 (25.7.2004) + +- Simplified the floating point number output code in vfprintf(). + Instead of two separate branches handling output for the %e and + %f conversion types, the two now share the same code. + + +c.lib 1.161 (24.7.2004) + +- Dropped all the non-public source code fragments from the library, + including the memory pools, ARexx variable support and asyncio + functionality. + + +c.lib 1.160 (24.7.2004) + +- fputc() never flushed the output buffer if the stream in question + was unbuffered. + +- Rewrote puts() not to call fputs(). This avoids flushing the output + buffer twice if stdout is unbuffered. + + +c.lib 1.159 (23.7.2004) + +- Trying to open a directory like a file now reliably produces the + error code EISDIR. Previously, the error code could have come + out as ENOTDIR instead. + + +c.lib 1.158 (21.7.2004) + +- freopen() was broken since it tried to reuse data from an already + closed stream. Fixed. + +- Fixed a number of small compiler problems resulting from debug + output code that had never been exercised, or was not adapted to + subsequent code changes. + +- You can now enable debug output and have assertions come out + correctly. + + +c.lib 1.157 (21.7.2004) + +- The file hook message action "file_hook_action_write_and_flush" was + not handled properly by the socket and scanf/printf hooks. Fixed. + +- Removed a few assertions from the select() wrapper code which + prevented it from working properly. + +- Changed the stdio buffered I/O flushing code so that data can stay + in the cache, if necessary, rather than get written to disk. This + should help the asynchronous I/O feature. + + +c.lib 1.156 (21.7.2004) + +- Brought back the __unix_path_semantics variable. If you link with + -lunix and set this variable to FALSE, you'll still get Unix-like + behaviour from certain routines, only the translations of Unix<->Amiga + path name semantics will be disabled, leaving you with Amiga path + semantics. + +- sscanf(), asprintf(), vasprintf(), snprintf(), vsnprintf(), sprintf() + and vsprintf() now use short local buffers to speed up conversion rather + than a single measly byte. + +- opendir() now avoids returning duplicate volume names. + + + +c.lib 1.155 (21.7.2004) + +- Lost all special case code which took care of unbuffered output + and input. The new implementation works by using one byte of + buffer, which is part of the iob structure. Unbuffered output + is produced by 'flushing' the buffer once data has been written + to it. The new code also has the advantage of making ungetc() + work on unbuffered streams. + + NOTE THAT THIS MEANS THAT THE ENTIRE LIBRARY NEEDS TO BE REBUILT! + +- Each FILE buffer now sports back-link information which can be + tested to verify that it is valid. + + +c.lib 1.154 (21.7.2004) + +- fwrite() has to call fputc() for each byte to be written. Oops... + fwrite() no longer changes the file position if a write access + went wrong. Trying to write to a stream which is not available + for writing now counts as an error. + +- fread() has to call fgetc() for each byte to be read. fread() no + longer changes the file position if a partial read would yield + fewer data than is necessary to fill an element. Trying to read + from a stream which is not available for reading now counts as + an error. + +- Lost all the code that tested if the hook pointer embedded in a + file descriptor table entry or buffered file was NULL. It + simply has to be a valid pointer. + + +c.lib 1.153 (19.7.2004) + +- Oops: cli->cli_DefaultStack does not necessarily match the size + of the program's stack if it was launched from the shell and the + "$STACK:" keyword embedded in the program overrides the default + shell command stack size. + +- Stack space allocated locally is now public rather than private + memory (although it probably should be private). + + +c.lib 1.152 (19.7.2004) + +- Simplified the code that figures out how much stack space was + provided to the program when it was launched. The number does + not need to be absolutely accurate at the time it is calculated. + +- vfprintf() now prints a pointer (%p) as if it were a hexadecimal + number with 8 digits (0x%08x). + + +c.lib 1.151 (18.7.2004) + +- Oops: I mixed up the file descriptor and buffered I/O flags + in fflush() and __fill_iob_read_buffer(). + + +c.lib 1.150 (18.7.2004) + +- Checked the dos.library/InternalRunCommand() code to see if + the fiddling with Process->pr_ReturnAddresss is really necessary to + figure out how much stack space is available. Turns out that it + isn't under Kickstart 2.0 and beyond. Since this is what the library + requires, only the task lower/upper bound and the current stack + pointer address are consulted now. + +- isascii() is now a macro. + + +c.lib 1.149 (17.7.2004) + +- Reworked the ctype table layout and how the table is used by + the optional ctype macros. + + +c.lib 1.148 (17.7.2004) + +- Changed the flag definitions used by buffered files. + + NOTE THAT THIS MEANS THAT THE ENTIRE LIBRARY NEEDS TO BE REBUILT! + +- Added new macros to and which replace functions + of the same name and which might be more efficient. + + +c.lib 1.147 (17.7.2004) + +- Removed the isascii() macro and replaced it with a real function. + + +c.lib 1.146 (17.7.2004) + +- added a missing isascii() define to the ctype.h include file + as it is quiet a common function macro and should be included + + +c.lib 1.145 (16.7.2004) + +- Oops, I broke strncpy() *again*. Fixed. + + +c.lib 1.144 (16.7.2004) + +- The file descriptor duplication code now sits in a separate + function rather than in the different file/socket descriptor + hooks. + +- The code which reduces AmigaDOS path names by dropping path + components followed by two slashes now sits in a separate + function. Previously, it appeared twice in the Amiga<->Unix + path name translation code. + +- Simplified the select() function considerably. + + +c.lib 1.143 (16.7.2004) + +- added missing hook_entry object files to GNU OS4 makefile + +- added required newlines "\n" to the 68k GNU inline assembler + functions to make them compile with GCC version 3 and upwards. + + +c.lib 1.142 (15.7.2004) + +- ferror() does not return the code of the error for the stream + which ran into trouble, it merely signals that an error occured. + There goes another iob state variable. + + NOTE THAT THIS MEANS THAT THE ENTIRE LIBRARY NEEDS TO BE REBUILT! + +- Removed all the code that set the value of 'errno' to 0. + +- Likewise, removed all the code that reset the error condition + that might have been set for a file. The only function which + can do that is clearerr(). + +- No functions other but clearerr(), ungetc() and fseek() clear the + 'eof detected' flag now. + +- Simplified vfprintf() some more, merging the %x formatting code + with the other integer conversion code. + +- vfscanf() now decides that with the %i conversion, a number is + in octal notation if the first digit converted is a 0 and there + is no 'x' or 'X' character following it. + +- vfscanf() no longer counts '%n' as an assignment/conversion operation. + +- Rewrote strtol() and strtoul() again. The overflow detection is + now different in both routines and they avoid performing a + conversion if the base is 1 (which would lead to an infinite + loop). Also, the possible base values are limited to <= 36 and + letters in the range a..z are allowed, too. + +- All buffered streams which hold data and which operate in line buffering + mode are now flushed before the buffer of a line buffered input stream + is filled. + +- fflush() now flushes all buffered files if the stream parameter + is NULL. + +- Unlike fgets(), gets() does *not* put the terminating '\n' character + into the buffer. Fixed. + +- rewind() now clears both the 'end of file' and error indicator flags. + +- Replaced all memcpy() calls with memmove(). + +- Cleaned up error code translation and forwarding within the hook + functions. Instead of mucking around with the global errno variable, + the hook functions now return the error code as part of the hook + message. The error code translation is now done entirely through + two functions rather than one function, which fiddled with the + global errno variable, and local code which, if necessary, translated + ERROR_OBJECT_WRONG_TYPE into ENOTDIR. + + NOTE THAT THIS, TOO, MEANS THAT THE ENTIRE LIBRARY NEEDS TO BE REBUILT! + +- Lost the unconditional address alignment test in the qsort() data + swapping routine. If the code is built for an 68020 and beyond, it + is replaced by a no-op. + + +c.lib 1.141 (14.7.2004) + +- Rewrote the buffered file I/O code, and in particular how the read + access interacts with the file's state information. Rather than + counting how many bytes can be read from the buffer still, the + new code checks the buffer position against the number of bytes + stored in the buffer. This makes maintenance easier since only + one state variable needs to be modified at a time. + + Note that this means that code which would use the getc() macro + needs to be rebuilt! + +- The pid_t type used by kill() and returned by getpid() is now + really a Process address pointer. It used to be a CLI number. + + +c.lib 1.140 (12.7.2004) + +- The stack alignment code used when reallocating new stack space and + swapping it with the current configuration pushed the end of the + stack beyond the boundaries of the allocated stack. This crashed + in no time at all, but sometimes it just about worked without + blowing up. The fixed code is simpler than before and now initializes + both the lower and the upper stack boundaries to be aligned to + multiples of 16 bytes. + + +c.lib 1.139 (11.7.2004) + +- snprintf/vsnprintf were broken: instead of limiting output to + the size given as a parameter, data beyond the end of the buffer + was trashed. + + +c.lib 1.138 (11.7.2004) + +- Greatly simplified the vfscanf() code. Added new code which + initializes each parameter before the conversion begins. + This should help software which tosses data at scanf() + and expects it to come back initialized without checking for + the function's return code. + +- The vfscanf() '%f' conversion method could have consumed one + more character than it was really allowed to. Fixed. + +- If vfscanf() is built without floating point support, the + '%f' conversion method now properly pulls the respective + floating point number from the stack but performs no + conversion and does not modify the contents of the + variable. + + +c.lib 1.137 (11.7.2004) + +- Moved the initialization for the stack size checking out + of the _main() code and into its own initialization function + where it belongs. That way, the test also works for programs + that detach from the shell. + +- The '%g' and '%G' vfprintf() format specifiers now have the + effect of stripping trailing 0 and . characters in the number + string produced. Previously, this effect was also enabled for + the '%f', '%e' and '%E' formats. + +- Greatly simplified the vfprintf() code and verified that the + output matches the requirements. + + +c.lib 1.136 (9.7.2004) + +- Dropped in loads more of assertions to check the validity of + files and descriptors. + + +c.lib 1.135 (6.7.2004) + +- Fixed the last two issues in puts() and fputs() caused by the + bug fix I made to fputc() which would not return the character + value passed in. Occasionally, this could cause puts() to omit + the trailing '\n'. + + +c.lib 1.134 (4.7.2004) + +- Simplified and reordered the init/exit procedure in "stdlib_main.c". + Initializations which could be done on the spot when required are + no longer performed that early on. The stdio initialization is + performed earlier so that error messages can be printed using + stdio methods. + +- A stack overflow can no longer turn into an infinite loop. + +- Removed some more redundant data from the memory management data + structures. + +- The temporary file cleanup in fclose() did not properly turn off + profiling. Fixed. + +- Both close() and fclose() now fill their data structures with 0 + bytes before they return. + +- The tables for the file descriptors and buffered files are now + allocated dynamically. + +- If the asynchronous I/O options is not in effect, then the + global file data structures will not include a pointer to + the AsyncFile. + +- Lost some duplicate code from the locale cleanup routines. + +- Simplified the code that picks a vacant file descriptor table + slot. + +- NOTE: YOU NEED TO REBUILD THE ENTIRE LIBRARY IF YOU WANT TO USE + THESE CHANGES! + + +c.lib 1.133 (4.7.2004) + +- The memory routines no longer look up the management data structures + before they deallocate or modify an allocated memory chunk. This is + now done only in the debug version of the library. + +- Moved the code that performs memory deallocations in the debug and + nodebug versions of the library. Instead of separate functions, a + single common routine is used. + +- When launched from shell, the program's name is no longer allocated + through malloc() but through AllocVec(), and released separately later. + This helps the memory debug code which otherwise wouldn't be able to + print meaningful information when starting up and shutting down. + +- You can now get additional information out of the memory debugging + code, covering the locations where memory is allocated and released, + including how much memory is involved. + +- The month and day names used by the time conversion code are now + declared as 'const'. + +- Replaced all uses of the EPERM error code with EACCES. + + + +c.lib 1.132 (26.6.2004) + +- abort() and raise() now call a common termination routine. + +- Chopped the math_kernel.c code into individual files. Some local constant + values had to be duplicated, but so there... + +- Lost "smakefile.old" and "math_kernel.c". + +- Got rid of more compiler warnings... + +- Fixed a typo in the "stdlib_headers.h" header file. + +- In libdebug.a, for 'va_arg()' to work with 'char' type parameters, these must + be picked up as type 'int' from the stack. Otherwise we get a linker error later... + This should finally make the PowerPC 'native' kprintf() function work. + + +c.lib 1.131 (21.6.2004) + +- The '%i' conversion method in the scanf() family did not take + a leading '0' properly into account when updating the number of + letters to be read and processed. + +- If the '%c' conversion method reads fewer than the required + characters, it stops the conversion rather than aborting it + with an error. + +- The scanf() family now watches more carefully what data it still + requires to satisfy a conversion. For example, while it may accept + a '-' character to indicate that a sign is given to the number to + follow, if there is no number to follow will trigger an error + condition. + + +c.lib 1.130 (20.6.2004) + +- The scanf() family now returns EOF if an error was detected + (not just an end of file) or if the stream ended before a + conversion could be performed. + +- The file type reported by stat() did not really take pipes into + account. Fixed. + +- Cleaned up the data structure definitions and references. This turned + up a bug in the Unix<->Amiga path name translation which would use + a local data structure which was larger than the public version. Fixed. + + +c.lib 1.129 (18.6.2004) + +- Added a free memory threshold test feature to malloc(); how it works + is described in . + +- The PowerPC debug.lib now calls RawPutChar() and RawMayGetChar() + through the 68k LVO. This should finally make kprintf() and friends + usable on the PowerPC. + +- The asyncio code now defaults to allocate at least twice as much + memory as a buffered file would require (so that double buffering + can be used). Also, the fundamental asyncio support functions require + that enough memory is allocated to allow for four disk blocks to + be read at a time. + +- When opening a file for asynchronous I/O access, both read-only and + write-only access is supported now. Previously, the functionality + was limited to read-only access. + + +c.lib 1.128 (14.6.2004) + +- Moved the stack size usage reporting code again so that the name of + the program can be printed correctly. Also, the data from the + initial stack size swapping is now cached until it is used. + +- Reordered the resource allocations and initializations in tmpname() + to make error recovery more robust. + + +c.lib 1.127 (13.6.2004) + +- Truncating a file to size 0 was, if successful, considered a failure. + Fixed. + +- ftruncate() no longer changes the file position. + +- Advisory record locking now checks if the lock should be shared or + exclusive and verifies that the file open mode supports this access + mode. + +- Negative record lengths are now supported in the advisory record + locking code. + + +c.lib 1.126 (13.6.2004) + +- Unless Unix path semantics are in use, lseek() no longer defaults + to 'seek and extend' operation. + +- There are no longer two separate functions to take care of 'seek' + and 'seek and extend' operations. + +- The Unix-like lseek() behaviour now takes advantage of cached + file seek position information. Previously, it just ignored it. + +- The 'truncate' file action now makes sure that once the size of + the file has been trimmed, the new file position refers to the + end of the file. There also was a problem with growing the size + of the file which could have started at the wrong file offset. + +- The advisory file locking code now handles integer overflows + gracefully when the end of a locked region is to be calculated. + In this case, the end is assumed to be the (2^31)-1st byte. + Also, when removing a lock the search for the locked region in + question keys off the start position and the length rather than + the start position and the adjusted end position. + +- Added more sanity checks to file system operations which invariably + have to deal with FileHandle->fh_Type. + +- Rewrote the Unix->Amiga path name translation function again. + + +c.lib 1.125 (13.6.2004) + +- Rewrote the Amiga->Unix path name conversion code. Double slashes are + translated more robustly into '../' and the translation of the volume + name and the path to follow it are now done separately. The current + directory name ("") could wind up getting translated to a string pointing + into a local buffer. Fixed. Also, the new code knows how to translate + ":" to a path relative to the current directory (if that directory is + defined by an absolute path name). + +- The code that parsed and initialized the command line parameter + array to be passed to the main() function made different assumptions + during the counting and the initialization of the different parameters. + Fixed. + +- snprintf() and vsnprintf() now handle zero length buffer + sizes properly. + +- The stack size usage measuring code got broken when the + constructor/destructor mechanism was reimplemented. It + now works again. + + +c.lib 1.124 (12.6.2004) + +- Dropped the fseek() optimization for files with a write buffer. This + feature had little impact, but complicated buffer management enormously. + +- In fputc(), __fputc(), fwrite(), __flush(), etc. and the functions which + build upon them flushing the buffer now always takes place before new data + is pushed into the buffer. The exception is fputc()/__fputc() which can + flush the buffer if the file is in line buffering mode and a line feed + character has just been written. Also, failure to flush the buffer now + implies that the character/data to be stored in the respective function + was not successful. Previously, the different functions either stored the + data in the cache before and/or after the buffer was flushed, making it + difficult to tell if it had been written. Which in turn made it impossible + to recover from the failure since you could not be sure if another attempt + to store that data would really store it at the proper file position. + +- mktime() now insists that the year must be 1978 or later. + +- In debug.lib, KPutFmt() and the functions which build upon it now + should work even on the PowerPC. This works by analyzing the format + string and by converting the parameters to fit into a table whose + contents RawDoFmt() can handle. + +- For the asyncio code, all write accesses immediately flushed the buffer, + thus nullifying any advantage the asynchronous I/O might have provided. + Fixed. + +- The optimized memset(), memcpy() and memmove() functions now use + displacement addressing rather than post- and preincrement in the + unrolled loop. This should help strictly pipelined processors. It + does not seem to make any difference at all for the 68060, though. + +- The locale cleanup code now separately closes the specific locales + and the 'all' locale. + + +c.lib 1.123 (12.6.2004) + +- The distribution license no longer requires that for binaries using + the library a mention of the license text is mandatory. + +- closedir() now checks for a NULL pointer and backs out if it finds + one. + +- opendir() now exits with an error if it cannot allocate enough memory + for a volume name to be added to the list. + +- readdir() now checks for a NULL pointer and backs out if it finds one. + +- readdir() no longer builds with volume list scanning code unless + Unix path compatibility is enabled. + +- rewinddir() now ignores a NULL directory pointer. + +- strncmp() now treats the parameters as strings of unsigned characters. + +- strdup() no longer traverses the string to be copied twice to figure + out how much data needs to be copied. + +- strerror() now knows how to produce an error message for error + code 0x80000000. + +- strtol() and strtoul() always need to initialize the 'ptr' + parameter before they exit, not just when they succeed. + +- fputc() did not return the character value written, but 0. Fixed. + +- fputs() now returns EOF if it couldn't flush the write buffer, + if that was necessary. + +- fseek() no longer changes the value of the global 'errno' variable, + as required by the specification. + +- fseek() now sets the buffer position to 0 if the number of bytes that + can be read from the buffer drops to 0. This avoids clashes with write + access to the same file. + +- ftell() now always sets the global 'errno' variable to a well-defined + value. + +- fwrite() now tries to seek back to the original file position if + flushing the buffer failed. This complements similar code in fread(). + +- fwrite() no longer flushes the buffer before it returns. It appears + that this behaviour is not mandated by the specifications. The + buffer will only be flushed upon entry, and even then only to make + room for new data to be stored. + +- fread() now preserves error status information when recovering from + a failed buffer fill attempt. Previously, the error status information + would revert to 'no error' during this task. + +- mktemp() now also adds the current Task address to the seed value that + goes into the creation of the temporary name. + +- If dup2() fails to close a file, if that is necessary, it will return + an error rather than ignoring the failure. + +- Lost a return statement in dup2(). Also, growing the size of the + file descriptor table can now be aborted with ^C. + +- In fcntl(), growing the size of the file descriptor table can now be + aborted with ^C. + + +c.lib 1.122 (1.6.2004) + +- Lost the NULL tests in front of all UnLock() and FreeDeviceProc() calls. + +- The command line is now trimmed, dropping leading and trailing + blank spaces. + +- The ftruncate() functionality did not write 0 bytes to the file + being extended. Fixed. + +- popen() allocated a few bytes less than necessary for the command + name and the parameters. + +- Neither popen() nor system() now quote the command name unless it + is really necessary. + + +c.lib 1.121 (30.5.2004) + +- Made the memory debugging options a little more flexible and easier to + configure. + + +c.lib 1.120 (30.5.2004) + +- The asynchronous I/O code was never actually used by the library. Fixed. + +- Tweaked the realloc() code to take the memory allocation granularity into + account. This means, for example, that for small allocation sizes < 8 bytes + no reallocation will ever be performed since it wouldn't amount to anything. + This complements similiar code in malloc() which also rounds up allocation + sizes to the OS memory allocation granularity limits. + + +c.lib 1.119 (27.5.2004) + +- Got rid of a few compiler warnings involving signed/unsigned integer + comparisons. + +- Fixed a bug in the Unix->Amiga translation routine which would cause + file names such as './../foo' come out as '/foo' and end up being + translated to 'foo:'. The new code now takes care of removing leading + './' and embedded '/./' segments before further processing is + performed on the name string. + +- Fixed up the 68k GNUmakefile so that it builds properly. + + +c.lib 1.118 (26.5.2004) + +- Rewrote those putc/__putc macros again... + +- The vfprintf()/fputs() code did not properly test the result of + the __putc() function call. There should have been a test for + '!= EOF' rather than '== OK'. + + +c.lib 1.117 (26.5.2004) + +- realloc() now checks the size of blocks to be shrunk. If the block + shrinks by less than half its current size, then no new memory + is allocated for it. This saves the need to allocate memory and to + move the data. + +- Implemented an option to have the allocated memory chunks managed + by a balanced tree, sorted by address. This should help applications + which claim a lot of memory, possibly in small chunks, which get + allocated/released a lot. While this is still not quite as good as + having the low level memory management code use buddy lists or + slab allocation, it might still do the trick. This feature is + activated in "stdlib_headers.h" via the __USE_MEM_TREES preprocessor + symbol. You will need to rebuild the files stdlib_data.o, stdlib_free.o, + stdlib_init_exit.o, stdlib_malloc.o, and stdlib_red_black.o if you + change this. + +- The size of the physical memory allocation chunks is now taken into + account when making memory allocations. This means that allocations + are rounded up to multiples of 8 bytes each. + + +c.lib 1.116 (26.5.2004) + +- Reworked the putc/getc macro definitions, moved them behind the + function prototype declarations in . + +- The putc() macro did not return the same result as the equivalent + fputc() function would have done after flushing the buffer. The + new macro now calls a special flush routine which itself safely + returns the last character written. + + +c.lib 1.115 (24.5.2004) + +- Prior to performing ^C checking, the respective routines now verify first + if ^C checking is enabled in the first place. This saves a function call. + +- Replaced all ^C handling code that would drop straight into raise(SIGINT) + with a proper call to __check_abort(), which the user may have set up to + his own liking. + +- The wildcard matching argument list build code no longer defaults to + allow for ^C checking. This is permitted only if the global checking + flag is enabled. + + +c.lib 1.114 (24.5.2004) + +- Replaced most of the internal single character I/O calls with macros. + +- I/O buffers are now allocated so that their start addresses are aligned + to cache line boundaries. + +- Buffer size and position are now both signed integers. This fixes a + tricky issue with the newly-introduced macros and zero length buffer + sizes. + + +c.lib 1.113 (23.5.2004) + +- The 'FILE' structure now has a public part. Flags and layout have changed! + +- Reimplemented getc() and putc() as macros, which helps a lot with some + applications. + +- Added more of the SAS/C internal floating point support code, which makes + sprintf() and friends build even with floating point options enabled. + +- Replaced CheckSignal() with SetSignal(), which helped the ^C checking + code a lot. + + +c.lib 1.112 (23.5.2004) + +- Plugged in the SAS/C code profiling functionality. This works by measuring + calling time intervals and should be very portable. + +- Duplicating file descriptors could lead to trouble if the descriptor + number in question exactly matched the number of descriptors. Fixed. + +- Reactivated code in open() which was disabled for OS4 but which + should have stayed active. + +- Reduced the overhead of the single character input/output routines, + especially when called from within the library. This helped fgets(), + scanf(), fputs() printf() and others. + + +c.lib 1.111 (12.5.2004) + +- chdir() now checks if the object in question is really a directory. + +- Added special tests to a number of Open(), Lock() and Delete() calls + to catch attempts to open "subdirectories" of files. If it happens, + e.g. trying to open when "utility" is a header + file on the search list, errno will be set to ENOTDIR. + + +c.lib 1.110 (10.4.2004) + +- memmove() no longer tries to move large chunks of data if the source + and destination overlap by fewer bytes than can be moved at a time. + The original code should not have done this in the first place, but + it's safer to check rather than to assume that it will work out fine. + + +c.lib 1.109 (9.4.2004) + +- Fixed a bug in the PPC version of setjmp that would trash floating + point registers. + +- Fixed a bug in dup2: If the second fd didn't exist, it would return -1, + which is wrong (it should not close the second fd when it doesn't exist). + +- Added F_DUPFD to fcntl + + +c.lib 1.108 (15.3.2004) + +- Fixed a bug in the printf() family which affected how the %e + output was formed (and by extension, %E, %g and %G). The %e + format must put exactly one digit in front of the decimal + point, followed by the mantissa and the exponent. This worked + fine unless the round-off fudge added to the number caused + an overflow, producing two digits in front of the decimal point. + This has been fixed by checking for an overflow after having + added the round-off fudge and rescaling the result, if + necessary [Andrija Antonijevic]. + + +c.lib 1.107 (15.2.2004) + +- The setjmp() code now actually manages to save and restore the + FPU state in the 68k library form. + +- The SAS/C constructor/destructor invocation finally works. + +- Added an option to cache the current file position, which should + help seek performance. + +- Added targets "version" and "cvs-tag" to the makefiles. + + +c.lib 1.106 (14.2.2004) + +- index() now calls strchr() and rindex() calls strrchr(). + +- strchr() and strrchr() now read each byte of the string to + be searched exactly once. + +- Added optimized versions of memchr() and memcmp(). + +- The optimized versions of memchr(), memcmp(), memcpy(), memmove() + and memset() check first if the amount of data involved justifies + the expense of gearing up to perform an optimized operation. + +- strstr() no longer calls strlen() even once. + + +c.lib 1.105 (12.2.2004) + +- Replaced memcpy(), memmove() and memset() with optimized portable + versions. + + +c.lib 1.104 (11.2.2004) + +- When open() calls Lock() and fails to obtain a correct result, the + error code checking now also covers ERROR_ACTION_NOT_KNOWN (which is + ignored). This should help handlers which are no file systems, such + as PAR: and PIPE:. + +- The file->iob_BufferWriteBytes and file->iob_BufferPosition counters + no longer have to be in sync. In fact, the position can be smaller + than the number of bytes waiting to be written. The buffer flushing + has to take this into account now (it may have to seek back after + having dumped the buffer, which is nasty). + +- Worked Jörg's changes into the fseek() code. This covers two fields: + if possible, an absolute positioning command is converted into a + relative position change; if the current file buffer allows for it, + the buffer access position is updated rather than forcing the buffer + to be flushed to disk/reread. + + +c.lib 1.103 (8.2.2004) + +- The bug fixes in version 1.101 broke ungetc(). Fixed. Also reworked the + sanity checks in ungetc() which previously were performed either out + of order or were entirely missing. + +- Renamed socket_get_socket_descriptor.c to socket_get_descriptor.c to + make it easier to build the library on the Amiga. + + +c.lib 1.102 (22.1.2004) + +- modified string.h to also include strings.h within the non ISO 'C' standard + part. This should make porting of existing applications a bit easier as many + sources only include . As the current string.h anyway defines the + symbols of i.e. bcmp() and bcopy() etc, which should normally also be + in strings.h, I don't see any problem with that. + +- added function macros for stricmp() and strnicmp() to non ISO 'C' standard + part of to make it easier to port applications relying on + stricmp()/strnicmp(). + + +c.lib 1.101 (18.1.2004) + +- Draining an stdio buffer via fgetc/fread, etc. completely before switching + over to using the same buffer for writing data to a file would flop because + one of two important variables did not get reset to zero. This would also + end up trashing the buffer management. New code makes sure that if a read + access ends up setting the number of bytes available for reading from the + buffer to 0, the buffer position is reset to 0 as well. + +- fwrite() now pushes the buffer contents to disk if it has completely + filled up rather than allowing the full buffer to stick around until + another opportunity presents itself to flush it to disk. + + +c.lib 1.100 (18.1.2004) + +- abort() and raise() no longer call fprintf(stderr,..) but rather + use fputs(..,stderr) instead. + +- Updated the copyright text. + + +c.lib 1.99 (28.12.2003) + +- Updated "stdlib_constructor_begin.c" to invoke the SAS/C constructors + and destructors and to make the OS4 specific destructor handling + safer: destructors calling exit() will now cause the next following + destructor function to be called. + + +c.lib 1.98 (23.12.2003) + +- Fixed up Hans-Jörg's previous fix for strncat(). Added comments + explaining as to what this function is supposed to accomplish in + order to avoid making the same mistake again and again. + +- accept() now returns a properly wrapped socket descriptor (thanks to + Marcus!). + +- TODO: fix up the PowerPC destructor code; currently, a destructor + function calling exit() will cause all subsequent destructors to + be either skipped or the entire destructor list to be rerun ad + inifinitum (haven't checked this in detail yet). Change the code to + work more like the 68k version, which plants a setjmp() at the beginning + of the loop and remembers which one was the last destructor called. + + +c.lib 1.97 (15.12.2003) + +- The library can now use constructors and destructors internally. + +- Added the realpath() function. + +- Put the dirent functions back in libc.a. + + +c.lib 1.96 (13.12.2003) + +- gettimeofday() no longer reports microsecond values > 1000000. + + +c.lib 1.95 (13.12.2003) + +- The default memory pool and puddle sizes can now be configured at link + time by defining the __default_pool_size and __default_puddle_size + variables in your program. + +- strncat() no longer eats the last character copied. + + +c.lib 1.94 (9.12.2003) + +- now includes rather than , if + necessary. + +- Changed DoTimer() to allocate the MsgPort and the timerequest from + public memory rather than from the stack (which could be allocated + as private memory). + + +c.lib 1.93 (29.11.2003) + +- Fixed up the Unix->Amiga path name translation code to map "volume:/" style + paths to the virtual root directory. + +- The file operations (open, chmod, mkdir, rmdir, mktemp, chown, unlink, + utime and rename) now watch out for the root directory to come out of a + Unix->Amiga path name translation and will react according to it. + +- access() now also works on the virtual root directory. + + +c.lib 1.92 (28.11.2003) + +- Replaced qsort() with a different, iterative implementation. In terms of + performace it seems to beat everything out there. + +- Tinkered with the select() code again. The local FD_ZERO() implementation + was too smart. It would attempt to optimize the operation by breaking it + down in to series of bytes to be set to zero, followed by individual bits. + This went wrong because this isn't how the fd_set bits are organized. + The code now clears all the long words involved. + +- Updated the fix_datestamp() function which is part of the select() + wrapper. The updated version should be less vulnerable against + overflows. + + +c.lib 1.91 (25.11.2003) + +- Fixed up the dependencies in the makefiles. The libunix.a routines which + would involve the asynchronous I/O code would not get rebuilt if the + associated header file would change. + +- Added extra code to the fd hook function which looks after files that + should be unlinked, but which didn't get deleted at the first attempt + because they were still in use. That extra code checks, after a file is + closed, if the file in question was set up for deletion. This seems to + help the Samba port a lot, which no longer accumulates scores of lock + files in "Samba:log/locks" which get deleted only when smbd exits. + + +c.lib 1.90 (24.11.2003) + +- The wildcard pattern expansion for command line arguments no longer + drops parameters for which there is no match. Instead, the argument + is used as is. With the old behaviour, things like + "-D__interrupt=__attribute__((__interrupt__))" would expand to nothing, + breaking the GCC preprocessor. + +- The special definitions & code that help GCC to build itself are now + enabled through a single line in a local header file. + +- The file descriptor hook now sets errno to EBADF for file descriptors + which are not in use (this used to be ENOSYS). + + +c.lib 1.89 (23.11.2003) + +- The asynchronous file I/O support can now be enabled at library build + time by uncommenting a definition in a single header file. The makefile + dependencies then do the rest... + +- Fixed a bug in the Unix->Amiga path name conversion code. A trailing + "/." in a path name is now stripped. + + +c.lib 1.88 (22.11.2003) + +- alloca() is now included in the library even if GCC is used as the + host compiler. + + +c.lib 1.87 (17.11.2003) + +- truncate() and ftruncate() now safely extend the size of a file by + adding 0 bytes at the end. + + +c.lib 1.86 (17.11.2003) + +- Fixed a bug in the Unix->Amiga name translation which could lead to + a path beginning with "../" to be mistakenly identified as being an + absolute path name starting with "/". + + +c.lib 1.85 (16.11.2003) + +- The realignment code was missing in the FlushAsync() routine. Fixed. + +- The alignment position was not calculated correctly in SeekAsync() + as the wrong variable was involved. Fixed. + +- __umodsi3, __udivsi3, __udivsi4, __modsi3, __divsi3, __divsi4 would + not refer to the proper __UtilityBase library symbol. Fixed. + + +c.lib 1.84 (12.11.2003) + +- Updated the optional asyncio code to return to a block-aligned + file position after seeking in a write-only file. Also added + code to check if read/write access is actually allowed. + +- Multiple inclusion of debug.h no longer leads to trouble. + +- Merged duplicate file advisory lock testing code. + +- The dirent functions are now a part of libunix.a and no longer + appear in libc.a. + +- Advisory file locks can now start beyond the end of the (current) + file and it is possible to lock a region until the end of the file. + Previously, the latter was rejected as an invalid range. + +- If several exactly overlapping regions are locked on a file, + they all are now unlocked by a single call. + +- Replaced the qsort() code. + +- The assertion handling has moved into its own routine which + tries to make sure that the failure message is shown. + +- Rewrote clock() (again) to be much simpler in operation. + +- The opendir/readdir/closedir cleanup code now actually invokes the + closedir() function rather than doing the cleanup job manually. + +- open() no longer tests for delete protection after the file has + been already opened. If it's open, only a possible write protection + may be problematic and ought to be flagged. + +- __drop_iob_read_buffer() now checks if the buffered file is actually + in use. + +- If fseek(..,0,SEEK_CUR) is is called, it no longer results in the + read/write buffers to be dropped. + +- The snprintf() family now returns the proper number of characters + that would have gone into the buffer, if enough room were available. + Previously, it would stop counting after the buffer had filled up. + +- Merged duplicate code around free(). + +- The memory cleanup code now calls the free functions if memory + debugging code is enabled. + +- If the memory debugging code is enabled, allocations and deallocations + will trigger consistency checks now and then (with a likelyhood of + about 6% per operation). + +- mktime() now properly fills in the day of the week. + +- strftime() now expects the format hook code to provide for the NUL- + termination. + +- __translate_amiga_to_unix_path_name() now performs a sanity check + before it proceeds to use the supplied path name. The check is + to make sure that the local buffer does not overflow. Rearranged + code in __translate_unix_to_amiga_path_name() to perform a similar + test. + +- Rewrote the command line wildcard expansion code to use standard + Exec lists rather than the tricky singly linked list stuff, coupled + with tricky pointer arithmetic. If the code crashes, it's now much + easier to tell why. + +- The __usergroup_init() function now returns an error code rather + than dropping into exit() in case of trouble. + +- They 'key' parameter of bsearch() is now of type "void *" rather + than "char *". + + +c.lib 1.83 (5.11.2003) + +- The scanf() family now skips over initial whitespace preceding + data to be converted. Exceptions are the %c, %n and %[ conversions + which are documented not to bother. + + +c.lib 1.82 (4.11.2003) + +- Fixed another bug in the scanf() family. Floating point numbers were + not converted correctly, only the integral part was picked up. + + +c.lib 1.81 (4.11.2003) + +- Added assertions to track trashing of certain global variables. + +- Rewrote the select() wrapper again. It no longer makes assumptions about + the size of the fd_set data structures passed in. The new code is, however, + significantly more complex than it used to be. It uses far less stack space, + though... + + +c.lib 1.80 (29.10.2003) + +- More tweaking for the optional asyncio support. If requested, it's + always enabled for read-only files bound to descriptors, but never + for write-only or read/write access. It's always enabled for buffered + files standard I/O files because there's an fflush() to take care + of pushing the buffer contents to disk. There is no fsync() for + file descriptors which would accomplish the same. + + +c.lib 1.79 (29.10.2003) + +- The optional asyncio code now also sports a function similiar + to fflush() which will write the current contents of the buffer + to the file. + + +c.lib 1.78 (27.10.2003) + +- The asyncio code support is now an optional feature which can be + enabled at library build time by defining the ASYNCIO_SUPPORT + preprocessor symbol. + +- Cleaned up the code that uses the buffered I/O data structure + 'iob', which used to be a much bigger data structure with + a hard-coded buffer attached to it. The buffer is now allocated + dynamically when needed. + + Note that this change requires that the library is rebuilt or the + I/O buffer data structures will cause trouble. + + +c.lib 1.77 (26.10.2003) + +- Worked an updated version of the asyncio code into the library. + File I/O performance will benefit from this if, and only if, a + file is opened either for read or write access only. If both + read and write access are requested for a file, the asyncio layer + will not kick in. Also, in order to enable it, you have to declare + a '__asyncio_buffer_size' variable (see "stdio_asynciobuffersize.c") + somewhere in your program. + + Note that this change requires that the library is rebuilt or the + file descriptor data structures will cause trouble. + + +c.lib 1.76 (22.10.2003) + +- Added to define the macros va_startlinear() and + va_getlinearva(). + + +c.lib 1.75 (20.10.2003) + +- __initialize_fd() and __initialize_iob() now perform the bulk of the + data structure initialization rather than just setting the data to + zero and plugging in a hook function. + + +c.lib 1.74 (19.10.2003) + +- Renamed the global __fd_table variable to __fd to match the buffered + I/O data structure name. + +- Further modifications to make the debug version of the library build + without errors. + +- Moved the stack size usage checking code from _main() into separate + routines which are found in the linker library. + + +c.lib 1.73 (19.10.2003) + +- __grow_fd_table(), __grow_iob_table(), __flush_iob_write_buffer(), + __drop_iob_read_buffer(), __fill_iob_read_buffer() and __open_iob() + now returns 0 for success, -1 otherwise. + +- __grow_fd_table() and __grow_iob_table() now both set errno in + case of failure. + +- Lost the unnecessary file descriptor and buffered I/O table + initializations. + + +c.lib 1.72 (19.10.2003) + +- fopen(), freopen() and fdopen() now all call the same common + routine to set up a buffered stdio stream. Previously, the + fdopen() code was seperate and did things differently from + the rest. + +- Deletion of temporary files upon program exit could lead to + a crash (worst case), but never actually deleted anything. Fixed. + +- The stdio_exit() cleanup function now actually calls into + fclose() and close() rather than doing the same job all over + again manually. + +- Lost code which didn't make much sense in the socket descriptor + hook. Same thing for the temp file cleanup code. + +- dup() now invokes dup2() with the second parameter set to -1. + +- Simplified the duplicate cleanup in close(). + + +c.lib 1.71 (19.10.2003) + +- Added missing prototype for setbuf() in . + +- Put the definition of HUGE_VAL in inside #ifndef, to allow + GCC to do its thing. + + +c.lib 1.70 (18.10.2003) + +- The tests to verify that a file descriptor was valid all had a + problem. This test is now done in a separate function which + performs the necessary error checking. + +- The dup2() function did not close the second file descriptor + prior to duplicating the first one. Also, the dup(..,-1) case + did not return the number of the new file descriptor but -1 + instead. + +- The tests to check whether a Hook is attached to a file + descriptor now set errno to EBADF if no Hook is found. + +- All file descriptor flags are now cleared when a descriptor + is closed. Same thing for buffered files. + + +c.lib 1.69 (14.10.2003) + +- Not all conversions performed by the scanf() family would respect + the maximum field width. Fixed. + +- The local sscanf() file hook function had the last two parameters + reversed. Fixed. + +- strftime() now fills in the week day if it's not provided. + + +c.lib 1.68 (13.10.2003) + +- To activate the memory debugging code, use "#define __MEM_DEBUG". + Other debugging code (assertions) is deactivated through + "#define NDEBUG". + + +c.lib 1.67 (11.10.2003) + +- Reworked the program startup code. Instead of rattling down a number of + initialization functions, one at a time, the whole thing is now performed + through a 'constructor style' table. This ought to be replaced by the + real thing once it's safely possible. + + +c.lib 1.66 (11.10.2003) + +- UtilityBase, LocaleBase, SocketBase and UserGroupBase no longer override + any user defined global variables. The library now keeps them under + private names. + +- The wildcard expansion code would not return an empty argument list in + case no match was found. Fixed. + +- Cleaned up the stdlib_main.c code, moved all the data and function + references into local header files. + +- Completed the usergroup.library API integration for the OS4 variant. + +- The constructors are now called in forward order and the destructors + in reverse order. + +- Moved the constructor/destructor invocation code into a separate file. + + +c.lib 1.65 (9.10.2003) + +- In dev_t is now an unsigned long. + + +c.lib 1.64 (9.10.2003) + +- Bum. The old and the new clock() code was wrong. The clock() function + is supposed to return how much processor time the current process + consumed since it was started, which is a monotonously increasing + number (or something like it, unless the system time is reset). + The new code should deliver proper data, although it might be better + to switch it over to timer.device/ReadEClock. + + +c.lib 1.63 (8.10.2003) + +- Ouch, the old clock() code was correct, it just didn't look like it. + I rewrote it to make it clearer what happens and why it happens like + that [Andrija Antonijevic]. + + +c.lib 1.62 (6.10.2003) + +- A "+" and a "*" had been mixed up in clock(). Fixed. + + +c.lib 1.61 (5.10.2003) + +- Now that main.o is a platform neutral startup code file, it's possible + to do some machine type checks in "stdlib_machine_test.c". This code + checks for presence of an FPU and an MC68020 CPU (or better). It may + not work for -fbaserel32 which by the time the test is performed + will have already crashed. + +- Added the missing stdlib_dosbase.c, stdlib_localebase.c, stdlib_sysbase.c, + stdlib_utilitybase.c and math_init_exit.c files to the repository. + + +c.lib 1.60 (5.10.2003) + +- Renamed the source code files which implement the strtod(), strtol(), + strtoul(), atof(), atoi() and atol() functions. + +- Moved main() out of libc.a and made it into a startup object file + which needs to be added to the GCC specs file in the "*startfile" + section, right at the end of the list. This solves practically all + linking problems I encountered so far. Which means that -lunix + and -lsocket actually work and that you don't have to tweak the + specs file to build the compiler. + + +c.lib 1.59 (4.10.2003) + +- The math initialization/test function is now always invoked by the + _main() function. The math init/exit code defaults to stubs, though, + unless libm.a is linked in. + + +c.lib 1.58 (4.10.2003) + +- Moved the global library base/interface definitions from stdlib_main.c + into separate files, each of which defines a base/interface pair. + +- Moved the math library initialization/testing into libm.a where it + really belongs. The MathIEEE library base definitions went there, + too. + + +c.lib 1.57 (1.10.2003) + +- Calling dup2() on a stdio file reinitialized the source fd instead of the + destination fd. Fixed. + +- Added const declaration to first argument of sscanf(). + +- no longer enforces the inclusion of . + + +c.lib 1.56 (30.9.2003) + +- Moved the scalbn() function prototype into math_pow.c, where it is + used. This is not an ISO 'C' function to start with. + +- strtod(), strtol(), strtoul(), atof(), atoi() and atol() moved + from into . + +- fputs() no longer adds a newline character at the end of the line. + This is now done only by puts(). + +- fdopen(), fopen(), freopen() and popen() no longer mix up file + access mode options such as "r" and "r+". + +- popen() now adds the current time stamp to the name of the + temporary files it opens. + + +c.lib 1.55 (21.9.2003) + +- Added support for 'long long' quantities in the printf/scanf + families. This is not yet enabled by default since I couldn't + seem to make it work on the 68k platform. + + +c.lib 1.54 (18.9.2003) + +- fputs()/puts() didn't add the '\n' character at the end of the + line. Fixed. + + +c.lib 1.53 (25.8.2003) + +- Added hooks for code to perform wildcard expansion for all + command line parameters. Excluded are those parameters which + are surrounded by quotes ("). + + +c.lib 1.52 (19.8.2003) + +- fpos_t is now a scalar data type. + +- size_t is now an unsigned integer. + +- Lost the file descriptor table usage counter. Whether or not a + file descriptor is in use is now indicated by a flag. + +- Temporary buffered files now have a dynamically allocated temporary + file name string attached. Previously, a statically allocated + buffer was part of each file buffer data structure. + +- The order of the hook parameters for the file descriptor and + buffered files was wrong. + +- All the buffered file routines now check if the file in question + is actually in use before they proceed. + +NOTE: the last four changes require a rebuild of the entire library, + just to be safe! + + +c.lib 1.51 (12.8.2003) + +- setvbuf() now sets the buffer size to 0 when switching a stream + into unbuffered mode. Also, with buffering mode _IONBF (no + buffering) no memory is allocated and no supplied buffer is + used. + +- The stdio cleanup code no longer runs all file descriptors and + files through the shutdown code. Only those which are actually + in use. + +- Fixed a typo in the BSD style license text. + +- Cosmetic changes... + +- fopen("a+", ..) did not actually append any data. + +- The unlink() cleanup code didn't unlock the temporary locks + it maintained. + + +c.lib 1.50 (2.8.2003) + +- Rewrote the entire Amiga->Unix and Unix->Amiga name/path translation + code from scratch. It's now much more robust than it used to be. + +- Restored the original difftime() code. + + +c.lib 1.49 (1.8.2003) + +- vfprintf() now treats the '%' format specifier as an escape + character and produces the next following letter as is if that + letter does not indicate a specific format. + + +c.lib 1.48 (31.7.2003) + +- vfprintf() now sets up the buffer it uses for converting numbers + into text every time it goes through the main loop. This means + that a terminating '\0' is placed at the end. + +- vfprintf() now first checks if a floating point number is + +/-infinity or not a number and then performs the '%g' check + to figure out which output format should be used. + +- Fixed the alternate conversion option for precision == 0 and + the %e/%f/%g conversions. + +- In vfprintf(), if there is no digit following the precision + specifier, the precision is now set to 0. + +- In vfscanf() only %c, %s and %[ respond to the maximum field + width option, all other conversion methods ignore it. + +- readdir() again returns the ".." entry for the root + directory. + + +c.lib 1.47 (31.7.2003) + +- Fixed vfscanf() and strtol() again to accept very small negative + integers (-2147483648). The previous check to avoid overflows + was too strict. + + +c.lib 1.46 (31.7.2003) + +- strftime() now makes sure that the string generated is always + NUL-terminated. The formatting code checks if the dates are + in range to avoid accessing invalid day/month table data. + + +c.lib 1.45 (30.7.2003) + +- lseek() could end up freeing a local buffer twice. Fixed. + +- The sscanf() wrapper no longer emulates seek/write. + +- Added some more error checking to the vasprintf() code. + +- Fixed the %h qualifier in vfprintf(). + +- The %d conversion of negative integers in vfprintf() was relying + upon a non-portable operation: the % operator used on negative + numbers was expected to yield a negative result. The new code + tries to be more careful and uses the % operator only on + non-negative numbers. + +- vfprintf() now handles floating point number exponents + gracefully which are larger than 100. + +- Made the varargs handling vfprintf() more portable. + +- vfscanf() could produce an error if a character in the + format string did not exactly match the corresponding + character in the input stream. Now it just pushes the + character back and stops scanning. + +- The %c conversion in vfscanf() never stored more than + one single character. + +- The automatic %d octal number conversion in vfscanf() lost + the first digit following the introducing '0'. Fixed. + +- vfscanf() now properly handles the 0x/0X prefix for the + %x conversion. + +- vfscanf() now only returns EOF if no arguments could be + converted and the EOF status of the stream involved has + been asserted. + +- vsnprintf() no longer tries to skip the trailing NUL byte if + the resulting string is larger than the buffer it would + hold. + +- The memory allocation cleanup code now also properly handles + the extra large debug allocations and cleans up the + alloca() tracking list. + +- Fixed strncpy() and strncat() again not to write too much + data. Also strncat() does not pad the destination buffer. + Neither function is supposed to do anything if the + length parameter is negative. + +- strncmp() now returns 0 if the length parameter is negative. + + +amiga.lib 1.7 (30.7.2003) + +- None of the 68k assembly language files appear in the PowerPC build + any more. Also, none of the functions which use the local CallHook() + appear in the PowerPC build either. + + +c.lib 1.44 (28.7.2003) + +- Files created through open() now get their 'executable' protection + bits cleared when they are closed. + +- mkdir() now sets the protection bits on the directory created. + +- The record locking code now uses shared semaphore locking where + necessary. + +- Added workarounds for NIL: style file handles inthe record locking + code. + +- Preparations to get rid of the file descriptor use counter... + +- __open_iob() no longer calls lseek(). + +- popen() and fdopen() now also ignore the extra access options + separated by a comma. + +- tmpnam() now creates names with up to 10 characters. + +- Lost the special case code for zero length memory allocations. + They now produce NULL result codes. + +- Lost the DosLibrary, LocaleBase and ExecBase definitions where + they were not actually required. + +- strncat() didn't pad the destination string with NUL bytes, + according to spec. Fixed. + +- Fixed the weird strxfrm() to work according to spec. + +- Simplified the asctime() and strftime() code. + +- The "%j" format specifier did not produce exactly three digits + in strftime(). Fixed. + + +amiga.lib 1.6 (28.7.2003) + +- Removed NULL pointer checks from "amiga.lib". Added assertions in + their places. + +- Added tests for IconBase and CxBase to the "amiga.lib" routines. + + +c.lib 1.43 (27.7.2003) + +- readlink() didn't free the DeviceProc structure it could use. + +- More fixes to the record locking code. If a lock/unlock action was + performed on a duplicate of a file descriptor, it wasn't always + guaranteed that all the duplicate/original file descriptors were + affected. + +- Fixed a potential bug in the strncpy() code which could drop into + an infinite loop. + +- Replaced almost all do .. while loops with while .. loops. + + +c.lib 1.42 (27.7.2003) + +- Changed the memcpy(), bcopy(), memmove() and bcopy() code + not to use any assembly language bits. I'm wondering whether + this will have an effect on overall stability. + +- The internal number->string conversion routine used by the + time.lib code had two of its parameters swapped. Fixed. + +- The main() startup code had a bug in the character escape + handling. Everything escaped other than 'e' or 'n' would + terminate the respective command line parameter in place. + +- The shell escape character (default is '*') is now configurable + at compile time, which can help applications ported from the + Unix world.Note that you cannot override the '*' escape character, + you can merely define another valid escape character. + +- Changed how double quotes are used by the main() startup code. + A quoted string is now terminated if there is a blank space + following the final double quote or if the end of the command + line is reached. + + +c.lib 1.41 (26.7.2003) + +- In vfscanf() the '%e', '%f' and '%g' conversions now default again + to 'float' unless a format size specifier is used. Also, the function + no longer 'forgets' that the default conversion is being used, which + could happen if several parameters were to be converted. + +- asctime() now tries to make sure that the conversion process + does not overflow the local buffer. + +- readdir() no longer returns the ".." entry for the root + directory. Also simplified the readdir() cleanup code. + +- open(), stat() and lstat() could leave dangling FileLocks behind. Fixed. + +- dup2() now returns the new file descriptor rather than 0. It also + tries to close the second descriptor if that one is in use and + easy to close. + +- fileno() never returned the associated file descriptor but the + table index of the FILE stream. Fixed. + +- Increased the internal maximum directory/file path length to + 1024 characters. Note that this means that the entire library + will have to be rebuilt! + +- setvbuf() now frees its custom allocated buffer if flushing the + write buffer fails. + +- setenv() now longer permits a NULL 'value' parameter. + +- fdopen() now 'claims' a file descriptor rather than performing + an 'internal' dup() on it. + +- vfscanf() now stops converting the mantissa when it finds + an exponent character in the input stream. + +- vfscanf() now makes sure that the strings it reads are + all NUL terminated while they are being read. If the + conversion is aborted, this will still produce a properly + NUL terminated string. + +- The '%' conversion in vfscanf() no longer exits with an + error if the next character read does not match the + '%s' character. + +- vfprintf() now watches the size of the buffer it uses for + converting numeric data into strings. + +- The file descriptor hook code now initializes the duplicate + when it performs a dup() operation. + +- The record locking support now also extends to duplicated + file descriptors. + +TODO: replace struct fd.fd_UseCount with a flag. + + +net.lib 1.8 (25.7.2003) + +- The select() function was broken in a number of ways. Always was, even + in its original form in the Samba 2.0.7 Amiga emulation library. First, + the except_fd bits could have been set even for files (unlikely, if not + impossible to happen). Second, if sockets and real files were used in + parallel, sockets were preferred and the FD_SETs for the files would + come out as indicating that data was available for reading/writing + (which was wrong). Third, the test loop which checked whether the files + had data waiting to be read never initialized the data structure it + had to use. As a bonus, the new code now also checks if a file is + writable and will then flag its FD_SET bit as "ready for writing". + +- More fixes to select(): in each iteration of the polling code, the + set bits would be cleared that might later be used to check for + new input. This no longer happens. + + +c.lib 1.40 (25.7.2003) + +- fopen() now ignores any open options following the mode string, + separated by comma. + + +c.lib 1.39 (23.7.2003) + +- Ouch! vfprintf() didn't work right for floating point number conversion + (again). The '%g' conversion code didn't work on the PowerPC because + the method employed to figure out which format to use was not portable. + Fixed. The '%f' conversion code would produce no output at all if the + number to be printed was zero and the number of digits following the + comma was zero, too. Fixed. Large numbers didn't come ought right. + Fixed. The '%e' conversion code was ill prepared for converting + negative numbers and sometimes failed to produce digits. Fixed. + +- More trouble. strtod() and, by extension, atof() didn't convert + numbers properly with more than one digit following the mantissa. + Fixed. Same stupid problem in vfscanf(). + +- The '%e', '%f' and '%g' conversions would always default to 'float'. + They now default to 'double'. Use the 'h' or 'L' specifiers if you + want less/more. + + +c.lib 1.38 (23.7.2003) + +- The '%s' and '%[' conversion code in vfscanf() never NUL-terminated + the string just read. Fixed. + + +amiga.lib 1.5 (15.6.2003) + +- CreatePort() didn't fill in the port priority. Fixed. + + +amiga.lib 1.4 (1.5.2003) + +- RangeRand() didn't obey the range parameter's restrictions. Fixed. + + +c.lib 1.37 (3.3.2003) + +- Added an option to allow a program to detach itself from the shell + it was launched from. This option is ignored for residentable + programs. + + +c.lib 1.36 (14.2.2003) + +- Removed redundant code from the routines which deal with buffered + stdio streams. The respective routines now only test for the + buffering type and ignore the buffer size altogether, just like + it's supposed to work. + +- Fixed the vfprintf() %e format output which no longer flips the + sign of the number to be converted until it's safe to do so. + The code to figure out whether %g should be mapped to %e or %f + was unreliable because it could miscount the number of digits in + front of the comma. + +- Updated the code that dumps the stdio buffer in fcntl() before the + set/get lock function is performed. These two should have nothing + in common, though. Let's see what it does. + + +c.lib 1.35 (13.2.2003) + +- When a stdio or plain unbuffered stream is opened, the respective data + structures are reinitialized with default values. Previously, the old + settings could persist and stale data could cause unallocated or + reallocated data to be clobbered. This seems to have been the problem + which eventually broke the Samba port. + +- Added some more code to improve debug output quality. + +- The buffered stdio routines now include some extra safety checking + code in case the buffer data structures get clobbered. Not that this + should happen again... + + +c.lib 1.34 (8.2.2003) + +- The program startup code now opens dos.library and utility.library + before it starts to figure out whether it has sufficient stack space + available or not. This allows the stack size setup callback function + to get its bearings. It also simplifies the startup code a bit. + +- The UtilityBase and LocaleBase library bases will now be cached until + the startup code performs its cleanup duties. This is intended to help + application software which insists on reopening these libraries by + itself all over again. + +- The stdio initialization code now uses the shell's standard error output + stream if one is available. Otherwise, it will open "CONSOLE:" instead, + thereby cloning the console file handle. + + +c.lib 1.33 (2.2.2003) + +- Rewrote the vfprintf() floating point conversion code not to rely + upon floating point to integer conversions which could overflow the + capacity of 32 bit integers. The new code now converts the individual + digits as floating point numbers which then end up getting converted + into integers, which should be safe enough. + +- Simplified the fgets() code a bit. + + +c.lib 1.32 (26.1.2003) + +- The fgets() EOF detection was flawed. Fixed [Andrea Valinotto]. + It now returns NULL if no data was read yet and an EOF condition + was detected. Previously, it would keep returning an empty string. + + +c.lib 1.31 (14.1.2003) + +- Rewrote the floating point conversion code in vfscanf(). The + EOF handling for the data to be parsed was not robust enough. + It aborted scanning altogether if the last data item also + included the last character in the data stream. + +- Now properly counts all characters read in vfscanf() even if + some of them have to be pushed back. + +- Invalid character matches are now pushed back by vfscanf(). + + +c.lib 1.30 (28.12.2002) + +- ungetc() now returns the character pushed back, or EOF if it + could not push anything back. It also clears the end-of-file + indicator. + +- ftell() no longer drops the read/write buffer contents. It now + checks where the current file access pointer is and then adjusts + that position with regard to what's in the read/write buffer. + + +net.lib 1.7 (28.12.2002) + +- The socket file descriptor hook now rejects seek accesses, + setting the proper errno code ESPIPE. + + +net.lib 1.6 (21.12.2002) + +- Turns out that the daemon socket bound to the stdio streams must be + marked as available for reading and writing or Samba won't work. + + +stack.lib 1.2 (18.12.2002) + +- Added code that collects information on how much memory is allocated + for stack extension. That data is printed by the debug library before + it exits. + + +c.lib 1.29 (18.12.2002) + +- strxfrm() and strcoll() did not use the locale.library pragma/inline + header files and thus would not link properly. Fixed. + +- Changed the entry assertions for bcopy(), bsearch(), memcpy(), + memmove(), memset() and bzero() to ignore zero length arrays. + This fixes the GCC port which had alloca(0) followed by bzero(..,0) + in it. + +- malloc() and alloca() now return NULL again for a zero length + allocation. Not sure if this is the way to go... + + +c.lib 1.28 (14.12.2002) + +- setenv() trashed the variable value to be used if the variable and + value names were given in the "variable=value" form. Fixed. + +- Reworked the overflow checking for strtol() and the scanf() family + again. This time it hopefully works as expected. + +- Trying to allocate a memory chunk of size 0 now returns a pointer + to a unique address rather than NULL. I wonder whether this is + really the right thing to do, but it seems to help the compiler. + +- Calling realloc() on a memory chunk with exactly the same size it + was allocated with now returns a pointer to that chunk rather than + NULL. + +- The alloca() memory cleanup code is now triggered from within the + library by a separate function which can be told apart from user + code making the call. + +- Now remembers which local variables were set with putenv()/setenv() + and makes sure that before it exits that they all get removed first. + + +c.lib 1.27 (13.12.2002) + +- The strtol() fix didn't actually fix anything broken, but broke some + working things instead. Fixed. + +- Reworked the overflow checking code in scanf() and strtol() again to + compile without producing warnings. + + +c.lib 1.26 (13.12.2002) + +- strtol() did not set the converted number to the smallest possible + negative integer if the number to convert had a sign. Fixed. + + +c.lib 1.25 (13.12.2002) + +- Added special case code to handle conversion of the smallest long + integer -2147483648 from ASCII string to number. + + +c.lib 1.24 (12.12.2002) + +- vfprintf() couldn't convert -2147483648 into a string. This is what + caused GCC to fail rebuilding itself. Fixed. + + +c.lib 1.23 (12.12.2002) + +- setvbuf() now consistently accepts a size value of 0, whereupon + it will default to "no buffering" mode. + +- Ouch. My "optimization" for unbuffered streams did not work if the + buffer size was set to zero. Fixed. + + +c.lib 1.22 (12.12.2002) + +- The buffered file I/O routines no longer take care of appending + data to the end of the file. This is now done entirely by the + file descriptor layer. + +- fread() could in unbuffered mode end up reading partial elements + from the file. It now backs up to change the file position to take + the exact number of records into account that should have been + read. + +- setvbuf() now frees the custom file buffer before replacing it + with a user supplied buffer. + +- stderr is no longer buffered by default (as it should be). However, + optimizations are in place to make vfprintf() and fputs() queue their + output until they return. + + +net.lib 1.5 (12.12.2002) + +- Replaced the inline header files. + +- When launched as a daemon from inetd or similar, the daemon socket + passed to the startup code is now adopted for stdin. Previously, + three new sockets were duplicated from the daemon socket. Also, + the three stdio streams are no longer buffered by default. The + file descriptor setup now matches the standard I/O setup in that + stdin can be read from and stdout/stderr can be written to. + + +c.lib 1.21 (10.12.2002) + +- The path name translation code could end up clobbering the original + string. Fixed. + +- The command name translation in system() did not work right. It + ended up translating the entire string which bombed with very + long command lines. Same problem for popen(), same fix. + +- Updated the Unix name translation code to bail out of the string + to translate is too long to be translated in the first place. + Previously, it just trashed the stack :( + +- system() now calls SystemTagList() with SYS_UserShell=TRUE. + +- Fixed up the header files so that function pointers for the debug + routines actually work. This became apparent when I was trying to + rebuild the binutils with the clib2. + +- The header file no longer pulls in + by default. If it hasn't been included yet, then only the timeval + structure is defined. + + +c.lib 1.20 (8.12.2002) + +- The stdio buffered file I/O routines now clear their error indicators + before work begins. + +- Simplified the code to back the lseek() function. It no longer calls + Seek() twice if the file position does not change. + +- fgetc() and fputc() now set errno to EBADF if the file in question + cannot be read from or written to, respectively. + + +amiga.lib 1.3 (8.12.2002) + +- The name of the memory pool is now placed at an odd memory location. + + +c.lib 1.19 (4.12.2002) + +- index()/rindex()/strchr()/strrch() now perform signed byte + comparisons. These used to be unsigned. + +- Added a cast to memchr() to make sure that the comparison + is performed on unsigned bytes. + +- fseek() and fsetpos() now clear the file EOF condition. + + +c.lib 1.18 (29.11.2002) + +- ftruncate() no longer works for files which aren't open for writing. + +- Simplified the __show_error() code. + +- When allocating a custom buffer, setvbuf() didn't actually fill in + the allocated buffer's address, causing data to be trashed. Fixed. + Setting the buffer size to zero now works only for the + "don't buffer" mode. If the buffer size was changed, the previous + buffer was not flushed to disk before. + +- If an attempt to flush a file write buffer fails, the next attempt + to put data into the buffer will retry flushing the buffer. + Previously, data would have been written beyond the bounds of the + buffer. + +- If fgets() hits an error, it now NUL terminates the string + to be on the safe side. + +- Lost the (disabled) asyncio code. + +- The startup file for SMALL_DATA32 mode did not set up register A4 + at all. Ouch. + + +amiga.lib 1.2 (29.11.2002) + +- Fixed the RVI code to look & work more like the original implementation. + + +m.lib 1.2 (7.11.2002) + +- pow() called the IEEEDPPow() LVO with the x/y parameters reversed. + Actually, IEEEDPPow() seems to be the one to blame [Andrija Antonijevic]. + +- __fixunsdfsi() and __fixunssfsi() had a cast in the wrong place. + The original libnix functions these were based on were still + correct [Andrija Antonijevic]. + + +m881.lib 1.2 (7.11.2002) + +- __fixunsdfsi() and __fixunssfsi() had a cast in the wrong place. + The original libnix functions these were based on were still + correct [Andrija Antonijevic]. + + +c.lib 1.17 (7.11.2002) + +- ftell() now returns the current file position rather than invoking + fseek(), which does something different altogether [Andrija Antonijevic]. + +- fgetpos() now calls ftell() [Andrija Antonijevic]. + +- fsetpos() didn't properly evaluate the return value of fseek() + which would have been -1 in case of error [Andrija Antonijevic]. + +- fseek() now returns 0 for success and -1 for error [Andrija Antonijevic]. + + +c.lib 1.16 (5.11.2002) + +- memcpy() and memmove() had a debug switch wired the wrong way + round, causing the wrong kind of code to be emitted. Code which + could call exec.library/CopyMem and shouldn't have called it. + Fixed. It no longer depends upon exec.library. + +- Removed all the abort signal routines from the string formatting + code. This kind of action is now done solely by the I/O routines. + + +c.lib 1.15 (4.11.2002) + +- sscanf() ended up calling vfprintf(). Ouch. + +- Practically none of the numeric conversion operations in the scanf() + family actually worked. Fixed. + +- scanf() and friends now push a character back upon detecting an + overflow rather than using it and setting the number converted to + MAXINT. + + +c.lib 1.14 (21.10.2002) + +- Rewrote strcasecmp() and strncasecmp() to work more like strcmp() and + strncmp(). Previously, these functions would drop into the utility.library + routines Stricmp() and Strnicmp() which don't work like strcmp() or + strncmp(), respectively. + +- Rewrote the code that closes file descriptors. It should now be much smarter + in handling duplicates. + +- fchmod() invoked the wrong hook action which could lead to a crash. + +- Added wrapper code for ExamineFH() to avoid crashing due to a bug in + dos.library V40 and below with NIL: file handles. + +- The temporary directory locks set up for temporary files were never + unlocked. + +- Submitting an untracked memory region to be freed did not produce the + intended error output. + + +c.lib 1.13 (7.10.2002) + +- The vfprintf() family didn't produce any sign characters at all unless + a field width specifier was used [Andrija Antonijevic]. + + +c.lib 1.12 (28.9.2002) + +- The vfprintf() family got the hexadecimal number conversion (and the pointer + conversion, too) wrong because the conversion string had an extra zero digit + in it [Detlef Würkner]. + + +c.lib 1.11 (15.9.2002) + +- In the printf() family, the default case for '%c' (plain character + output without padding) did not update the length of the string + created [Andrija Antonijevic]. + + +c.lib 1.10 (11.9.2002) + +- In gettimeofday() the important DateStamp() call was missing [Andrija + Antonijevic]. + +- Removed the replacement remainder calculation code. It's not necessary. + + +c.lib 1.9 (7.9.2002) + +- Added replacement code for the two routines the updated compiler will call + in place of the inline '020 math which cannot be used on the '060. This + ought to be done smarter, but this works, too. + + +c.lib 1.8 (28.8.2002) + +- The open() code now avoids calling Lock() on NIL:, which otherwise could + have caused the file open action to follow later to be skipped. + +- Added more compiler internal code to support SAS/C. + +- Increased the size of the memory debugging walls. + +- When reading data off stdin character by character, the stdout and + stderr streams are now flushed first. + + +c.lib 1.7 (27.8.2002) + +- Discovered that ExamineFH() and ChangeMode() will crash on file + handles which refer to "NIL:". Put a workaround for these into + the open() code. + + +c.lib 1.6 (27.8.2002) + +- With the standard I/O streams the vfprintf() code would still add a + terminating NUL byte to each string printed. Fixed. + +- The open() code now checks before it opens if the file in question + can be overwritten, should this be necessary. Likewise, once the + file in question has opened, its protection bits are examined to + verify that the access mode it has been opened for is applicable + in the first place. + +- The asynchronous I/O option now works only for O_RDONLY and O_WRONLY + mode access. + + +c.lib 1.5 (25.8.2002) + +- fread() treated EOF as an error, returning with 0 characters read + from the buffer even if there was still some data in the buffer that + could be read. + +- fread() now seeks back to the last location it could read an entire + element from. Subsequent fgetc() calls will thus pick up the data + not processed by the previous fread() call. Also, if fread() encounters + an error, it seeks back to where the read was supposed to begin. + + +c.lib 1.4 (22.8.2002) + +- Updated the ctype_headers.h, locale_headers.h, math_headers.h, + signal_headers.h, stdio_headers.h, stdlib_headers.h, string_headers.h, + strings_headers.h and time_headers.h header files. The extern library + definitions are now in the SAS/C branch. + +- Moved the __is_daemon definition from unistd.h into dos.h and changed + its type as well. + + +net.lib 1.4 (22.8.2002) + +- Updated the SAS/C compatible prototypes and #pragma definitions. + + +c.lib 1.3 (22.8.2002) + +- Files opened in exclusive access mode are now switched back into + shared access mode for testing. + +- The asynchronous file I/O is now enabled only for read and write + access. Appending is disabled. + +- You now have more control over the asynchronous file I/O and can + enable it on demand and specify the default buffer size. + +- You can now provide for a callback function that initializes the + default stack size to use early on during the runtime configuration + process. + + +net.lib 1.3 (22.8.2002) + +- getgroups() and setgroups() now ignore the second parameter if the + number of groups involved is zero. + +- Upon startup, the runtime environment now sets a global variable + to 1 if the current program was launched by the internet superserver + or an equivalent facility. + + +c.lib 1.2 (21.8.2002) + +- Added sigaddset() and sigemptyset(). + +- isxdigit() didn't work. Fixed. + + +net.lib 1.2 (21.8.2002) + +- Added setpwent(), getpwent(), endpwent(), setgrent(), getgrent() and + endgrent() + + +---------------------------------------------------------------------------- + +amiga.lib 1.1 (20.08.2002) + +- Now bears a version number. + + +c.lib 1.1 (20.08.2002) + +- Now bears a version number. + + +debug.lib 1.1 (20.08.2002) + +- Now bears a version number. + + +m.lib 1.1 (20.08.2002) + +- Now bears a version number. + + +m881.lib 1.1 (20.08.2002) + +- Now bears a version number. + + +net.lib 1.1 (20.08.2002) + +- Now bears a version number. + + +stack.lib 1.1 (20.08.2002) + +- Now bears a version number. + + +unix.lib 1.1 (20.08.2002) + +- Now bears a version number. + + +---------------------------------------------------------------------------- + +- '%f' floating point output now also works for numbers > 9. + +- needs to include and . + +- now only defines a bunch of data types, it no + longer includes any header files. + +- Activated the local bcopy() and ovbcopy() code. + +- Added ACrypt(). + +- Added CreateTask() and DeleteTask(). + +- Added Sebastian's fix for vsprintf(), which did not generate + a '-' at all appropriate times. + +- Added Unix-style directory scanning with pseudo "/" directory + support. + +- Added __stdio_configure_streams() to reconfigure the stream + I/O after the Workbench output window has been opened. + +- Added a local NewList() replacement. + +- Added a plain 68k version of the setjump()/longjmp() pair. + +- Added an extra call to __check_abort() after each + bsdsocket.library call. Because, if a ^C was registered, + causing the respective function call to return, the signal + will still be set, waiting to be picked up. + +- Added assertions to vfscanf(). + +- Added basename(), dirname(), asprintf(), snprintf(), + vasprintf(), vsnprintf(), mkdtemp(), mkstemp(), mktemp(), + putenv(), setenv(), unsetenv(), strcasecmp(), strncasecmp(), + strdup(), gettimeofday() and alloca(). + +- Added data and code to support SAS/C stack overflow checking + and abort. + +- Added further ^C checking to closedir(), opendir(), readdir(), + rewinddir(), creat(), open(), read(), write(), chmod(), fchmod(), + fstat(), lstat(), mkdir(), rmdir(), stat(), fprintf(), fputs(), + ftell(), getc(), getchar(), gets(), __open_iob(), printf(), + putc(), putchar(), puts(), rewind(), setbuf(), sprintf(), + tmpfile(), tmpnam(), vfprintf(), __vfscan(), vprintf(), + vsprintf(), getenv(), system(), strtod(), strtol(), strtoul(), + strftime(), access(), chdir(), chown(), fchown(), fileno(), + ftruncate(), getcwd(), getopt(), lchown(), link(), readlink(), + sleep(), symlink(), truncate(), unlink() and utime(). + +- Added getopt(), kill() and getpid(). + +- Added grp.h and pwd.h header files. + +- Added isatty(). + +- Added more assertions and tests to detect illegal parameters + earlier than before. + +- Added more assertions to strftime(). + +- Added more casts to (size_t) where appropriate. + +- Added more memory debugging hooks to other routines which + implicitly allocate memory and return it. + +- Added more of the GCC specific support routines. + +- Added new __get_a4() and __set_a4() routines to the startup + code. Also put them into the header file. + +- Added platform specific header file. + +- Added popen() and pclose(). + +- Added some more assertions to qsort(). + +- Added some of the bsdsocket.library stubs required for + Samba 2.0.7 to work. + +- Added stack size checking support. + +- Added stack swapping code. + +- Added statfs() and fstatfs(). + +- Added stub code to handle double precision IEEE math. + +- Added support code to emulate the behaviour of debug.lib. + +- Added the Amiga/Unix name translation code. + +- Added the GCC specific floating point runtime library routines. + +- Added the GCC specific startup code. + +- Added the README file. + +- Added the amiga.lib RVI code. + +- Added the hook and method functions from amiga.lib. + +- Added the math support code. + +- Added the memory allocation debugging code. + +- Added the memory pools code to the amiga.lib set. + +- Added the monitoring and debugging code. + +- Added the remaining few amiga.lib 'C' library routines. The + memory pools stuff is probably hopeless, but we'll what I can do. + +- Added the socket I/O wrapper. + +- Added the source code comments to the memory pools source code. + +- Added the stack extension code. It still has to be updated to + be more readable, though. + +- Added the wide character stubs. + +- Added umask(). + +- Added usergroup.library support. + +- All debug output now uses kprintf() again. + +- All memory allocations now use malloc() and free(). + +- Changed the manner in which the floating point support code is + compiled into the library. + +- Changed the name of the preprocessor symbol which activates + the Unix file name semantic support. + +- Changed the names of unused function parameters to match their uses. + +- Changed the way the library is built. We now build seven + different component libraries which all must be linked + separately. + +- Conditional branches no longer bear an 's' or 'w' suffix. + The assembler is supposed to find out all by itself which + one should be picked. + +- File descriptors and I/O buffers now receive the respective + data structures as part of the hook calling packet rather + than having to probe the h_Data contents. + +- Finally figured out what the %n format specifier is supposed + to accomplish in fprintf(). + +- Finally figured out what the __main() reference was good + for and implemented construtor and destructor support. + +- Fixed a bunch of compiler warnings. + +- Fixed more than one bug in sleep(). This time the code + hopefully works as advertized. + +- Fixed several bugs GCC highlighted. + +- Fixed two more compiler warnings related to signed/unsigned + comparisons. + +- For Workbench startup, the stderr stream is now merely an alias + for the stdout stream. + +- Forgot the SAS/C CallHookA() stub. + +- Forgot to add the stubs for the socket and usergroup components. + +- Found and worked around two more code generation problems with + WaitSelect() and recvfrom(). + +- GMT+0 always came out as GMT+ with strftime(). It now stays GMT. + +- If possible, memory pools are used for memory management. + +- In we now define sigset_t rather than in . + +- In CreateTask(), the recovery from a failed AllocEntry() call + was flawed. Reread the exec source code and fixed that bug. + +- In alloca(), no unused memory was ever freed. + +- In listen() a test to see if the file descriptor was really a + socket was missing. + +- In memmove(), the local ovbcopy() code is now smarter about the + registers it has to save. + +- In stat(), lstat() and fstat() the st_dev structure member is + now initialized with the address of the file system's MsgPort + the respective directory/file is stored on. This allows file + descriptors to be compared. + +- In strstr() there is now a test to make sure that the substring + is smaller or equal in size to the big string to be searched in. + +- In vfprintf() the '%g' output format always came out as '%e' if + the precision was uninitialized. Fixed. + +- Instead of passing local variables around to show errors or to + display the current program name, the whole code now uses global + variables. + +- Integrated a modified version of the Commodore asynchronous file + I/O code into the library, mainly for the benefit of Samba. + +- Integrated the default stack size checking variables into the + makefiles. + +- Integrated the extra super elaborate advisory file locking code + which worked so well with Samba. Or did it? With the new library + it appears that opportunistic locks don't work any more. I'm not + so sure if they ever did :( + +- Knocked up replacement functions for amiga.lib and SAS/C runtime + library functions. + +- Looks like Samba needs the super elaborate locking method after + all. Oh well... + +- Modified the startup code and the assembly language fragments + to support the -fbaserel32 option. Built Samba 2.0.7 with it, + which actually seems to work OK. + +- Modified the unistd.h header file to avoid clashes with the + TCP/IP header files. + +- More components are now part of libunix.a to make sure that the right replacement functions are linked in. + +- Moved NewList() into its own source file. This is supposed to + be more compatible with amiga.lib. + +- Moved all the functions which are unimplemented out of the build + files. The old build makefiles are still around, though. + +- Moved the fundamental file descriptor I/O into the stdio branch. + The fcntl branch now only contains stubs. + +- Moved the locale references made in strtod() into the math + libraries, too. + +- Moved the macro definitions into a separate header file. + +- Moved the string hook code into sscanf(). + +- No longer uses the cooked version of for the build. + A local "debug.h" header file is used instead. + +- Now actually compiles and links with GCC. + +- Now builds code for the 68020-60 target rather than 68020-40. + +- Now builds with SAS/C again. + +- Only a single error message should appear during startup, not + a long list of messages for each problem that might appear. + +- Oops. Forgot the constructor/destructor defaults for GCC. + +- Oops. One variable was uninitialized. + +- Plugged in the optimized assembly language data copying code. + +- Preparations for %ll support in vfprintf() and vfscanf(). + +- Rebuilt with GCC, which revealed a problem in calling + AutoRequest(). Fixed. + +- Rebuilt with new GCC inline macros which yield better code. + +- Redid the BOOPSI functions in 'C'. + +- Redid the qsort() code, borrowing snippets from libnix2. + +- Reduced the complexity of fseek() a bit. + +- Renamed stdio_unixsemantics.c to stdio_unixbehaviour.c. + +- Reorganized the libdebug.a source code. Each file now contains + only a single routine. + +- Replaced all unconditional branches with jbra. + +- Restored the old advisory record locking code to see if it + makes a difference. + +- Reviewed the stack extension code and added comments. Now + uses pooled memory allocations instead of AllocMem()/FreeMem() + if possible. + +- Reworked the header file set to key off the compiler used. + +- Reworked the popen() initialization code. + +- Rewrote the ncrt0.S and nrcrt0.S startup code again, trying to + make it simpler. + +- Rewrote the setjmp()/longjmp() code to also save and restore + the floating point register set if there is an FPU installed. + +- Separated the code paths for alloca(), malloc(), realloc() + and free(). They all call intermediate routines to get their + jobs done. + +- Simplified error return codes in many components. + +- Simplified the build makefile. + +- Stack swapping appears to work. + +- Switched compiler options to large data/large code to keep + SAS/C out of my hair. + +- Tested the Unix name semantics translation. + +- The 'e', 'f' and 'g' formatting commands produce no output + the floating point support code is not built into the library. + +- The Amiga/Unix name translation routines now treat "" and "." + special. + +- The FLOATING_POINT_SUPPORT macro definition never checked for + the M68881_FLOATING_POINT_SUPPORT symbol. Fixed. + +- The HUGE_VAL constant now actually refers to a constant floating + point number which the startup code will initialize with 'positive + infinity'. + +- The IEEE math code now compiles properly. + +- The IEEE math libraries are now opened requiring version 33 or + higher. Earlier versions did not support floor() or ceil(). + +- The Unix name translation code now allows for files in /dev to + be accessed. /dev/null, however, is still mapped to NIL:. + +- The __swap_stack_and_call() function never actually loaded A6 + with SysBase. Guess I was lucky... + +- The _main() startup code now displays error messages and is more + careful about mucking with the program's streams and current + directory configuration. + +- The abort() and raise() code now shares the same error message. + +- The abort() code now drops into _exit() rather than relying + upon raise() to do this. + +- The amiga_rexxvars code no longer uses 'fp' in place of 'a5'. + +- The asyncio.c code now uses the local bcopy() routine rather + than calling into CopyMem(). The local bcopy() is a lot faster. + +- The atexit() processing now takes care of all registered + functions, even if exit() is called by one of them. + +- The constructor/destructor support code could crash if no + such functions were present in the binary. Fixed. + +- The conversion of the program startup parameters to a command + vector now works as expected. + +- The debug.h header file now also works with GCC (sort of). + +- The file descriptor duplication is now done in the respective hook. + +- The fundamental lseek() code could trash the current file + position. Fixed. + +- The kgetnum() code did not properly update the character + position for the sign and the digits. Fixed. + +- The libdebug.a code is now fully self contained, so that it may + be linked in last. + +- The log tag initialization in the socket setup code did not work + properly. Fixed. + +- The math routines are now compiled only if the preprocessor + symbols are set up for them to build. + +- The name translation routine in readlink() changed the wrong name. + Fixed. + +- The new test code also prints an integer and a rational number + to test floating point output. + +- The non-blocking console I/O flag was not reset as it should have + been. Fixed. + +- The numeric and collation locale references were still using + the old locale variables. Fixed. + +- The numeric conversion routine used by the time code did not + generate proper ASCII digits. Fixed. + +- The old record locking code needed to be integrated better. + +- The pseudo-root directory containing all volumes is now scanned + entirely within readdir(); opendir() now only collects the + available volume names. + +- The raw I/O routines no longer reference the SysBase variable. + +- The return code of rename() was always the opposite of what + it really should have been. Fixed. + +- The socket code is now compiled conditionally. + +- The special behaviour of remove() and rename() is now a compile + time option. + +- The stack extension setup and cleanup routines are actually + called now. + +- The stack size checking code is no longer built if the stack + extension code is to be used. + +- The stdlib initialization code now attempts to create a memory + pool. This is done exactly once. + +- The time conversion code no longer drops into assert() if the + time stamp is not within the supported Amiga time window. + +- The unlink() and rename() functions can now be configured to + perform vaguely like on a Unix system. + +- There is still something wrong with the built-in functions, so + I disabled them in the makefile. + +- Tried to find a way to allow for ":" to pass through the Unix + file name translation process without being mistaken for the + pseudo-root directory. + +- Triggering a call to exit() while the program is already on the + way out should now be considerably safer than it used to be and + no longer end in recursion. + +- Turned out that in order to be residentable, the constant + __huge_val cannot actually be replaced at runtime with positive + infinity. So the __huge_val is no longer constant, but a cast in + forces it to be. + +- Turns out that the GNU linker visits each library only once. + Bummer. Had to reorganize the source code again and now libnet.a + contains only those special versions of the file access routines + which use Unix-like semantics and behaviour. + +- Updated several instances of signed vs. unsigned comparisons. + +- Updated the GNUMakefil to be more portable and to build all the + library flavours necessary. + +- Updated the object file list. + +- When using socket I/O as a daemon, no error messages are sent to + stderr by abort() or raise(). + +- Whoops. Overlooked two files which should have gone into the + repository much earlier. + +- Workbench startup now opens a default output window. + +- __fixunsdfsi() and __fixunssfsi() didn't actually do anything + useful. Fixed. + +- __locale_exit() should no longer close the same locale twice. + +- __open_iob() now truncates files for "w+" mode. + +- __stdio_exit() and close() should handle closing of an aliased + file descriptor properly now. + +- _main() now checks how much stack space was actually used and + prints that number. + +- access() now always returns an error if a file does not exist. + This fixes open(), which could fail if a file did not exist + even though it should have failed if it existed. + +- assert() now prints the program name. + +- assert() now throughs an Enforcer hit to make bug tracking easier. + +- assert() now uses kprintf() to print its messages. + +- bcopy() no longer calls into memcpy(). + +- bzero() no longer calls into memset(). + +- clock() did not work properly. Fixed. + +- free() and malloc() now mangle the contents of the memory + buffer before they return unless the NDEBUG symbol is defined. + +- free() now also invokes the alloca() drop code. + +- fseek() could end in an assertion if no data had been read from + the file yet. Fixed. + +- fstat() now also works on sockets. + +- getcwd() always trashed memory if "/" was returned. Fixed. + +- getcwd() now takes the / directory into account. + +- index() and rindex() no longer invoke strchr() and strrch(). + +- lseek() returns the file position reached after the file + pointer has been repositioned. + +- mktemp() always changed the wrong string. Fixed. + +- mktemp() ran over the end of the buffer, only that this didn't + really matter up until now. + +- popen() didn't actually compile. Fixed. + +- printf() and friends no longer attempt to NUL terminate streams. + +- qsort() and bsearch() no longer drop into abort() if their + invalid parameters don't matter because there is no data to + examine. + +- readlink() now attempts to let dos.library resolve the path + and then returns an absolute path name. If that doesn't work, + it invokes ReadLink() instead. + +- realloc() no longer needs to know about the manner in which + the allocation itself is managed. + +- remove() now calls unlink(). + +- rename() now returns -1 on error, not 0 as it could have done + accidentally. + +- setvbuf() doesn't really need to go through the memory + allocation debugging code. The memory allocated isn't visible + to the outside. + +- size_t parameters are now tested to see if they might have been + negative integers originally. + +- sleep() tries to be nicer about the timer I/O request in progress. + +- snprintf() now returns the number of characters that would + have been written to the buffer, now matter how many could + really be stored. + +- stat() now makes up pseudo data for the pseudo root directory. + +- statfs() now also knows how to treat the pseudo root directory. + +- strchr() and strrchr() now perform their comparisons on + unsigned characters. + +- strings.h didn't actually compile. Fixed. + +- time() did not add any seconds to the current time. Fixed. + +- tmpnam() could return with AmigaDOS requesters disabled for + the shell. Fixed. + +- unlink() now checks if the file to be deleted has been set up + for deletion before. + +- vfprintf() now uses fputc() to dump strings rather than calling + fwrite(). This has the effect of flushing the buffer properly + if there are line feed characters in the string specified for %s. diff --git a/library/sas_cxamemcpy.asm b/library/sas_cxamemcpy.asm new file mode 100644 index 0000000..42095a0 --- /dev/null +++ b/library/sas_cxamemcpy.asm @@ -0,0 +1,46 @@ +* +* $Id: sas_cxamemcpy.asm,v 1.1.1.1 2004-07-26 16:31:03 obarthel Exp $ +* +* :ts=8 +* +* Portable ISO 'C' (1994) runtime library for the Amiga computer +* Copyright (c) 2002-2004 by Olaf Barthel +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* - Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* - Neither the name of Olaf Barthel nor the names of contributors +* may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* + + section text,code + + xdef __CXAMEMCPY + +__CXAMEMCPY: + + move.b (a0)+,(a1)+ + subq.l #1,d0 + bne.b __CXAMEMCPY + + rts + + end diff --git a/library/sas_cxamemset.asm b/library/sas_cxamemset.asm new file mode 100644 index 0000000..cdc4033 --- /dev/null +++ b/library/sas_cxamemset.asm @@ -0,0 +1,89 @@ +* +* $Id: sas_cxamemset.asm,v 1.1.1.1 2004-07-26 16:31:03 obarthel Exp $ +* +* :ts=8 +* +* Adapted from reassembled SAS/C runtime library code. +* + + section text,code + + xdef __CXAMEMSET + +__CXAMEMSET: + + cmpi.l #$18,d1 + blt.s L2A + +L10: move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + subi.l #$18,d1 + cmpi.l #$18,d1 + bge.s L10 + +L2A: add.w d1,d1 + move.w L34(pc,d1.w),d1 + jmp L34(pc,d1.w) + +L34: dc.w $66 + dc.w $58 + dc.w $4A + dc.w $3A + dc.w $64 + dc.w $56 + dc.w $48 + dc.w $38 + dc.w $62 + dc.w $54 + dc.w $46 + dc.w $36 + dc.w $60 + dc.w $52 + dc.w $44 + dc.w $34 + dc.w $5E + dc.w $50 + dc.w $42 + dc.w $32 + dc.w $5C + dc.w $4E + dc.w $40 + dc.w $30 + + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.w d0,(a0)+ + move.b d0,(a0)+ + rts + + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.w d0,(a0)+ + rts + + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.b d0,(a0)+ + rts + + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + move.l d0,(a0)+ + rts + + end diff --git a/library/sas_cxferr.c b/library/sas_cxferr.c new file mode 100644 index 0000000..f3f1978 --- /dev/null +++ b/library/sas_cxferr.c @@ -0,0 +1,19 @@ +/* + * $Id: sas_cxferr.c,v 1.1.1.1 2004-07-26 16:31:03 obarthel Exp $ + * + * :ts=4 + * + * Adapted from SAS/C runtime library code. + */ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +/****************************************************************************/ + +void __stdargs +_CXFERR(int code) +{ + raise(SIGFPE); +} diff --git a/library/sas_cxv.asm b/library/sas_cxv.asm new file mode 100644 index 0000000..e8d7d3f --- /dev/null +++ b/library/sas_cxv.asm @@ -0,0 +1,141 @@ +* +* $Id: sas_cxv.asm,v 1.1.1.1 2004-07-26 16:31:04 obarthel Exp $ +* +* :ts=8 +* +* Adapted from reassembled SAS/C runtime library code. +* + + section text,code + + xdef __CXV25 + xdef __CXV35 + xdef __CXNRM5 + xdef __CXTAB5 + +__CXV25: + + MOVEM.L D2-D5/A1,-(SP) + MOVEQ #0,D4 + MOVEQ #0,D1 + BRA L2C + +__CXV35: + + MOVEM.L D2-D5/A1,-(SP) + MOVEQ #0,D4 + MOVEQ #0,D1 + TST.L D0 + BEQ L54 + BPL L2C + MOVE.W #$8000,D4 + NEG.L D0 + +L2C: CMP.L #$200000,D0 + BCC L44 + MOVE.W #$4120,D5 + JSR __CXNRM5(PC) +L54: MOVEM.L (SP)+,D2-D5/A1 + RTS + +L44: MOVE.W D0,D1 + CLR.W D0 + SWAP D0 + SWAP D1 + MOVE.W #$4220,D5 + JSR __CXNRM5(PC) + MOVEM.L (SP)+,D2-D5/A1 + RTS + +__CXNRM5: + + CMP.L #$20,D0 + BGE L98 + SWAP D0 + SWAP D1 + MOVE.W D1,D0 + CLR.W D1 + SUB.W #$100,D5 + BGE.S __CXNRM5 + BRA LDC + +__CXTAB5: + + dc.b 5 + dc.b 4 + dc.b 3 + dc.b 3 + dc.b 2 + dc.b 2 + dc.b 2 + dc.b 2 + dc.b 1 + dc.b 1 + dc.b 1 + dc.b 1 + dc.b 1 + dc.b 1 + dc.b 1 + dc.b 1 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + +L98: MOVEQ #0,D3 + CMP.L #$2000,D0 + BGE LA8 + LSL.L #8,D0 + ADDQ.W #8,D3 + +LA8: SWAP D0 + TST.W D0 + BNE LB4 + ROL.L #4,D0 + ADDQ.W #4,D3 + +LB4: MOVEQ #0,D2 + MOVE.B __CXTAB5(PC,D0.W),D2 + ROL.L D2,D0 + ADD.W D2,D3 + SWAP D0 + MOVE.L D1,D2 + LSL.L D3,D1 + ROL.L D3,D2 + EOR.W D1,D2 + EOR.W D2,D0 + LSL.W #4,D3 + SUB.W D3,D5 + BLT LDC + SWAP D0 + ADD.W D5,D0 + OR.W D4,D0 + SWAP D0 + RTS + +LDC: NEG.W D5 + LSR.W #4,D5 + MOVE.L D0,D2 + LSR.L D5,D0 + ROR.L D5,D2 + LSR.L D5,D1 + EOR.L D0,D2 + EOR.L D2,D1 + SWAP D0 + EOR.W D4,D0 + SWAP D0 + RTS + + end diff --git a/library/sas_cxv45.asm b/library/sas_cxv45.asm new file mode 100644 index 0000000..b1ebca0 --- /dev/null +++ b/library/sas_cxv45.asm @@ -0,0 +1,143 @@ +* +* $Id: sas_cxv45.asm,v 1.1.1.1 2004-07-26 16:31:04 obarthel Exp $ +* +* :ts=8 +* +* Adapted from reassembled SAS/C runtime library code. +* + + section text,code + + xdef __CXV45 + +__CXV45 + MOVE.L D0,D1 + SWAP D1 + AND.W #$7FFF,D1 + CMP.W #$80,D1 + BLT lbC00003E + CMP.W #$7F80,D1 + BGE lbC000060 + ASR.L #3,D0 + AND.L #$8FFFFFFF,D0 + ADD.L #$38000000,D0 + SWAP D1 + AND.L #7,D1 + ROR.L #3,D1 +lbC00003C + RTS + +lbC00003E + TST.L D1 + BEQ.S lbC00003C + MOVEM.L D2-D5,-(SP) + SWAP D0 + MOVE.W D0,D4 + AND.W #$8000,D4 + MOVE.W #$39D0,D5 + MOVEQ #0,D0 + SWAP D1 + JSR __CXNRM5(PC) + MOVEM.L (SP)+,D2-D5 + RTS + +lbC000060 + ASR.L #3,D0 + OR.L #$7FF00000,D0 + SWAP D1 + AND.L #7,D1 + ROR.L #3,D1 + RTS + +__CXNRM5 + CMP.L #$20,D0 + BGE lbC0000B0 + SWAP D0 + SWAP D1 + MOVE.W D1,D0 + CLR.W D1 + SUB.W #$100,D5 + BGE.S __CXNRM5 + BRA lbC0000F4 + +__CXTAB5 + dc.b 5 + dc.b 4 + dc.b 3 + dc.b 3 + dc.b 2 + dc.b 2 + dc.b 2 + dc.b 2 + dc.b 1 + dc.b 1 + dc.b 1 + dc.b 1 + dc.b 1 + dc.b 1 + dc.b 1 + dc.b 1 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + dc.b 0 + +lbC0000B0 + MOVEQ #0,D3 + CMP.L #$2000,D0 + BGE lbC0000C0 + LSL.L #8,D0 + ADDQ.W #8,D3 +lbC0000C0 + SWAP D0 + TST.W D0 + BNE lbC0000CC + ROL.L #4,D0 + ADDQ.W #4,D3 +lbC0000CC + MOVEQ #0,D2 + MOVE.B __CXTAB5(PC,D0.W),D2 + ROL.L D2,D0 + ADD.W D2,D3 + SWAP D0 + MOVE.L D1,D2 + LSL.L D3,D1 + ROL.L D3,D2 + EOR.W D1,D2 + EOR.W D2,D0 + LSL.W #4,D3 + SUB.W D3,D5 + BLT lbC0000F4 + SWAP D0 + ADD.W D5,D0 + OR.W D4,D0 + SWAP D0 + RTS + +lbC0000F4 + NEG.W D5 + LSR.W #4,D5 + MOVE.L D0,D2 + LSR.L D5,D0 + ROR.L D5,D2 + LSR.L D5,D1 + EOR.L D0,D2 + EOR.L D2,D1 + SWAP D0 + EOR.W D4,D0 + SWAP D0 + RTS + + end diff --git a/library/sas_cxv54.asm b/library/sas_cxv54.asm new file mode 100644 index 0000000..7493938 --- /dev/null +++ b/library/sas_cxv54.asm @@ -0,0 +1,114 @@ +* +* $Id: sas_cxv54.asm,v 1.1.1.1 2004-07-26 16:31:04 obarthel Exp $ +* +* :ts=8 +* +* Adapted from reassembled SAS/C runtime library code. +* + + section text,code + + xdef __CXV54 + xref __CXFERR + +__CXV54 + MOVEM.L A0/A1,-(SP) + MOVE.L D4,A0 + SWAP D0 + MOVE.W D0,D4 + AND.W #$8000,D4 + EOR.W D4,D0 + SUB.W #$3800,D0 + CMP.W #$10,D0 + BLT lbC000098 + CMP.W #$FEF,D0 + BLT lbC000102 + CMP.W #$47F0,D0 + BLT lbC000058 + SWAP D0 + LSL.L #3,D0 + ROL.L #3,D1 + AND.L #7,D1 + EOR.L D1,D0 + SWAP D0 + OR.W #$7F80,D0 + BRA lbC000112 + +lbC000058 + CMP.W #$FF0,D0 + BGE lbC000074 + CMP.L #$FFFF0FEF,D0 + BNE lbC000102 + CMP.L #$F0000000,D1 + BCS lbC000102 +lbC000074 + MOVEM.L D0/D1/A0/A1,-(SP) + PEA 2.L + JSR __CXFERR + ADDQ.W #4,SP + MOVEM.L (SP)+,D0/D1/A0/A1 + MOVE.L #$7F80,D0 + EOR.W D4,D0 + SWAP D0 + MOVEQ #0,D1 + BRA lbC000116 + +lbC000098 + CMP.W #$FE90,D0 + BGE lbC0000C4 + ADD.W #$3800,D0 + OR.L D1,D0 + BEQ lbC000112 + MOVEM.L D0/D1/A0/A1,-(SP) + PEA 1.L + JSR __CXFERR + ADDQ.W #4,SP + MOVEM.L (SP)+,D0/D1/A0/A1 + MOVEQ #0,D0 + BRA lbC000112 + +lbC0000C4 + MOVE.L D5,A1 + MOVE.W D0,D5 + AND.W #15,D0 + EOR.W #$10,D0 + SWAP D0 + ASR.W #4,D5 + ADDQ.W #2,D5 + BGE lbC0000E6 + NEG.W D5 + LSR.L D5,D0 + MOVEQ #0,D5 + ADDX.L D5,D0 + BRA lbC0000F6 + +lbC0000E6 + CLR.W D1 + LSL.L D5,D0 + ADDQ.W #1,D5 + ROXL.L D5,D1 + AND.L #15,D1 + ADDX.L D1,D0 +lbC0000F6 + MOVE.L A1,D5 + SWAP D0 + EOR.W D4,D0 + SWAP D0 + BRA lbC000116 + +lbC000102 + SWAP D0 + LSL.L #3,D0 + ROXL.L #4,D1 + AND.L #7,D1 + ADDX.L D1,D0 + SWAP D0 +lbC000112 + EOR.W D4,D0 + SWAP D0 +lbC000116 + MOVE.L A0,D4 + MOVEM.L (SP)+,A0/A1 + RTS + + end diff --git a/library/sas_profile.c b/library/sas_profile.c new file mode 100644 index 0000000..9e9e018 --- /dev/null +++ b/library/sas_profile.c @@ -0,0 +1,319 @@ +/* + * $Id: sas_profile.c,v 1.1.1.1 2004-07-26 16:31:04 obarthel Exp $ + * + * :ts=4 + * + * Adapted from SAS/C runtime library code. + */ + +#include +#include +#include + +#include + +/****************************************************************************/ + +#define __NOLIBBASE__ +#define __NOGLOBALIFACE__ + +#include +#include + +/****************************************************************************/ + +extern struct Library * SysBase; + +/****************************************************************************/ + +#include "macros.h" +#include "debug.h" + +/****************************************************************************/ + +struct SPROFMSG +{ + struct Message message; + + struct Process * process; + ULONG clock_value; + char * id; + ULONG stack_pointer; + ULONG flags; +}; + +/****************************************************************************/ + +/* Values for the 'flags' field of SPROFMSG */ +#define SPROF_INIT 0x00000001 /* Initialize connection */ +#define SPROF_ENTRY 0x00000002 /* Function entry */ +#define SPROF_EXIT 0x00000004 /* Function exit */ +#define SPROF_TERM 0x00000008 /* Terminate connection, program continues */ +#define SPROF_ABORT 0x00000010 /* Abort program */ +#define SPROF_DENIED 0x00000020 /* Connection refused */ + +/****************************************************************************/ + +static struct Library * TimerBase; + +/****************************************************************************/ + +static struct MsgPort * profiler_port; +static struct MsgPort * reply_port; + +static struct MsgPort * time_port; +static struct timerequest * time_request; + +static struct Process * this_process; + +static struct EClockVal start_time; +static ULONG eclock_frequency; +static struct EClockVal last_time; +static ULONG overhead; + +static ULONG num_messages_allocated; + +static BOOL initialized; + +/****************************************************************************/ + +static int send_profiler_message(ULONG clock_value, char *id, ULONG flags); +static ULONG get_current_time(void); +static void update_overhead(void); +static void __profile_init(void); +static void __profile_exit(void); + +/****************************************************************************/ + +void ASM _PROLOG(REG(a0, char *id)); +void ASM _EPILOG(REG(a0, char *id)); + +/****************************************************************************/ + +static int +send_profiler_message(ULONG clock_value,char * id,ULONG flags) +{ + extern long __builtin_getreg(int); + + struct SPROFMSG * spm; + int result = -1; + + spm = (struct SPROFMSG *)GetMsg(reply_port); + if(spm != NULL) + { + if(flags != SPROF_TERM && spm->flags == SPROF_TERM) + { + PutMsg(reply_port,(struct Message *)spm); + + __profile_exit(); + goto out; + } + } + else + { + spm = AllocMem(sizeof(*spm),MEMF_ANY|MEMF_PUBLIC|MEMF_CLEAR); + if(spm == NULL) + { + __profile_exit(); + goto out; + } + + spm->message.mn_Length = sizeof(*spm); + spm->message.mn_ReplyPort = reply_port; + spm->process = this_process; + + num_messages_allocated++; + } + + spm->clock_value = clock_value; + spm->id = id; + spm->stack_pointer = __builtin_getreg(15); /* getreg(REG_A7) */ + spm->flags = flags; + + PutMsg(profiler_port,(struct Message *)spm); + WaitPort(reply_port); + + result = OK; + + out: + + return(result); +} + +/****************************************************************************/ + +static ULONG +get_current_time(void) +{ + ULONG result; + + ReadEClock(&last_time); + + result = (last_time.ev_lo - start_time.ev_lo - overhead) / eclock_frequency; + + return(result); +} + +/****************************************************************************/ + +static void +update_overhead(void) +{ + struct EClockVal ev; + + ReadEClock(&ev); + + overhead += (ev.ev_lo - last_time.ev_lo); +} + +/****************************************************************************/ + +void ASM +_PROLOG(REG(a0,char * id)) +{ + if(initialized) + { + if(send_profiler_message(get_current_time(),id,SPROF_ENTRY) == OK) + update_overhead(); + } +} + +/****************************************************************************/ + +void ASM +_EPILOG(REG(a0,char * id)) +{ + if(initialized) + { + if(send_profiler_message(get_current_time(),id,SPROF_EXIT) == OK) + update_overhead(); + } +} + +/****************************************************************************/ + +static void +__profile_init(void) +{ + struct SPROFMSG * spm; + BOOL ready = FALSE; + + this_process = (struct Process *)FindTask(NULL); + + time_port = CreateMsgPort(); + if(time_port == NULL) + goto out; + + time_request = (struct timerequest *)CreateIORequest(time_port,sizeof(*time_request)); + if(time_request == NULL) + goto out; + + if(OpenDevice(TIMERNAME,UNIT_ECLOCK,(struct IORequest *)time_request,0) != OK) + goto out; + + TimerBase = (struct Library *)time_request->tr_node.io_Device; + + reply_port = CreateMsgPort(); + if(reply_port == NULL) + goto out; + + Forbid(); + + profiler_port = FindPort("SPROF_Profiler"); + if(profiler_port == NULL) + { + Permit(); + + goto out; + } + + if(send_profiler_message(0,NULL,SPROF_INIT) != OK) + { + Permit(); + + goto out; + } + + initialized = TRUE; + + Permit(); + + while((spm = (struct SPROFMSG *)GetMsg(reply_port)) == NULL) + WaitPort(reply_port), + + PutMsg(reply_port,(struct Message *)spm); + + if(spm->flags == SPROF_DENIED || spm->flags == SPROF_TERM) + goto out; + + eclock_frequency = ReadEClock(&start_time) / 1000; + + ready = TRUE; + + out: + + if(NOT ready) + __profile_exit(); +} + +/****************************************************************************/ + +static void +__profile_exit(void) +{ + if(initialized) + { + send_profiler_message(0,NULL,SPROF_TERM); + + initialized = FALSE; + } + + if(reply_port != NULL) + { + struct SPROFMSG * spm; + + while(num_messages_allocated > 0) + { + while((spm = (struct SPROFMSG *)GetMsg(reply_port)) == NULL) + WaitPort(reply_port), + + FreeMem(spm,sizeof(*spm)); + + num_messages_allocated--; + } + + DeleteMsgPort(reply_port); + reply_port = NULL; + } + + if(time_request != NULL) + { + if(time_request->tr_node.io_Device != NULL) + CloseDevice((struct IORequest *)time_request); + + DeleteIORequest((struct IORequest *)time_request); + time_request = NULL; + } + + if(time_port != NULL) + { + DeleteMsgPort(time_port); + time_port = NULL; + } +} + +/****************************************************************************/ + +PROFILE_CONSTRUCTOR(profile_init) +{ + __profile_init(); + + CONSTRUCTOR_SUCCEED(); +} + +/****************************************************************************/ + +PROFILE_DESTRUCTOR(profile_exit) +{ + __profile_exit(); +} diff --git a/library/signal_checkabort.c b/library/signal_checkabort.c new file mode 100644 index 0000000..1dd91eb --- /dev/null +++ b/library/signal_checkabort.c @@ -0,0 +1,49 @@ +/* + * $Id: signal_checkabort.c,v 1.1.1.1 2004-07-26 16:31:04 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +/****************************************************************************/ + +void +__check_abort(void) +{ + if(__check_abort_enabled && FLAG_IS_SET(SetSignal(0,SIGBREAKF_CTRL_C),SIGBREAKF_CTRL_C)) + raise(SIGINT); +} diff --git a/library/signal_data.c b/library/signal_data.c new file mode 100644 index 0000000..606a730 --- /dev/null +++ b/library/signal_data.c @@ -0,0 +1,61 @@ +/* + * $Id: signal_data.c,v 1.1.1.1 2004-07-26 16:31:04 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +/****************************************************************************/ + +signal_handler_t __signal_handler_table[NUM_SIGNALS] = +{ + SIG_DFL, + SIG_DFL, + SIG_DFL, + SIG_DFL, + SIG_DFL, + SIG_DFL +}; + +/****************************************************************************/ + +int __signals_blocked; + +/****************************************************************************/ + +BOOL __check_abort_enabled = TRUE; + +/****************************************************************************/ + +BOOL __termination_message_printed; +BOOL __termination_message_disabled; diff --git a/library/signal_headers.h b/library/signal_headers.h new file mode 100644 index 0000000..c1478fb --- /dev/null +++ b/library/signal_headers.h @@ -0,0 +1,94 @@ +/* + * $Id: signal_headers.h,v 1.1.1.1 2004-07-26 16:31:05 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SIGNAL_HEADERS_H +#define _SIGNAL_HEADERS_H + +/****************************************************************************/ + +#include + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include +#include +#include +#include +#include + +/****************************************************************************/ + +#include "macros.h" +#include "debug.h" + +/****************************************************************************/ + +#define NUM_SIGNALS (SIGTERM - SIGABRT + 1) + +/****************************************************************************/ + +typedef void (*signal_handler_t)(int sig); + +/****************************************************************************/ + +extern signal_handler_t __signal_handler_table[NUM_SIGNALS]; + +/****************************************************************************/ + +extern int __signals_blocked; + +/****************************************************************************/ + +extern BOOL __termination_message_printed; +extern BOOL __termination_message_disabled; + +/****************************************************************************/ + +extern const char __abnormal_program_termination[]; + +/****************************************************************************/ + +#ifndef _STDLIB_PROTOS_H +#include "stdlib_protos.h" +#endif /* _STDLIB_PROTOS_H */ + +/****************************************************************************/ + +#endif /* _SIGNAL_HEADERS_H */ diff --git a/library/signal_kill.c b/library/signal_kill.c new file mode 100644 index 0000000..2a4b84e --- /dev/null +++ b/library/signal_kill.c @@ -0,0 +1,120 @@ +/* + * $Id: signal_kill.c,v 1.1.1.1 2004-07-26 16:31:05 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +kill(pid_t pid, int signal_number) +{ + int result = -1; + + ENTER(); + + SHOWVALUE(pid); + SHOWVALUE(signal_number); + + Forbid(); + + if(pid > 0) + { + #if 0 + { + struct Process * cli_process; + + cli_process = FindCliProc((ULONG)pid); + if(cli_process == NULL) + { + SHOWMSG("didn't find the process"); + + errno = ESRCH; + goto out; + } + + SHOWMSG("found the process"); + + if(signal_number == SIGTERM || signal_number == SIGINT) + Signal((struct Task *)cli_process,SIGBREAKF_CTRL_C); + else + SHOWMSG("but won't shut it down"); + } + #else + { + ULONG max_cli_number,i; + BOOL found = FALSE; + + max_cli_number = MaxCli(); + + for(i = 1 ; i <= max_cli_number ; i++) + { + if(FindCliProc(i) == (struct Process *)pid) + { + found = TRUE; + break; + } + } + + if(NOT found) + { + SHOWMSG("didn't find the process"); + + errno = ESRCH; + goto out; + } + + SHOWMSG("found the process"); + + if(signal_number == SIGTERM || signal_number == SIGINT) + Signal((struct Task *)pid,SIGBREAKF_CTRL_C); + else + SHOWMSG("but won't shut it down"); + } + #endif + } + + result = 0; + + out: + + Permit(); + + RETURN(result); + return(result); +} diff --git a/library/signal_raise.c b/library/signal_raise.c new file mode 100644 index 0000000..b485dd4 --- /dev/null +++ b/library/signal_raise.c @@ -0,0 +1,105 @@ +/* + * $Id: signal_raise.c,v 1.1.1.1 2004-07-26 16:31:05 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +/****************************************************************************/ + +int +raise(int sig) +{ + int result = -1; + + ENTER(); + + SHOWVALUE(sig); + + assert( SIGABRT <= sig && sig <= SIGTERM ); + + if(sig < SIGABRT || sig > SIGTERM) + { + SHOWMSG("unknown signal number"); + + errno = EINVAL; + goto out; + } + + if(FLAG_IS_CLEAR(__signals_blocked,(1 << sig))) + { + int table_entry = sig - SIGABRT; + signal_handler_t handler; + + handler = __signal_handler_table[table_entry]; + + /* Revert to the default handler to prevent recursion. */ + __signal_handler_table[table_entry] = SIG_DFL; + + if(handler == SIG_DFL) + { + SHOWMSG("this is the default handler"); + + /* Don't trigger a recursion. */ + __check_abort_enabled = FALSE; + + __print_termination_message((sig == SIGINT) ? "*** BREAK\n" : __abnormal_program_termination); + + SHOWMSG("bye, bye..."); + + /* Note that we drop into the exit() function which + * does not trigger the exit trap. + */ + _exit(EXIT_FAILURE); + } + else if (handler != SIG_IGN) + { + SHOWMSG("calling the handler"); + + (*handler)(sig); + + SHOWMSG("done."); + } + } + else + { + SHOWMSG("that signal is blocked"); + } + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/signal_sigaddset.c b/library/signal_sigaddset.c new file mode 100644 index 0000000..be7d5b4 --- /dev/null +++ b/library/signal_sigaddset.c @@ -0,0 +1,77 @@ +/* + * $Id: signal_sigaddset.c,v 1.1.1.1 2004-07-26 16:31:05 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +sigaddset(sigset_t * set,int sig) +{ + int result = -1; + + ENTER(); + + assert( set != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(set == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + (*set) |= sigmask(sig); + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/signal_sigblock.c b/library/signal_sigblock.c new file mode 100644 index 0000000..caa06cd --- /dev/null +++ b/library/signal_sigblock.c @@ -0,0 +1,59 @@ +/* + * $Id: signal_sigblock.c,v 1.1.1.1 2004-07-26 16:31:05 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +sigblock(int signal_mask) +{ + int result; + + ENTER(); + + SHOWVALUE(signal_mask); + + result = __signals_blocked; + + __signals_blocked |= signal_mask; + + RETURN(result); + return(result); +} diff --git a/library/signal_sigemptyset.c b/library/signal_sigemptyset.c new file mode 100644 index 0000000..63a134f --- /dev/null +++ b/library/signal_sigemptyset.c @@ -0,0 +1,77 @@ +/* + * $Id: signal_sigemptyset.c,v 1.1.1.1 2004-07-26 16:31:06 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +sigemptyset(sigset_t * set) +{ + int result = -1; + + ENTER(); + + assert( set != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(set == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + (*set) = 0; + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/signal_sigmask.c b/library/signal_sigmask.c new file mode 100644 index 0000000..6ea3c4b --- /dev/null +++ b/library/signal_sigmask.c @@ -0,0 +1,62 @@ +/* + * $Id: signal_sigmask.c,v 1.1.1.1 2004-07-26 16:31:06 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +sigmask(int sig) +{ + int result; + + ENTER(); + + SHOWVALUE(sig); + + assert( 0 <= sig && sig <= 31 ); + + if(SIGABRT <= sig && sig <= SIGTERM) + result = (1< + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +/****************************************************************************/ + +void (*signal(int sig, void (* handler)(int)))(int) +{ + int table_entry = sig - SIGABRT; + void (*result)(int) = SIG_ERR; + + ENTER(); + + SHOWVALUE(sig); + SHOWPOINTER(handler); + + if(sig < SIGABRT || sig > SIGTERM || handler == SIG_ERR) + { + SHOWMSG("unsupported signal"); + + errno = EINVAL; + goto out; + } + + result = (void (*)(int))__signal_handler_table[table_entry]; + + __signal_handler_table[table_entry] = (signal_handler_t)handler; + + out: + + RETURN(result); + return(result); +} diff --git a/library/signal_sigprocmask.c b/library/signal_sigprocmask.c new file mode 100644 index 0000000..124cbc1 --- /dev/null +++ b/library/signal_sigprocmask.c @@ -0,0 +1,101 @@ +/* + * $Id: signal_sigprocmask.c,v 1.1.1.1 2004-07-26 16:31:06 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +sigprocmask(int how, const sigset_t *set, sigset_t *oset) +{ + int result = -1; + + ENTER(); + + SHOWVALUE(how); + SHOWPOINTER(set); + SHOWPOINTER(oset); + + if(how < SIG_BLOCK || how > SIG_SETMASK) + { + SHOWMSG("invalid operating mode"); + + errno = EINVAL; + goto out; + } + + if(oset != NULL) + (*oset) = __signals_blocked; + + if(set != NULL) + { + SHOWVALUE(*set); + + switch(how) + { + case SIG_BLOCK: + + SHOWMSG("SIG_BLOCK"); + + __signals_blocked |= (*set); + break; + + case SIG_UNBLOCK: + + SHOWMSG("SIG_UNBLOCK"); + + __signals_blocked &= ~(*set); + break; + + case SIG_SETMASK: + + SHOWMSG("SIG_SETMASK"); + + __signals_blocked = (*set); + break; + } + } + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/signal_sigsetmask.c b/library/signal_sigsetmask.c new file mode 100644 index 0000000..5d5278f --- /dev/null +++ b/library/signal_sigsetmask.c @@ -0,0 +1,59 @@ +/* + * $Id: signal_sigsetmask.c,v 1.1.1.1 2004-07-26 16:31:06 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +sigsetmask(int signal_mask) +{ + int result; + + ENTER(); + + SHOWVALUE(signal_mask); + + result = __signals_blocked; + + __signals_blocked = signal_mask; + + RETURN(result); + return(result); +} diff --git a/library/smakefile b/library/smakefile new file mode 100644 index 0000000..9bf023d --- /dev/null +++ b/library/smakefile @@ -0,0 +1,783 @@ +# +# $Id: smakefile,v 1.1.1.1 2004-07-26 16:31:07 obarthel Exp $ +# +# :ts=8 +# + +############################################################################## + +.c.o: + @echo "Compiling $<" + @sc nover $(CFLAGS) $< + +.asm.o: + @echo "Assembling $<" + @asm $(AFLAGS) $< + +############################################################################## + + OPTIMIZE = optimize opttime optschedule optinline +#DEBUG = debug=line noopt define=CHECK_FOR_NULL_POINTERS +#DEBUG = debug=line +#DEBUG = debug=line define=NDEBUG + DEBUG = debug=sf noopt +#DEBUG = debug=sf noopt define=CHECK_FOR_NULL_POINTERS +#PROFILE = profile + DATA = data=faronly +#CODE = code=far + CPU = cpu=060 +MATH = define=IEEE_FLOATING_POINT_SUPPORT math=IEEE +SUPPORT = define=UNIX_PATH_SEMANTICS define=SOCKET_SUPPORT define=USERGROUP_SUPPORT \ + define=__C_MACROS__ + +############################################################################## + +CFLAGS = \ + idlen=64 idir=include idir=netinclude commentnest \ + $(PROFILE) $(OPTIMIZE) $(CODE) $(DATA) $(CPU) $(MATH) \ + $(SUPPORT) $(DEBUG) + +AFLAGS = \ + -d -m2 + +############################################################################## + +AMIGA_OBJ = \ + amiga_acrypt.o \ + amiga_addtof.o \ + amiga_argarraydone.o \ + amiga_argarrayinit.o \ + amiga_argint.o \ + amiga_argstring.o \ + amiga_beginio.o \ + amiga_callhook.o \ + amiga_callhooka.o \ + amiga_coercemethod.o \ + amiga_createextio.o \ + amiga_createport.o \ + amiga_createstdio.o \ + amiga_createtask.o \ + amiga_deleteextio.o \ + amiga_deleteport.o \ + amiga_deletestdio.o \ + amiga_deletetask.o \ + amiga_domethod.o \ + amiga_dosupermethod.o \ + amiga_dotimer.o \ + amiga_fastrand.o \ + amiga_freeievents.o \ + amiga_hookentry.o \ + amiga_hotkey.o \ + amiga_invertstring.o \ + amiga_newlist.o \ + amiga_rangerand.o \ + amiga_remtof.o \ + amiga_setsuperattrs.o \ + amiga_timedelay.o \ + amiga_waitbeam.o \ + sas_cxamemcpy.o \ + sas_cxamemset.o \ + sas_cxv.o \ + sas_cxv45.o \ + sas_cxv54.o \ + sas_cxferr.o \ + sas_profile.o + +CTYPE_OBJ = \ + ctype_isalnum.o \ + ctype_isalpha.o \ + ctype_isascii.o \ + ctype_iscntrl.o \ + ctype_isdigit.o \ + ctype_isgraph.o \ + ctype_islower.o \ + ctype_isprint.o \ + ctype_ispunct.o \ + ctype_isspace.o \ + ctype_isupper.o \ + ctype_isxdigit.o \ + ctype_tolower.o \ + ctype_toupper.o \ + ctype_table.o + +DEBUG_OBJ = \ + debug.o \ + debug_cmpstrexec.o \ + debug_kcmpstr.o \ + debug_kdofmt.o \ + debug_kgetc.o \ + debug_kgetch1.o \ + debug_kgetch2.o \ + debug_kgetchar1.o \ + debug_kgetchar2.o \ + debug_kgetnum1.o \ + debug_kgetnum2.o \ + debug_kmaygetch.o \ + debug_kmaygetchar.o \ + debug_kprintf1.o \ + debug_kprintf2.o \ + debug_kputc.o \ + debug_kputch1.o \ + debug_kputch2.o \ + debug_kputchar1.o \ + debug_kputchar2.o \ + debug_kputfmt.o \ + debug_kputs1.o \ + debug_kputs2.o \ + debug_kputstr1.o \ + debug_kputstr2.o \ + debug_kvprintf1.o \ + debug_kvprintf2.o \ + debug_level.o + +DIRENT_OBJ = \ + dirent_closedir.o \ + dirent_data.o \ + dirent_opendir.o \ + dirent_readdir.o \ + dirent_rewinddir.o + +ERRNO_OBJ = \ + errno_data.o + +FCNTL_OBJ = \ + fcntl_close.o \ + fcntl_creat.o \ + fcntl_fcntl.o \ + fcntl_lseek.o \ + fcntl_open.o \ + fcntl_read.o \ + fcntl_write.o + +LIBGEN_OBJ = \ + libgen_basename.o \ + libgen_dirname.o + +LOCALE_OBJ = \ + locale_data.o \ + locale_init_exit.o \ + locale_localeconv.o \ + locale_setlocale.o + +MATH_OBJ = \ + math_acos.o \ + math_asin.o \ + math_atan.o \ + math_atan2.o \ + math_ceil.o \ + math_cos.o \ + math_cosh.o \ + math_data.o \ + math_exp.o \ + math_fabs.o \ + math_floor.o \ + math_fmod.o \ + math_frexp.o \ + math_init_exit.o \ + math_ldexp.o \ + math_log.o \ + math_log10.o \ + math_modf.o \ + math_pow.o \ + math_sin.o \ + math_sinh.o \ + math_sqrt.o \ + math_tan.o \ + math_tanh.o + +MOUNT_OBJ = \ + mount_convertinfo.o \ + mount_fstatfs.o \ + mount_statfs.o + +SIGNAL_OBJ = \ + signal_checkabort.o \ + signal_data.o \ + signal_kill.o \ + signal_raise.o \ + signal_sigaddset.o \ + signal_sigblock.o \ + signal_sigemptyset.o \ + signal_sigmask.o \ + signal_signal.o \ + signal_sigprocmask.o \ + signal_sigsetmask.o + +SOCKET_OBJ = \ + socket_accept.o \ + socket_bind.o \ + socket_connect.o \ + socket_data.o \ + socket_gethostbyaddr.o \ + socket_gethostbyname.o \ + socket_gethostid.o \ + socket_gethostname.o \ + socket_getnetbyaddr.o \ + socket_getnetbyname.o \ + socket_getpeername.o \ + socket_getprotobyname.o \ + socket_getprotobynumber.o \ + socket_getservbyname.o \ + socket_getservbyport.o \ + socket_getsockname.o \ + socket_getsockopt.o \ + socket_get_descriptor.o \ + socket_inet_addr.o \ + socket_inet_aton.o \ + socket_inet_lnaof.o \ + socket_inet_makeaddr.o \ + socket_inet_netof.o \ + socket_inet_network.o \ + socket_inet_ntoa.o \ + socket_init_exit.o \ + socket_ioctl.o \ + socket_isdaemon.o \ + socket_listen.o \ + socket_recv.o \ + socket_recvfrom.o \ + socket_recvmsg.o \ + socket_select.o \ + socket_send.o \ + socket_sendmsg.o \ + socket_sendto.o \ + socket_setsockopt.o \ + socket_shutdown.o \ + socket_socket.o \ + socket_hook_entry.o + +STAT_OBJ = \ + stat_chmod.o \ + stat_convertfileinfo.o \ + stat_data.o \ + stat_fchmod.o \ + stat_fstat.o \ + stat_lstat.o \ + stat_mkdir.o \ + stat_rmdir.o \ + stat_stat.o \ + stat_umask.o + +STDIO_OBJ = \ + stdio_asprintf.o \ + stdio_clearerr.o \ + stdio_data.o \ + stdio_dropiobreadbuffer.o \ + stdio_duplicate_fd.o \ + stdio_fclose.o \ + stdio_fdhookentry.o \ + stdio_feof.o \ + stdio_ferror.o \ + stdio_fflush.o \ + stdio_flush.o \ + stdio_fgetc.o \ + stdio_fgetpos.o \ + stdio_fgets.o \ + stdio_filliobreadbuffer.o \ + stdio_findvacantfdentry.o \ + stdio_findvacantiobentry.o \ + stdio_flushiobwritebuffer.o \ + stdio_fopen.o \ + stdio_fprintf.o \ + stdio_fputc.o \ + stdio_fputs.o \ + stdio_fread.o \ + stdio_freopen.o \ + stdio_fscanf.o \ + stdio_fseek.o \ + stdio_fsetpos.o \ + stdio_ftell.o \ + stdio_fwrite.o \ + stdio_getc.o \ + stdio_getchar.o \ + stdio_get_file_descriptor.o \ + stdio_gets.o \ + stdio_growfdtable.o \ + stdio_growiobtable.o \ + stdio_initializefd.o \ + stdio_initializeiob.o \ + stdio_init_exit.o \ + stdio_iobhookentry.o \ + stdio_isinfinity.o \ + stdio_isnotanumber.o \ + stdio_locksemaphorename.o \ + stdio_nostdio.o \ + stdio_openiob.o \ + stdio_perror.o \ + stdio_popen.o \ + stdio_printf.o \ + stdio_putc.o \ + stdio_putchar.o \ + stdio_puts.o \ + stdio_remove.o \ + stdio_rename.o \ + stdio_rewind.o \ + stdio_scanf.o \ + stdio_setbuf.o \ + stdio_setvbuf.o \ + stdio_snprintf.o \ + stdio_sprintf.o \ + stdio_sscanf.o \ + stdio_sscanf_hook_entry.o \ + stdio_tmpfile.o \ + stdio_tmpnam.o \ + stdio_translateioerror.o \ + stdio_ungetc.o \ + stdio_vasprintf.o \ + stdio_vasprintf_hook_entry.o \ + stdio_vfprintf.o \ + stdio_vfscanf.o \ + stdio_vprintf.o \ + stdio_vsnprintf.o \ + stdio_vsnprintf_hook_entry.o \ + stdio_vsprintf.o \ + stdio_vsprintf_hook_entry.o + +STDLIB_OBJ = \ + stdlib_abort.o \ + stdlib_abs.o \ + stdlib_assertion_failure.o \ + stdlib_atexit.o \ + stdlib_atof.o \ + stdlib_atoi.o \ + stdlib_atol.o \ + stdlib_bsearch.o \ + stdlib_calloc.o \ + stdlib_checkdetach.o \ + stdlib_constructor_begin.o \ + stdlib_constructor.o \ + stdlib_constructor_end.o \ + stdlib_data.o \ + stdlib_default_pool_size.o \ + stdlib_default_puddle_size.o \ + stdlib_destructor.o \ + stdlib_detach.o \ + stdlib_dosbase.o \ + stdlib_sysbase.o \ + stdlib_termination_message.o \ + stdlib_threshold.o \ + stdlib_disablerequesters.o \ + stdlib_div.o \ + stdlib_exit.o \ + stdlib_free.o \ + stdlib_getdefstacksize.o \ + stdlib_getenv.o \ + stdlib_getsp.o \ + stdlib_init_exit.o \ + stdlib_isresident.o \ + stdlib_labs.o \ + stdlib_ldiv.o \ + stdlib_main.o \ + stdlib_malloc.o \ + stdlib_machine_test.o \ + stdlib_mkdtemp.o \ + stdlib_mkstemp.o \ + stdlib_mktemp.o \ + stdlib_never_free.o \ + stdlib_putenv.o \ + stdlib_qsort.o \ + stdlib_rand.o \ + stdlib_realloc.o \ + stdlib_red_black.o \ + stdlib_setenv.o \ + stdlib_setjmp.o \ + stdlib_shell_escape.o \ + stdlib_showerror.o \ + stdlib_srand.o \ + stdlib_stackcheck.o \ + stdlib_stackoverflow.o \ + stdlib_stackargbytes.o \ + stdlib_stacksafezone.o \ + stdlib_stacksize.o \ + stdlib_stack_usage.o \ + stdlib_startup.o \ + stdlib_strtod.o \ + stdlib_strtol.o \ + stdlib_strtoul.o \ + stdlib_swapstack.o \ + stdlib_system.o \ + stdlib_unsetenv.o \ + stdlib_wildcard_expand.o + +STRING_OBJ = \ + string_bcmp.o \ + string_bcopy.o \ + string_bzero.o \ + string_index.o \ + string_memchr.o \ + string_memcmp.o \ + string_memcpy.o \ + string_memmove.o \ + string_memset.o \ + string_rindex.o \ + string_strcat.o \ + string_strchr.o \ + string_strcmp.o \ + string_strcoll.o \ + string_strcpy.o \ + string_strcspn.o \ + string_strdup.o \ + string_strerror.o \ + string_strlen.o \ + string_strncat.o \ + string_strncmp.o \ + string_strncpy.o \ + string_strpbrk.o \ + string_strrchr.o \ + string_strspn.o \ + string_strstr.o \ + string_strtok.o \ + string_strxfrm.o + +STRINGS_OBJ = \ + strings_strcasecmp.o \ + strings_strncasecmp.o + +TIME_OBJ = \ + time_asctime.o \ + time_clock.o \ + time_converttime.o \ + time_ctime.o \ + time_data.o \ + time_difftime.o \ + time_gettimeofday.o \ + time_gmtime.o \ + time_localtime.o \ + time_mktime.o \ + time_numbertostring.o \ + time_strftime.o \ + time_time.o + +UNISTD_OBJ = \ + unistd_access.o \ + unistd_chdir.o \ + unistd_chown.o \ + unistd_currentpathname.o \ + unistd_data.o \ + unistd_dup.o \ + unistd_dup2.o \ + unistd_fchown.o \ + unistd_fdopen.o \ + unistd_fileno.o \ + unistd_ftruncate.o \ + unistd_getcwd.o \ + unistd_getopt.o \ + unistd_getpid.o \ + unistd_init_exit.o \ + unistd_isatty.o \ + unistd_lchown.o \ + unistd_link.o \ + unistd_readlink.o \ + unistd_realpath.o \ + unistd_restorepathname.o \ + unistd_setcurrentpath.o \ + unistd_sleep.o \ + unistd_strip_double_slash.o \ + unistd_symlink.o \ + unistd_translatea2u.o \ + unistd_translaterel.o \ + unistd_translateu2a.o \ + unistd_truncate.o \ + unistd_unix_path_semantics.o \ + unistd_unlink.o +# \ +# unistd_wildcard_expand.o + +USERGROUP_OBJ = \ + usergroup_crypt.o \ + usergroup_data.o \ + usergroup_endgrent.o \ + usergroup_endpwent.o \ + usergroup_getegid.o \ + usergroup_geteuid.o \ + usergroup_getgid.o \ + usergroup_getgrent.o \ + usergroup_getgrgid.o \ + usergroup_getgrnam.o \ + usergroup_getgroups.o \ + usergroup_getpass.o \ + usergroup_getpwent.o \ + usergroup_getpwnam.o \ + usergroup_getpwuid.o \ + usergroup_getuid.o \ + usergroup_initgroups.o \ + usergroup_init_exit.o \ + usergroup_rootmode.o \ + usergroup_setegid.o \ + usergroup_seteuid.o \ + usergroup_setgid.o \ + usergroup_setgrent.o \ + usergroup_setgroups.o \ + usergroup_setpwent.o \ + usergroup_setregid.o \ + usergroup_setreuid.o \ + usergroup_setsid.o \ + usergroup_setuid.o + +UTIME_OBJ = \ + utime_utime.o + +############################################################################## + +all: setup c.lib startup.o test fgets_test iotest sscanf_test printf_test stack_size_test translate_test cleanup + +clean: + -delete \#?.o \#?.lib \#?.map test fgets_test iotest sscanf_test printf_test stack_size_test translate_test + +############################################################################## + +setup: + @echo "Setting up include: assignment" + @assign include: include V:include + +cleanup: + @echo "Cleaning up include: assignment" + @assign include: sc:include + +############################################################################## + +version: + copy clone c.lib_rev.rev amiga.lib_rev.rev + copy clone c.lib_rev.rev debug.lib_rev.rev + copy clone c.lib_rev.rev m.lib_rev.rev + copy clone c.lib_rev.rev m881.lib_rev.rev + copy clone c.lib_rev.rev net.lib_rev.rev + copy clone c.lib_rev.rev stack.lib_rev.rev + copy clone c.lib_rev.rev unix.lib_rev.rev + bumprev 1 amiga.lib + bumprev 1 c.lib + bumprev 1 debug.lib + bumprev 1 m.lib + bumprev 1 m881.lib + bumprev 1 net.lib + bumprev 1 stack.lib + bumprev 1 unix.lib + +############################################################################## + +cvs-tag: + cvs -q tag V1_`type c.lib_rev.rev` + +############################################################################## + +test: test.o startup.o c.lib + @echo "Linking $@" + @slink startup.o test.o to $@ lib c.lib addsym \ + map $@.map,fhx fwidth 32 pwidth 32 swidth 32 + +fgets_test: fgets_test.o startup.o c.lib + @echo "Linking $@" + @slink startup.o fgets_test.o to $@ lib c.lib addsym \ + map $@.map,fhx fwidth 32 pwidth 32 swidth 32 + +iotest: iotest.o startup.o c.lib + @echo "Linking $@" + @slink startup.o iotest.o to $@ lib c.lib addsym \ + map $@.map,fhx fwidth 32 pwidth 32 swidth 32 + +sscanf_test: sscanf_test.o startup.o c.lib + @echo "Linking $@" + @slink startup.o sscanf_test.o to $@ lib c.lib addsym \ + map $@.map,fhx fwidth 32 pwidth 32 swidth 32 + +printf_test: printf_test.o startup.o c.lib + @echo "Linking $@" + @slink startup.o printf_test.o to $@ lib c.lib addsym \ + map $@.map,fhx fwidth 32 pwidth 32 swidth 32 + +stack_size_test: stack_size_test.o startup.o c.lib + @echo "Linking $@" + @slink startup.o stack_size_test.o to $@ lib c.lib addsym \ + map $@.map,fhx fwidth 32 pwidth 32 swidth 32 + +translate_test: translate_test.o startup.o c.lib + @echo "Linking $@" + @slink startup.o translate_test.o to $@ lib c.lib addsym \ + map $@.map,fhx fwidth 32 pwidth 32 swidth 32 + +############################################################################## + +c.lib_rev.o : c.lib_rev.c c.lib_rev.h + +amiga_hookentry.o : amiga_hookentry.asm + +amiga_callhooka.o : amiga_callhooka.asm + +stdlib_getsp.o : stdlib_getsp.asm + +stdlib_setjmp.o : stdlib_setjmp.asm + +stdlib_swapstack.o : stdlib_swapstack.asm + +stdio_fdhookentry.o : stdio_fdhookentry.c stdlib_mem_debug.h + +stdlib_data.o : stdlib_data.c stdlib_mem_debug.h + +stdio_openiob.o : stdio_openiob.c stdlib_mem_debug.h + +stdlib_alloca.o : stdlib_alloca.c stdlib_mem_debug.h + +stdlib_calloc.o : stdlib_calloc.c stdlib_mem_debug.h + +stdlib_free.o : stdlib_free.c stdlib_mem_debug.h + +stdlib_init_exit.o : stdlib_init_exit.c stdlib_mem_debug.h + +stdlib_malloc.o : stdlib_malloc.c stdlib_mem_debug.h + +stdlib_realloc.o : stdlib_realloc.c stdlib_mem_debug.h + +stdlib_red_black.o : stdlib_red_black.c stdlib_mem_debug.h + +dirent_closedir.o : dirent_closedir.c stdlib_mem_debug.h + +dirent_opendir.o : dirent_opendir.c stdlib_mem_debug.h + +fcntl_open.o : fcntl_open.c stdlib_mem_debug.h + +socket_select.o : socket_select.c stdlib_mem_debug.h + +stdio_fclose.o : stdio_fclose.c stdlib_mem_debug.h + +stdio_growfdtable.o : stdio_growfdtable.c stdlib_mem_debug.h + +stdio_growiobtable.o : stdio_growiobtable.c stdlib_mem_debug.h + +stdio_init_exit.o : stdio_init_exit.c stdlib_mem_debug.h + +stdio_popen.o : stdio_popen.c stdlib_mem_debug.h + +stdio_setvbuf.o : stdio_setvbuf.c stdlib_mem_debug.h + +stdio_tmpfile.o : stdio_tmpfile.c stdlib_mem_debug.h + +stdlib_atexit.o : stdlib_atexit.c stdlib_mem_debug.h + +stdlib_setenv.o : stdlib_setenv.c stdlib_mem_debug.h + +stdlib_startup.o : stdlib_startup.c stdlib_mem_debug.h + +stdlib_system.o : stdlib_system.c stdlib_mem_debug.h + +stdlib_unsetenv.o : stdlib_unsetenv.c stdlib_mem_debug.h + +unistd_getcwd.o : unistd_getcwd.c stdlib_mem_debug.h + +unistd_unlink.o : unistd_unlink.c stdlib_mem_debug.h + +unistd_wildcard_expand.o : unistd_wildcard_expand.c stdlib_mem_debug.h + +stdlib_main.o : stdlib_main.c + @echo "Compiling $<" + @sc $(CFLAGS) noprofile stdlib_main.c + +sas_profile.o : sas_profile.c + @echo "Compiling $<" + @sc $(CFLAGS) noprofile sas_profile.c + +############################################################################## + +ctype.lib : $(CTYPE_OBJ) + @date to $@ + +debug.lib : $(DEBUG_OBJ) + @date to $@ + +dirent.lib : $(DIRENT_OBJ) + @date to $@ + +errno.lib : $(ERRNO_OBJ) + @date to $@ + +fcntl.lib : $(FCNTL_OBJ) + @date to $@ + +libgen.lib : $(LIBGEN_OBJ) + @date to $@ + +locale.lib : $(LOCALE_OBJ) + @date to $@ + +math.lib : $(MATH_OBJ) + @date to $@ + +mount.lib : $(MOUNT_OBJ) + @date to $@ + +signal.lib : $(SIGNAL_OBJ) + @date to $@ + +socket.lib : $(SOCKET_OBJ) + @date to $@ + +stat.lib : $(STAT_OBJ) + @date to $@ + +stdio.lib : $(STDIO_OBJ) + @date to $@ + +stdlib.lib : $(STDLIB_OBJ) + @date to $@ + +string.lib : $(STRING_OBJ) + @date to $@ + +strings.lib : $(STRINGS_OBJ) + @date to $@ + +time.lib : $(TIME_OBJ) + @date to $@ + +unistd.lib : $(UNISTD_OBJ) + @date to $@ + +usergroup.lib : $(USERGROUP_OBJ) + @date to $@ + +utime.lib : $(UTIME_OBJ) + @date to $@ + +amiga.lib : $(AMIGA_OBJ) + @date to $@ + +############################################################################## + +c.lib: \ + c.lib_rev.o \ + amiga.lib ctype.lib debug.lib dirent.lib errno.lib fcntl.lib libgen.lib \ + locale.lib math.lib mount.lib signal.lib socket.lib stat.lib stdio.lib \ + stdlib.lib string.lib strings.lib time.lib unistd.lib usergroup.lib \ + utime.lib + @-delete >NIL: T:$@ T:$@.cmd + @echo >>T:$@.cmd c.lib_rev.o + @echo >>T:$@.cmd $(AMIGA_OBJ) + @echo >>T:$@.cmd $(CTYPE_OBJ) + @echo >>T:$@.cmd $(DEBUG_OBJ) + @echo >>T:$@.cmd $(DIRENT_OBJ) + @echo >>T:$@.cmd $(ERRNO_OBJ) + @echo >>T:$@.cmd $(FCNTL_OBJ) + @echo >>T:$@.cmd $(LIBGEN_OBJ) + @echo >>T:$@.cmd $(LOCALE_OBJ) + @echo >>T:$@.cmd $(MATH_OBJ) + @echo >>T:$@.cmd $(MOUNT_OBJ) + @echo >>T:$@.cmd $(SIGNAL_OBJ) + @echo >>T:$@.cmd $(SOCKET_OBJ) + @echo >>T:$@.cmd $(STAT_OBJ) + @echo >>T:$@.cmd $(STDIO_OBJ) + @echo >>T:$@.cmd $(STDLIB_OBJ) + @echo >>T:$@.cmd $(STRINGS_OBJ) + @echo >>T:$@.cmd $(STRING_OBJ) + @echo >>T:$@.cmd $(TIME_OBJ) + @echo >>T:$@.cmd $(UNISTD_OBJ) + @echo >>T:$@.cmd $(USERGROUP_OBJ) + @echo >>T:$@.cmd $(UTIME_OBJ) + oml T:$@ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +accept(int sockfd,struct sockaddr *cliaddr,int *addrlen) +{ + struct fd * fd; + struct fd * new_fd; + int new_fd_slot_number; + int result = -1; + LONG new_socket_fd; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWPOINTER(cliaddr); + SHOWPOINTER(addrlen); + + assert( cliaddr != NULL && addrlen != NULL ); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(cliaddr == NULL || addrlen == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + new_fd_slot_number = __find_vacant_fd_entry(); + if(new_fd_slot_number < 0) + { + if(__grow_fd_table() < 0) + { + SHOWMSG("couldn't find a vacant fd slot and no memory to create one"); + goto out; + } + + new_fd_slot_number = __find_vacant_fd_entry(); + assert( new_fd_slot_number >= 0 ); + } + + PROFILE_OFF(); + new_socket_fd = __accept((LONG)fd->fd_DefaultFile,cliaddr,(LONG *)addrlen); + PROFILE_ON(); + + if(new_socket_fd < 0) + { + SHOWMSG("could not accept connection"); + goto out; + } + + new_fd = __fd[new_fd_slot_number]; + + __initialize_fd(new_fd,(HOOKFUNC)__socket_hook_entry,(BPTR)new_socket_fd,FDF_IN_USE | FDF_IS_SOCKET | FDF_READ | FDF_WRITE); + + result = new_fd_slot_number; + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_bind.c b/library/socket_bind.c new file mode 100644 index 0000000..9cd7b1e --- /dev/null +++ b/library/socket_bind.c @@ -0,0 +1,101 @@ +/* + * $Id: socket_bind.c,v 1.1.1.1 2004-07-26 16:31:08 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +bind(int sockfd,struct sockaddr *name,int namelen) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWPOINTER(name); + SHOWVALUE(namelen); + + assert( name != NULL ); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name == NULL) + { + SHOWMSG("invalid name parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __bind((LONG)fd->fd_DefaultFile,name,namelen); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_connect.c b/library/socket_connect.c new file mode 100644 index 0000000..a5d0b1e --- /dev/null +++ b/library/socket_connect.c @@ -0,0 +1,101 @@ +/* + * $Id: socket_connect.c,v 1.1.1.1 2004-07-26 16:31:08 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +connect(int sockfd,struct sockaddr *name,int namelen) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWPOINTER(name); + SHOWVALUE(namelen); + + assert( name != NULL ); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name == NULL) + { + SHOWMSG("invalid name parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __connect((LONG)fd->fd_DefaultFile,name,namelen); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_data.c b/library/socket_data.c new file mode 100644 index 0000000..4e75a11 --- /dev/null +++ b/library/socket_data.c @@ -0,0 +1,56 @@ +/* + * $Id: socket_data.c,v 1.1.1.1 2004-07-26 16:31:08 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +struct Library * __SocketBase; + +/****************************************************************************/ + +#if defined(__amigaos4__) + +struct SocketIFace *__ISocket; + +#endif /* __amigaos4__ */ + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_get_descriptor.c b/library/socket_get_descriptor.c new file mode 100644 index 0000000..fc1f154 --- /dev/null +++ b/library/socket_get_descriptor.c @@ -0,0 +1,72 @@ +/* + * $Id: socket_get_descriptor.c,v 1.1.1.1 2004-07-26 16:31:08 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +struct fd * +__get_socket_descriptor(int socket_descriptor) +{ + struct fd * result = NULL; + struct fd * fd; + + fd = __get_file_descriptor(socket_descriptor); + if(fd == NULL) + { + errno = EBADF; + goto out; + } + + if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_SOCKET)) + { + errno = ENOTSOCK; + goto out; + } + + result = fd; + + out: + + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_gethostbyaddr.c b/library/socket_gethostbyaddr.c new file mode 100644 index 0000000..2c32138 --- /dev/null +++ b/library/socket_gethostbyaddr.c @@ -0,0 +1,91 @@ +/* + * $Id: socket_gethostbyaddr.c,v 1.1.1.1 2004-07-26 16:31:09 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +struct hostent * +gethostbyaddr(const char *addr, int len, int type) +{ + struct hostent *result = NULL; + + ENTER(); + + SHOWPOINTER(addr); + SHOWVALUE(len); + SHOWVALUE(type); + + assert(addr != NULL); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(addr == NULL) + { + SHOWMSG("invalid addr parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __gethostbyaddr((STRPTR)addr,len,type); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_gethostbyname.c b/library/socket_gethostbyname.c new file mode 100644 index 0000000..6a577bd --- /dev/null +++ b/library/socket_gethostbyname.c @@ -0,0 +1,89 @@ +/* + * $Id: socket_gethostbyname.c,v 1.1.1.1 2004-07-26 16:31:09 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +struct hostent * +gethostbyname(const char *name) +{ + struct hostent *result = NULL; + + ENTER(); + + SHOWSTRING(name); + + assert(name != NULL); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name == NULL) + { + SHOWMSG("invalid name parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __gethostbyname((STRPTR)name); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_gethostid.c b/library/socket_gethostid.c new file mode 100644 index 0000000..11e009d --- /dev/null +++ b/library/socket_gethostid.c @@ -0,0 +1,66 @@ +/* + * $Id: socket_gethostid.c,v 1.1.1.1 2004-07-26 16:31:09 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +long +gethostid(void) +{ + long result; + + ENTER(); + + assert(__SocketBase != NULL); + + PROFILE_OFF(); + result = __gethostid(); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_gethostname.c b/library/socket_gethostname.c new file mode 100644 index 0000000..58a0351 --- /dev/null +++ b/library/socket_gethostname.c @@ -0,0 +1,90 @@ +/* + * $Id: socket_gethostname.c,v 1.1.1.1 2004-07-26 16:31:09 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +gethostname(const char *hostname,int size) +{ + int result = -1; + + ENTER(); + + SHOWPOINTER(hostname); + SHOWVALUE(size); + + assert(hostname != NULL); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(hostname == NULL) + { + SHOWMSG("invalid host name parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __gethostname((STRPTR)hostname,size); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_getnetbyaddr.c b/library/socket_getnetbyaddr.c new file mode 100644 index 0000000..7c215f0 --- /dev/null +++ b/library/socket_getnetbyaddr.c @@ -0,0 +1,68 @@ +/* + * $Id: socket_getnetbyaddr.c,v 1.1.1.1 2004-07-26 16:31:09 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +struct netent * +getnetbyaddr(long net,int type) +{ + struct netent *result = NULL; + + ENTER(); + + assert(__SocketBase != NULL); + + PROFILE_OFF(); + result = __getnetbyaddr((ULONG)net,type); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_getnetbyname.c b/library/socket_getnetbyname.c new file mode 100644 index 0000000..d0a1284 --- /dev/null +++ b/library/socket_getnetbyname.c @@ -0,0 +1,89 @@ +/* + * $Id: socket_getnetbyname.c,v 1.1.1.1 2004-07-26 16:31:09 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +struct netent * +getnetbyname(const char *name) +{ + struct netent *result = NULL; + + ENTER(); + + SHOWSTRING(name); + + assert(name != NULL); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name == NULL) + { + SHOWMSG("invalid name parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __getnetbyname((STRPTR)name); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_getpeername.c b/library/socket_getpeername.c new file mode 100644 index 0000000..221c260 --- /dev/null +++ b/library/socket_getpeername.c @@ -0,0 +1,101 @@ +/* + * $Id: socket_getpeername.c,v 1.1.1.1 2004-07-26 16:31:10 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +getpeername(int sockfd,struct sockaddr *name,int *namelen) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWPOINTER(name); + SHOWPOINTER(namelen); + + assert( name != NULL && namelen != NULL ); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name == NULL || namelen == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __getpeername((LONG)fd->fd_DefaultFile,name,(LONG *)namelen); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_getprotobyname.c b/library/socket_getprotobyname.c new file mode 100644 index 0000000..f512bcc --- /dev/null +++ b/library/socket_getprotobyname.c @@ -0,0 +1,87 @@ +/* + * $Id: socket_getprotobyname.c,v 1.1.1.1 2004-07-26 16:31:10 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +struct protoent * +getprotobyname(const char *name) +{ + struct protoent *result = NULL; + + ENTER(); + + assert(name != NULL); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __getprotobyname((char *)name); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_getprotobynumber.c b/library/socket_getprotobynumber.c new file mode 100644 index 0000000..167db93 --- /dev/null +++ b/library/socket_getprotobynumber.c @@ -0,0 +1,66 @@ +/* + * $Id: socket_getprotobynumber.c,v 1.1.1.1 2004-07-26 16:31:10 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +struct protoent * +getprotobynumber(int proto) +{ + struct protoent *result; + + ENTER(); + + assert(__SocketBase != NULL); + + PROFILE_OFF(); + result = __getprotobynumber(proto); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_getservbyname.c b/library/socket_getservbyname.c new file mode 100644 index 0000000..7826b88 --- /dev/null +++ b/library/socket_getservbyname.c @@ -0,0 +1,87 @@ +/* + * $Id: socket_getservbyname.c,v 1.1.1.1 2004-07-26 16:31:10 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +struct servent * +getservbyname(const char *name, const char *proto) +{ + struct servent * result = NULL; + + ENTER(); + + assert(name != NULL && proto != NULL); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name == NULL || proto == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __getservbyname((char *)name,(char *)proto); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_getservbyport.c b/library/socket_getservbyport.c new file mode 100644 index 0000000..750f765 --- /dev/null +++ b/library/socket_getservbyport.c @@ -0,0 +1,87 @@ +/* + * $Id: socket_getservbyport.c,v 1.1.1.1 2004-07-26 16:31:10 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +struct servent * +getservbyport(int port, const char *proto) +{ + struct servent * result = NULL; + + ENTER(); + + assert(proto != NULL); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(proto == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __getservbyport(port,(char *)proto); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_getsockname.c b/library/socket_getsockname.c new file mode 100644 index 0000000..aa48898 --- /dev/null +++ b/library/socket_getsockname.c @@ -0,0 +1,101 @@ +/* + * $Id: socket_getsockname.c,v 1.1.1.1 2004-07-26 16:31:11 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +getsockname(int sockfd,struct sockaddr *name,int *namelen) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWPOINTER(name); + SHOWPOINTER(namelen); + + assert( name != NULL && namelen != NULL ); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name == NULL || namelen == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __getsockname((LONG)fd->fd_DefaultFile,name,(LONG *)namelen); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_getsockopt.c b/library/socket_getsockopt.c new file mode 100644 index 0000000..2dfa9b9 --- /dev/null +++ b/library/socket_getsockopt.c @@ -0,0 +1,103 @@ +/* + * $Id: socket_getsockopt.c,v 1.1.1.1 2004-07-26 16:31:11 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +getsockopt(int sockfd,int level,int optname,void *optval,int *optlen) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWVALUE(level); + SHOWVALUE(optname); + SHOWPOINTER(optval); + SHOWPOINTER(optlen); + + assert( optval != NULL && optlen != NULL ); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(optval == NULL || optlen == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __getsockopt((LONG)fd->fd_DefaultFile,level,optname,optval,(LONG *)optlen); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_headers.h b/library/socket_headers.h new file mode 100644 index 0000000..e6f9ff8 --- /dev/null +++ b/library/socket_headers.h @@ -0,0 +1,1065 @@ +/* + * $Id: socket_headers.h,v 1.1.1.1 2004-07-26 16:31:14 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SOCKET_HEADERS_H +#define _SOCKET_HEADERS_H + +/****************************************************************************/ + +#ifndef _NETINET_IN_H +#include +#endif /* _NETINET_IN_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +extern struct Library * __SocketBase; + +/****************************************************************************/ + +#if defined(__amigaos4__) + +extern struct SocketIFace *__ISocket; + +#endif /* __amigaos4__ */ + +/****************************************************************************/ + +extern struct fd * __get_socket_descriptor(int socket_descriptor); +extern void __socket_hook_entry(struct Hook * hook,struct fd * fd,struct file_hook_message * message); + +/****************************************************************************/ + +#if defined(__GNUC__) + +#if defined(__amigaos4__) + +#include + +#define __socket(domain, type, protocol) __ISocket->socket(domain , type , protocol) +#define __bind(sock, name, namelen) __ISocket->bind(sock , name , namelen) +#define __listen(sock, backlog) __ISocket->listen(sock , backlog) +#define __accept(sock, addr, addrlen) __ISocket->accept(sock , addr , addrlen) +#define __connect(sock, name, namelen) __ISocket->connect(sock , name , namelen) +#define __sendto(sock, buf, len, flags, to, tolen) __ISocket->sendto(sock , buf , len , flags , to , tolen) +#define __send(sock, buf, len, flags) __ISocket->send(sock , buf , len , flags) +#define __recvfrom(sock, buf, len, flags, addr, addrlen) __ISocket->recvfrom(sock , buf , len , flags , addr , addrlen) +#define __recv(sock, buf, len, flags) __ISocket->recv(sock , buf , len , flags) +#define __shutdown(sock, how) __ISocket->shutdown(sock , how) +#define __setsockopt(sock, level, optname, optval, optlen) __ISocket->setsockopt(sock , level , optname , optval , optlen) +#define __getsockopt(sock, level, optname, optval, optlen) __ISocket->getsockopt(sock , level , optname , optval , optlen) +#define __getsockname(sock, name, namelen) __ISocket->getsockname(sock , name , namelen) +#define __getpeername(sock, name, namelen) __ISocket->getpeername(sock , name , namelen) +#define __IoctlSocket(sock, req, argp) __ISocket->IoctlSocket(sock , req , argp) +#define __CloseSocket(sock) __ISocket->CloseSocket(sock) +#define __WaitSelect(nfds, read_fds, write_fds, except_fds, timeout, signals) __ISocket->WaitSelect(nfds , read_fds , write_fds , except_fds , timeout , signals) +#define __SetSocketSignals(int_mask, io_mask, urgent_mask) __ISocket->SetSocketSignals(int_mask , io_mask , urgent_mask) +#define __getdtablesize() __ISocket->getdtablesize() +#define __ObtainSocket(id, domain, type, protocol) __ISocket->ObtainSocket(id , domain , type , protocol) +#define __ReleaseSocket(sock, id) __ISocket->ReleaseSocket(sock , id) +#define __ReleaseCopyOfSocket(sock, id) __ISocket->ReleaseCopyOfSocket(sock , id) +#define __Errno() __ISocket->Errno() +#define __SetErrnoPtr(errno_ptr, size) __ISocket->SetErrnoPtr(errno_ptr , size) +#define __Inet_NtoA(ip) __ISocket->Inet_NtoA(ip) +#define __Inet_AtoN(cp, ip) __ISocket->inet_aton(cp, ip) +#define __inet_addr(cp) __ISocket->inet_addr(cp) +#define __Inet_LnaOf(in) __ISocket->Inet_LnaOf(in) +#define __Inet_NetOf(in) __ISocket->Inet_NetOf(in) +#define __Inet_MakeAddr(net, host) __ISocket->Inet_MakeAddr(net , host) +#define __inet_network(cp) __ISocket->inet_network(cp) +#define __gethostbyname(name) __ISocket->gethostbyname(name) +#define __gethostbyaddr(addr, len, type) __ISocket->gethostbyaddr(addr , len , type) +#define __getnetbyname(name) __ISocket->getnetbyname(name) +#define __getnetbyaddr(net, type) __ISocket->getnetbyaddr(net , type) +#define __getservbyname(name, proto) __ISocket->getservbyname(name , proto) +#define __getservbyport(port, proto) __ISocket->getservbyport(port , proto) +#define __getprotobyname(name) __ISocket->getprotobyname(name) +#define __getprotobynumber(proto) __ISocket->getprotobynumber(proto) +#define __vsyslog(pri, msg, args) __ISocket->vsyslog(pri , msg , args) +#define __syslog(pri, msg, tag1...) __ISocket->syslog(pri , msg , ## tag1) +#define __Dup2Socket(old_socket, new_socket) __ISocket->Dup2Socket(old_socket , new_socket) +#define __sendmsg(sock, msg, flags) __ISocket->sendmsg(sock , msg , flags) +#define __recvmsg(sock, msg, flags) __ISocket->recvmsg(sock , msg , flags) +#define __gethostname(name, namelen) __ISocket->gethostname(name , namelen) +#define __gethostid() __ISocket->gethostid() +#define __SocketBaseTagList(tags) __ISocket->SocketBaseTagList(tags) +#define __SocketBaseTags(tag1...) __ISocket->SocketBaseTags(## tag1) + +#else + +#define __socket(domain, type, protocol) ({ \ + LONG _socket_domain = (domain); \ + LONG _socket_type = (type); \ + LONG _socket_protocol = (protocol); \ + LONG _socket__re = \ + ({ \ + register struct Library * const __socket__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __socket__re __asm("d0"); \ + register LONG __socket_domain __asm("d0") = (_socket_domain); \ + register LONG __socket_type __asm("d1") = (_socket_type); \ + register LONG __socket_protocol __asm("d2") = (_socket_protocol); \ + __asm volatile ("jsr a6@(-30:W)" \ + : "=r"(__socket__re) \ + : "r"(__socket__bn), "r"(__socket_domain), "r"(__socket_type), "r"(__socket_protocol) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __socket__re; \ + }); \ + _socket__re; \ +}) + +#define __bind(sock, name, namelen) ({ \ + LONG _bind_sock = (sock); \ + struct sockaddr * _bind_name = (name); \ + LONG _bind_namelen = (namelen); \ + LONG _bind__re = \ + ({ \ + register struct Library * const __bind__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __bind__re __asm("d0"); \ + register LONG __bind_sock __asm("d0") = (_bind_sock); \ + register struct sockaddr * __bind_name __asm("a0") = (_bind_name); \ + register LONG __bind_namelen __asm("d1") = (_bind_namelen); \ + __asm volatile ("jsr a6@(-36:W)" \ + : "=r"(__bind__re) \ + : "r"(__bind__bn), "r"(__bind_sock), "r"(__bind_name), "r"(__bind_namelen) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __bind__re; \ + }); \ + _bind__re; \ +}) + +#define __listen(sock, backlog) ({ \ + LONG _listen_sock = (sock); \ + LONG _listen_backlog = (backlog); \ + LONG _listen__re = \ + ({ \ + register struct Library * const __listen__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __listen__re __asm("d0"); \ + register LONG __listen_sock __asm("d0") = (_listen_sock); \ + register LONG __listen_backlog __asm("d1") = (_listen_backlog); \ + __asm volatile ("jsr a6@(-42:W)" \ + : "=r"(__listen__re) \ + : "r"(__listen__bn), "r"(__listen_sock), "r"(__listen_backlog) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __listen__re; \ + }); \ + _listen__re; \ +}) + +#define __accept(sock, addr, addrlen) ({ \ + LONG _accept_sock = (sock); \ + struct sockaddr * _accept_addr = (addr); \ + LONG * _accept_addrlen = (addrlen); \ + LONG _accept__re = \ + ({ \ + register struct Library * const __accept__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __accept__re __asm("d0"); \ + register LONG __accept_sock __asm("d0") = (_accept_sock); \ + register struct sockaddr * __accept_addr __asm("a0") = (_accept_addr); \ + register LONG * __accept_addrlen __asm("a1") = (_accept_addrlen); \ + __asm volatile ("jsr a6@(-48:W)" \ + : "=r"(__accept__re) \ + : "r"(__accept__bn), "r"(__accept_sock), "r"(__accept_addr), "r"(__accept_addrlen) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __accept__re; \ + }); \ + _accept__re; \ +}) + +#define __connect(sock, name, namelen) ({ \ + LONG _connect_sock = (sock); \ + struct sockaddr * _connect_name = (name); \ + LONG _connect_namelen = (namelen); \ + LONG _connect__re = \ + ({ \ + register struct Library * const __connect__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __connect__re __asm("d0"); \ + register LONG __connect_sock __asm("d0") = (_connect_sock); \ + register struct sockaddr * __connect_name __asm("a0") = (_connect_name); \ + register LONG __connect_namelen __asm("d1") = (_connect_namelen); \ + __asm volatile ("jsr a6@(-54:W)" \ + : "=r"(__connect__re) \ + : "r"(__connect__bn), "r"(__connect_sock), "r"(__connect_name), "r"(__connect_namelen) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __connect__re; \ + }); \ + _connect__re; \ +}) + +#define __sendto(sock, buf, len, flags, to, tolen) ({ \ + LONG _sendto_sock = (sock); \ + APTR _sendto_buf = (buf); \ + LONG _sendto_len = (len); \ + LONG _sendto_flags = (flags); \ + struct sockaddr * _sendto_to = (to); \ + LONG _sendto_tolen = (tolen); \ + LONG _sendto__re = \ + ({ \ + register struct Library * const __sendto__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __sendto__re __asm("d0"); \ + register LONG __sendto_sock __asm("d0") = (_sendto_sock); \ + register APTR __sendto_buf __asm("a0") = (_sendto_buf); \ + register LONG __sendto_len __asm("d1") = (_sendto_len); \ + register LONG __sendto_flags __asm("d2") = (_sendto_flags); \ + register struct sockaddr * __sendto_to __asm("a1") = (_sendto_to); \ + register LONG __sendto_tolen __asm("d3") = (_sendto_tolen); \ + __asm volatile ("jsr a6@(-60:W)" \ + : "=r"(__sendto__re) \ + : "r"(__sendto__bn), "r"(__sendto_sock), "r"(__sendto_buf), "r"(__sendto_len), "r"(__sendto_flags), "r"(__sendto_to), "r"(__sendto_tolen) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __sendto__re; \ + }); \ + _sendto__re; \ +}) + +#define __send(sock, buf, len, flags) ({ \ + LONG _send_sock = (sock); \ + APTR _send_buf = (buf); \ + LONG _send_len = (len); \ + LONG _send_flags = (flags); \ + LONG _send__re = \ + ({ \ + register struct Library * const __send__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __send__re __asm("d0"); \ + register LONG __send_sock __asm("d0") = (_send_sock); \ + register APTR __send_buf __asm("a0") = (_send_buf); \ + register LONG __send_len __asm("d1") = (_send_len); \ + register LONG __send_flags __asm("d2") = (_send_flags); \ + __asm volatile ("jsr a6@(-66:W)" \ + : "=r"(__send__re) \ + : "r"(__send__bn), "r"(__send_sock), "r"(__send_buf), "r"(__send_len), "r"(__send_flags) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __send__re; \ + }); \ + _send__re; \ +}) + +#define __recvfrom(sock, buf, len, flags, addr, addrlen) ({ \ + LONG _recvfrom_sock = (sock); \ + APTR _recvfrom_buf = (buf); \ + LONG _recvfrom_len = (len); \ + LONG _recvfrom_flags = (flags); \ + struct sockaddr * _recvfrom_addr = (addr); \ + LONG * _recvfrom_addrlen = (addrlen); \ + LONG _recvfrom__re = \ + ({ \ + register struct Library * const __recvfrom__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __recvfrom__re __asm("d0"); \ + register LONG __recvfrom_sock __asm("d0") = (_recvfrom_sock); \ + register APTR __recvfrom_buf __asm("a0") = (_recvfrom_buf); \ + register LONG __recvfrom_len __asm("d1") = (_recvfrom_len); \ + register LONG __recvfrom_flags __asm("d2") = (_recvfrom_flags); \ + register struct sockaddr * __recvfrom_addr __asm("a1") = (_recvfrom_addr); \ + register LONG * __recvfrom_addrlen __asm("a2") = (_recvfrom_addrlen); \ + __asm volatile ("jsr a6@(-72:W)" \ + : "=r"(__recvfrom__re) \ + : "r"(__recvfrom__bn), "r"(__recvfrom_sock), "r"(__recvfrom_buf), "r"(__recvfrom_len), "r"(__recvfrom_flags), "r"(__recvfrom_addr), "r"(__recvfrom_addrlen) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __recvfrom__re; \ + }); \ + _recvfrom__re; \ +}) + +#define __recv(sock, buf, len, flags) ({ \ + LONG _recv_sock = (sock); \ + APTR _recv_buf = (buf); \ + LONG _recv_len = (len); \ + LONG _recv_flags = (flags); \ + LONG _recv__re = \ + ({ \ + register struct Library * const __recv__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __recv__re __asm("d0"); \ + register LONG __recv_sock __asm("d0") = (_recv_sock); \ + register APTR __recv_buf __asm("a0") = (_recv_buf); \ + register LONG __recv_len __asm("d1") = (_recv_len); \ + register LONG __recv_flags __asm("d2") = (_recv_flags); \ + __asm volatile ("jsr a6@(-78:W)" \ + : "=r"(__recv__re) \ + : "r"(__recv__bn), "r"(__recv_sock), "r"(__recv_buf), "r"(__recv_len), "r"(__recv_flags) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __recv__re; \ + }); \ + _recv__re; \ +}) + +#define __shutdown(sock, how) ({ \ + LONG _shutdown_sock = (sock); \ + LONG _shutdown_how = (how); \ + LONG _shutdown__re = \ + ({ \ + register struct Library * const __shutdown__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __shutdown__re __asm("d0"); \ + register LONG __shutdown_sock __asm("d0") = (_shutdown_sock); \ + register LONG __shutdown_how __asm("d1") = (_shutdown_how); \ + __asm volatile ("jsr a6@(-84:W)" \ + : "=r"(__shutdown__re) \ + : "r"(__shutdown__bn), "r"(__shutdown_sock), "r"(__shutdown_how) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __shutdown__re; \ + }); \ + _shutdown__re; \ +}) + +#define __setsockopt(sock, level, optname, optval, optlen) ({ \ + LONG _setsockopt_sock = (sock); \ + LONG _setsockopt_level = (level); \ + LONG _setsockopt_optname = (optname); \ + APTR _setsockopt_optval = (optval); \ + LONG _setsockopt_optlen = (optlen); \ + LONG _setsockopt__re = \ + ({ \ + register struct Library * const __setsockopt__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __setsockopt__re __asm("d0"); \ + register LONG __setsockopt_sock __asm("d0") = (_setsockopt_sock); \ + register LONG __setsockopt_level __asm("d1") = (_setsockopt_level); \ + register LONG __setsockopt_optname __asm("d2") = (_setsockopt_optname); \ + register APTR __setsockopt_optval __asm("a0") = (_setsockopt_optval); \ + register LONG __setsockopt_optlen __asm("d3") = (_setsockopt_optlen); \ + __asm volatile ("jsr a6@(-90:W)" \ + : "=r"(__setsockopt__re) \ + : "r"(__setsockopt__bn), "r"(__setsockopt_sock), "r"(__setsockopt_level), "r"(__setsockopt_optname), "r"(__setsockopt_optval), "r"(__setsockopt_optlen) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __setsockopt__re; \ + }); \ + _setsockopt__re; \ +}) + +#define __getsockopt(sock, level, optname, optval, optlen) ({ \ + LONG _getsockopt_sock = (sock); \ + LONG _getsockopt_level = (level); \ + LONG _getsockopt_optname = (optname); \ + APTR _getsockopt_optval = (optval); \ + LONG * _getsockopt_optlen = (optlen); \ + LONG _getsockopt__re = \ + ({ \ + register struct Library * const __getsockopt__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __getsockopt__re __asm("d0"); \ + register LONG __getsockopt_sock __asm("d0") = (_getsockopt_sock); \ + register LONG __getsockopt_level __asm("d1") = (_getsockopt_level); \ + register LONG __getsockopt_optname __asm("d2") = (_getsockopt_optname); \ + register APTR __getsockopt_optval __asm("a0") = (_getsockopt_optval); \ + register LONG * __getsockopt_optlen __asm("a1") = (_getsockopt_optlen); \ + __asm volatile ("jsr a6@(-96:W)" \ + : "=r"(__getsockopt__re) \ + : "r"(__getsockopt__bn), "r"(__getsockopt_sock), "r"(__getsockopt_level), "r"(__getsockopt_optname), "r"(__getsockopt_optval), "r"(__getsockopt_optlen) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getsockopt__re; \ + }); \ + _getsockopt__re; \ +}) + +#define __getsockname(sock, name, namelen) ({ \ + LONG _getsockname_sock = (sock); \ + struct sockaddr * _getsockname_name = (name); \ + LONG * _getsockname_namelen = (namelen); \ + LONG _getsockname__re = \ + ({ \ + register struct Library * const __getsockname__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __getsockname__re __asm("d0"); \ + register LONG __getsockname_sock __asm("d0") = (_getsockname_sock); \ + register struct sockaddr * __getsockname_name __asm("a0") = (_getsockname_name); \ + register LONG * __getsockname_namelen __asm("a1") = (_getsockname_namelen); \ + __asm volatile ("jsr a6@(-102:W)" \ + : "=r"(__getsockname__re) \ + : "r"(__getsockname__bn), "r"(__getsockname_sock), "r"(__getsockname_name), "r"(__getsockname_namelen) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getsockname__re; \ + }); \ + _getsockname__re; \ +}) + +#define __getpeername(sock, name, namelen) ({ \ + LONG _getpeername_sock = (sock); \ + struct sockaddr * _getpeername_name = (name); \ + LONG * _getpeername_namelen = (namelen); \ + LONG _getpeername__re = \ + ({ \ + register struct Library * const __getpeername__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __getpeername__re __asm("d0"); \ + register LONG __getpeername_sock __asm("d0") = (_getpeername_sock); \ + register struct sockaddr * __getpeername_name __asm("a0") = (_getpeername_name); \ + register LONG * __getpeername_namelen __asm("a1") = (_getpeername_namelen); \ + __asm volatile ("jsr a6@(-108:W)" \ + : "=r"(__getpeername__re) \ + : "r"(__getpeername__bn), "r"(__getpeername_sock), "r"(__getpeername_name), "r"(__getpeername_namelen) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getpeername__re; \ + }); \ + _getpeername__re; \ +}) + +#define __IoctlSocket(sock, req, argp) ({ \ + LONG _IoctlSocket_sock = (sock); \ + ULONG _IoctlSocket_req = (req); \ + APTR _IoctlSocket_argp = (argp); \ + LONG _IoctlSocket__re = \ + ({ \ + register struct Library * const __IoctlSocket__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __IoctlSocket__re __asm("d0"); \ + register LONG __IoctlSocket_sock __asm("d0") = (_IoctlSocket_sock); \ + register ULONG __IoctlSocket_req __asm("d1") = (_IoctlSocket_req); \ + register APTR __IoctlSocket_argp __asm("a0") = (_IoctlSocket_argp); \ + __asm volatile ("jsr a6@(-114:W)" \ + : "=r"(__IoctlSocket__re) \ + : "r"(__IoctlSocket__bn), "r"(__IoctlSocket_sock), "r"(__IoctlSocket_req), "r"(__IoctlSocket_argp) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __IoctlSocket__re; \ + }); \ + _IoctlSocket__re; \ +}) + +#define __CloseSocket(sock) ({ \ + LONG _CloseSocket_sock = (sock); \ + LONG _CloseSocket__re = \ + ({ \ + register struct Library * const __CloseSocket__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __CloseSocket__re __asm("d0"); \ + register LONG __CloseSocket_sock __asm("d0") = (_CloseSocket_sock); \ + __asm volatile ("jsr a6@(-120:W)" \ + : "=r"(__CloseSocket__re) \ + : "r"(__CloseSocket__bn), "r"(__CloseSocket_sock) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __CloseSocket__re; \ + }); \ + _CloseSocket__re; \ +}) + +#define __WaitSelect(nfds, read_fds, write_fds, except_fds, timeout, signals) ({ \ + LONG _WaitSelect_nfds = (nfds); \ + APTR _WaitSelect_read_fds = (read_fds); \ + APTR _WaitSelect_write_fds = (write_fds); \ + APTR _WaitSelect_except_fds = (except_fds); \ + struct timeval * _WaitSelect_timeout = (timeout); \ + ULONG * _WaitSelect_signals = (signals); \ + LONG _WaitSelect__re = \ + ({ \ + register struct Library * const __WaitSelect__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __WaitSelect__re __asm("d0"); \ + register LONG __WaitSelect_nfds __asm("d0") = (_WaitSelect_nfds); \ + register APTR __WaitSelect_read_fds __asm("a0") = (_WaitSelect_read_fds); \ + register APTR __WaitSelect_write_fds __asm("a1") = (_WaitSelect_write_fds); \ + register APTR __WaitSelect_except_fds __asm("a2") = (_WaitSelect_except_fds); \ + register struct timeval * __WaitSelect_timeout __asm("a3") = (_WaitSelect_timeout); \ + register ULONG * __WaitSelect_signals __asm("d1") = (_WaitSelect_signals); \ + __asm volatile ("jsr a6@(-126:W)" \ + : "=r"(__WaitSelect__re) \ + : "r"(__WaitSelect__bn), "r"(__WaitSelect_nfds), "r"(__WaitSelect_read_fds), "r"(__WaitSelect_write_fds), "r"(__WaitSelect_except_fds), "r"(__WaitSelect_timeout), "r"(__WaitSelect_signals) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __WaitSelect__re; \ + }); \ + _WaitSelect__re; \ +}) + +#define __SetSocketSignals(int_mask, io_mask, urgent_mask) ({ \ + ULONG _SetSocketSignals_int_mask = (int_mask); \ + ULONG _SetSocketSignals_io_mask = (io_mask); \ + ULONG _SetSocketSignals_urgent_mask = (urgent_mask); \ + { \ + register struct Library * const __SetSocketSignals__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register ULONG __SetSocketSignals_int_mask __asm("d0") = (_SetSocketSignals_int_mask); \ + register ULONG __SetSocketSignals_io_mask __asm("d1") = (_SetSocketSignals_io_mask); \ + register ULONG __SetSocketSignals_urgent_mask __asm("d2") = (_SetSocketSignals_urgent_mask); \ + __asm volatile ("jsr a6@(-132:W)" \ + : \ + : "r"(__SetSocketSignals__bn), "r"(__SetSocketSignals_int_mask), "r"(__SetSocketSignals_io_mask), "r"(__SetSocketSignals_urgent_mask) \ + : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + } \ +}) + +#define __getdtablesize() ({ \ + LONG _getdtablesize__re = \ + ({ \ + register struct Library * const __getdtablesize__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __getdtablesize__re __asm("d0"); \ + __asm volatile ("jsr a6@(-138:W)" \ + : "=r"(__getdtablesize__re) \ + : "r"(__getdtablesize__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getdtablesize__re; \ + }); \ + _getdtablesize__re; \ +}) + +#define __ObtainSocket(id, domain, type, protocol) ({ \ + LONG _ObtainSocket_id = (id); \ + LONG _ObtainSocket_domain = (domain); \ + LONG _ObtainSocket_type = (type); \ + LONG _ObtainSocket_protocol = (protocol); \ + LONG _ObtainSocket__re = \ + ({ \ + register struct Library * const __ObtainSocket__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __ObtainSocket__re __asm("d0"); \ + register LONG __ObtainSocket_id __asm("d0") = (_ObtainSocket_id); \ + register LONG __ObtainSocket_domain __asm("d1") = (_ObtainSocket_domain); \ + register LONG __ObtainSocket_type __asm("d2") = (_ObtainSocket_type); \ + register LONG __ObtainSocket_protocol __asm("d3") = (_ObtainSocket_protocol); \ + __asm volatile ("jsr a6@(-144:W)" \ + : "=r"(__ObtainSocket__re) \ + : "r"(__ObtainSocket__bn), "r"(__ObtainSocket_id), "r"(__ObtainSocket_domain), "r"(__ObtainSocket_type), "r"(__ObtainSocket_protocol) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __ObtainSocket__re; \ + }); \ + _ObtainSocket__re; \ +}) + +#define __ReleaseSocket(sock, id) ({ \ + LONG _ReleaseSocket_sock = (sock); \ + LONG _ReleaseSocket_id = (id); \ + LONG _ReleaseSocket__re = \ + ({ \ + register struct Library * const __ReleaseSocket__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __ReleaseSocket__re __asm("d0"); \ + register LONG __ReleaseSocket_sock __asm("d0") = (_ReleaseSocket_sock); \ + register LONG __ReleaseSocket_id __asm("d1") = (_ReleaseSocket_id); \ + __asm volatile ("jsr a6@(-150:W)" \ + : "=r"(__ReleaseSocket__re) \ + : "r"(__ReleaseSocket__bn), "r"(__ReleaseSocket_sock), "r"(__ReleaseSocket_id) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __ReleaseSocket__re; \ + }); \ + _ReleaseSocket__re; \ +}) + +#define __ReleaseCopyOfSocket(sock, id) ({ \ + LONG _ReleaseCopyOfSocket_sock = (sock); \ + LONG _ReleaseCopyOfSocket_id = (id); \ + LONG _ReleaseCopyOfSocket__re = \ + ({ \ + register struct Library * const __ReleaseCopyOfSocket__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __ReleaseCopyOfSocket__re __asm("d0"); \ + register LONG __ReleaseCopyOfSocket_sock __asm("d0") = (_ReleaseCopyOfSocket_sock); \ + register LONG __ReleaseCopyOfSocket_id __asm("d1") = (_ReleaseCopyOfSocket_id); \ + __asm volatile ("jsr a6@(-156:W)" \ + : "=r"(__ReleaseCopyOfSocket__re) \ + : "r"(__ReleaseCopyOfSocket__bn), "r"(__ReleaseCopyOfSocket_sock), "r"(__ReleaseCopyOfSocket_id) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __ReleaseCopyOfSocket__re; \ + }); \ + _ReleaseCopyOfSocket__re; \ +}) + +#define __Errno() ({ \ + LONG _Errno__re = \ + ({ \ + register struct Library * const __Errno__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __Errno__re __asm("d0"); \ + __asm volatile ("jsr a6@(-162:W)" \ + : "=r"(__Errno__re) \ + : "r"(__Errno__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __Errno__re; \ + }); \ + _Errno__re; \ +}) + +#define __SetErrnoPtr(errno_ptr, size) ({ \ + APTR _SetErrnoPtr_errno_ptr = (errno_ptr); \ + LONG _SetErrnoPtr_size = (size); \ + { \ + register struct Library * const __SetErrnoPtr__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register APTR __SetErrnoPtr_errno_ptr __asm("a0") = (_SetErrnoPtr_errno_ptr); \ + register LONG __SetErrnoPtr_size __asm("d0") = (_SetErrnoPtr_size); \ + __asm volatile ("jsr a6@(-168:W)" \ + : \ + : "r"(__SetErrnoPtr__bn), "r"(__SetErrnoPtr_errno_ptr), "r"(__SetErrnoPtr_size) \ + : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + } \ +}) + +#define __Inet_NtoA(ip) ({ \ + ULONG _Inet_NtoA_ip = (ip); \ + STRPTR _Inet_NtoA__re = \ + ({ \ + register struct Library * const __Inet_NtoA__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register STRPTR __Inet_NtoA__re __asm("d0"); \ + register ULONG __Inet_NtoA_ip __asm("d0") = (_Inet_NtoA_ip); \ + __asm volatile ("jsr a6@(-174:W)" \ + : "=r"(__Inet_NtoA__re) \ + : "r"(__Inet_NtoA__bn), "r"(__Inet_NtoA_ip) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __Inet_NtoA__re; \ + }); \ + _Inet_NtoA__re; \ +}) + +#define __inet_addr(cp) ({ \ + STRPTR _inet_addr_cp = (cp); \ + ULONG _inet_addr__re = \ + ({ \ + register struct Library * const __inet_addr__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register ULONG __inet_addr__re __asm("d0"); \ + register STRPTR __inet_addr_cp __asm("a0") = (_inet_addr_cp); \ + __asm volatile ("jsr a6@(-180:W)" \ + : "=r"(__inet_addr__re) \ + : "r"(__inet_addr__bn), "r"(__inet_addr_cp) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __inet_addr__re; \ + }); \ + _inet_addr__re; \ +}) + +#define __Inet_LnaOf(in) ({ \ + ULONG _Inet_LnaOf_in = (in); \ + ULONG _Inet_LnaOf__re = \ + ({ \ + register struct Library * const __Inet_LnaOf__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register ULONG __Inet_LnaOf__re __asm("d0"); \ + register ULONG __Inet_LnaOf_in __asm("d0") = (_Inet_LnaOf_in); \ + __asm volatile ("jsr a6@(-186:W)" \ + : "=r"(__Inet_LnaOf__re) \ + : "r"(__Inet_LnaOf__bn), "r"(__Inet_LnaOf_in) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __Inet_LnaOf__re; \ + }); \ + _Inet_LnaOf__re; \ +}) + +#define __Inet_NetOf(in) ({ \ + ULONG _Inet_NetOf_in = (in); \ + ULONG _Inet_NetOf__re = \ + ({ \ + register struct Library * const __Inet_NetOf__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register ULONG __Inet_NetOf__re __asm("d0"); \ + register ULONG __Inet_NetOf_in __asm("d0") = (_Inet_NetOf_in); \ + __asm volatile ("jsr a6@(-192:W)" \ + : "=r"(__Inet_NetOf__re) \ + : "r"(__Inet_NetOf__bn), "r"(__Inet_NetOf_in) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __Inet_NetOf__re; \ + }); \ + _Inet_NetOf__re; \ +}) + +#define __Inet_MakeAddr(net, host) ({ \ + ULONG _Inet_MakeAddr_net = (net); \ + ULONG _Inet_MakeAddr_host = (host); \ + ULONG _Inet_MakeAddr__re = \ + ({ \ + register struct Library * const __Inet_MakeAddr__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register ULONG __Inet_MakeAddr__re __asm("d0"); \ + register ULONG __Inet_MakeAddr_net __asm("d0") = (_Inet_MakeAddr_net); \ + register ULONG __Inet_MakeAddr_host __asm("d1") = (_Inet_MakeAddr_host); \ + __asm volatile ("jsr a6@(-198:W)" \ + : "=r"(__Inet_MakeAddr__re) \ + : "r"(__Inet_MakeAddr__bn), "r"(__Inet_MakeAddr_net), "r"(__Inet_MakeAddr_host) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __Inet_MakeAddr__re; \ + }); \ + _Inet_MakeAddr__re; \ +}) + +#define __inet_network(cp) ({ \ + STRPTR _inet_network_cp = (cp); \ + ULONG _inet_network__re = \ + ({ \ + register struct Library * const __inet_network__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register ULONG __inet_network__re __asm("d0"); \ + register STRPTR __inet_network_cp __asm("a0") = (_inet_network_cp); \ + __asm volatile ("jsr a6@(-204:W)" \ + : "=r"(__inet_network__re) \ + : "r"(__inet_network__bn), "r"(__inet_network_cp) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __inet_network__re; \ + }); \ + _inet_network__re; \ +}) + +#define __gethostbyname(name) ({ \ + STRPTR _gethostbyname_name = (name); \ + struct hostent * _gethostbyname__re = \ + ({ \ + register struct Library * const __gethostbyname__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register struct hostent * __gethostbyname__re __asm("d0"); \ + register STRPTR __gethostbyname_name __asm("a0") = (_gethostbyname_name); \ + __asm volatile ("jsr a6@(-210:W)" \ + : "=r"(__gethostbyname__re) \ + : "r"(__gethostbyname__bn), "r"(__gethostbyname_name) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __gethostbyname__re; \ + }); \ + _gethostbyname__re; \ +}) + +#define __gethostbyaddr(addr, len, type) ({ \ + STRPTR _gethostbyaddr_addr = (addr); \ + LONG _gethostbyaddr_len = (len); \ + LONG _gethostbyaddr_type = (type); \ + struct hostent * _gethostbyaddr__re = \ + ({ \ + register struct Library * const __gethostbyaddr__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register struct hostent * __gethostbyaddr__re __asm("d0"); \ + register STRPTR __gethostbyaddr_addr __asm("a0") = (_gethostbyaddr_addr); \ + register LONG __gethostbyaddr_len __asm("d0") = (_gethostbyaddr_len); \ + register LONG __gethostbyaddr_type __asm("d1") = (_gethostbyaddr_type); \ + __asm volatile ("jsr a6@(-216:W)" \ + : "=r"(__gethostbyaddr__re) \ + : "r"(__gethostbyaddr__bn), "r"(__gethostbyaddr_addr), "r"(__gethostbyaddr_len), "r"(__gethostbyaddr_type) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __gethostbyaddr__re; \ + }); \ + _gethostbyaddr__re; \ +}) + +#define __getnetbyname(name) ({ \ + STRPTR _getnetbyname_name = (name); \ + struct netent * _getnetbyname__re = \ + ({ \ + register struct Library * const __getnetbyname__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register struct netent * __getnetbyname__re __asm("d0"); \ + register STRPTR __getnetbyname_name __asm("a0") = (_getnetbyname_name); \ + __asm volatile ("jsr a6@(-222:W)" \ + : "=r"(__getnetbyname__re) \ + : "r"(__getnetbyname__bn), "r"(__getnetbyname_name) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getnetbyname__re; \ + }); \ + _getnetbyname__re; \ +}) + +#define __getnetbyaddr(net, type) ({ \ + ULONG _getnetbyaddr_net = (net); \ + LONG _getnetbyaddr_type = (type); \ + struct netent * _getnetbyaddr__re = \ + ({ \ + register struct Library * const __getnetbyaddr__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register struct netent * __getnetbyaddr__re __asm("d0"); \ + register ULONG __getnetbyaddr_net __asm("d0") = (_getnetbyaddr_net); \ + register LONG __getnetbyaddr_type __asm("d1") = (_getnetbyaddr_type); \ + __asm volatile ("jsr a6@(-228:W)" \ + : "=r"(__getnetbyaddr__re) \ + : "r"(__getnetbyaddr__bn), "r"(__getnetbyaddr_net), "r"(__getnetbyaddr_type) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getnetbyaddr__re; \ + }); \ + _getnetbyaddr__re; \ +}) + +#define __getservbyname(name, proto) ({ \ + STRPTR _getservbyname_name = (name); \ + STRPTR _getservbyname_proto = (proto); \ + struct servent * _getservbyname__re = \ + ({ \ + register struct Library * const __getservbyname__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register struct servent * __getservbyname__re __asm("d0"); \ + register STRPTR __getservbyname_name __asm("a0") = (_getservbyname_name); \ + register STRPTR __getservbyname_proto __asm("a1") = (_getservbyname_proto); \ + __asm volatile ("jsr a6@(-234:W)" \ + : "=r"(__getservbyname__re) \ + : "r"(__getservbyname__bn), "r"(__getservbyname_name), "r"(__getservbyname_proto) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getservbyname__re; \ + }); \ + _getservbyname__re; \ +}) + +#define __getservbyport(port, proto) ({ \ + LONG _getservbyport_port = (port); \ + STRPTR _getservbyport_proto = (proto); \ + struct servent * _getservbyport__re = \ + ({ \ + register struct Library * const __getservbyport__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register struct servent * __getservbyport__re __asm("d0"); \ + register LONG __getservbyport_port __asm("d0") = (_getservbyport_port); \ + register STRPTR __getservbyport_proto __asm("a0") = (_getservbyport_proto); \ + __asm volatile ("jsr a6@(-240:W)" \ + : "=r"(__getservbyport__re) \ + : "r"(__getservbyport__bn), "r"(__getservbyport_port), "r"(__getservbyport_proto) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getservbyport__re; \ + }); \ + _getservbyport__re; \ +}) + +#define __getprotobyname(name) ({ \ + STRPTR _getprotobyname_name = (name); \ + struct protoent * _getprotobyname__re = \ + ({ \ + register struct Library * const __getprotobyname__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register struct protoent * __getprotobyname__re __asm("d0"); \ + register STRPTR __getprotobyname_name __asm("a0") = (_getprotobyname_name); \ + __asm volatile ("jsr a6@(-246:W)" \ + : "=r"(__getprotobyname__re) \ + : "r"(__getprotobyname__bn), "r"(__getprotobyname_name) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getprotobyname__re; \ + }); \ + _getprotobyname__re; \ +}) + +#define __getprotobynumber(proto) ({ \ + LONG _getprotobynumber_proto = (proto); \ + struct protoent * _getprotobynumber__re = \ + ({ \ + register struct Library * const __getprotobynumber__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register struct protoent * __getprotobynumber__re __asm("d0"); \ + register LONG __getprotobynumber_proto __asm("d0") = (_getprotobynumber_proto); \ + __asm volatile ("jsr a6@(-252:W)" \ + : "=r"(__getprotobynumber__re) \ + : "r"(__getprotobynumber__bn), "r"(__getprotobynumber_proto) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getprotobynumber__re; \ + }); \ + _getprotobynumber__re; \ +}) + +#define __vsyslog(pri, msg, args) ({ \ + LONG _vsyslog_pri = (pri); \ + STRPTR _vsyslog_msg = (msg); \ + APTR _vsyslog_args = (args); \ + { \ + register struct Library * const __vsyslog__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __vsyslog_pri __asm("d0") = (_vsyslog_pri); \ + register STRPTR __vsyslog_msg __asm("a0") = (_vsyslog_msg); \ + register APTR __vsyslog_args __asm("a1") = (_vsyslog_args); \ + __asm volatile ("jsr a6@(-258:W)" \ + : \ + : "r"(__vsyslog__bn), "r"(__vsyslog_pri), "r"(__vsyslog_msg), "r"(__vsyslog_args) \ + : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + } \ +}) + +#define __Dup2Socket(old_socket, new_socket) ({ \ + LONG _Dup2Socket_old_socket = (old_socket); \ + LONG _Dup2Socket_new_socket = (new_socket); \ + LONG _Dup2Socket__re = \ + ({ \ + register struct Library * const __Dup2Socket__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __Dup2Socket__re __asm("d0"); \ + register LONG __Dup2Socket_old_socket __asm("d0") = (_Dup2Socket_old_socket); \ + register LONG __Dup2Socket_new_socket __asm("d1") = (_Dup2Socket_new_socket); \ + __asm volatile ("jsr a6@(-264:W)" \ + : "=r"(__Dup2Socket__re) \ + : "r"(__Dup2Socket__bn), "r"(__Dup2Socket_old_socket), "r"(__Dup2Socket_new_socket) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __Dup2Socket__re; \ + }); \ + _Dup2Socket__re; \ +}) + +#define __sendmsg(sock, msg, flags) ({ \ + LONG _sendmsg_sock = (sock); \ + struct msghdr * _sendmsg_msg = (msg); \ + LONG _sendmsg_flags = (flags); \ + LONG _sendmsg__re = \ + ({ \ + register struct Library * const __sendmsg__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __sendmsg__re __asm("d0"); \ + register LONG __sendmsg_sock __asm("d0") = (_sendmsg_sock); \ + register struct msghdr * __sendmsg_msg __asm("a0") = (_sendmsg_msg); \ + register LONG __sendmsg_flags __asm("d1") = (_sendmsg_flags); \ + __asm volatile ("jsr a6@(-270:W)" \ + : "=r"(__sendmsg__re) \ + : "r"(__sendmsg__bn), "r"(__sendmsg_sock), "r"(__sendmsg_msg), "r"(__sendmsg_flags) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __sendmsg__re; \ + }); \ + _sendmsg__re; \ +}) + +#define __recvmsg(sock, msg, flags) ({ \ + LONG _recvmsg_sock = (sock); \ + struct msghdr * _recvmsg_msg = (msg); \ + LONG _recvmsg_flags = (flags); \ + LONG _recvmsg__re = \ + ({ \ + register struct Library * const __recvmsg__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __recvmsg__re __asm("d0"); \ + register LONG __recvmsg_sock __asm("d0") = (_recvmsg_sock); \ + register struct msghdr * __recvmsg_msg __asm("a0") = (_recvmsg_msg); \ + register LONG __recvmsg_flags __asm("d1") = (_recvmsg_flags); \ + __asm volatile ("jsr a6@(-276:W)" \ + : "=r"(__recvmsg__re) \ + : "r"(__recvmsg__bn), "r"(__recvmsg_sock), "r"(__recvmsg_msg), "r"(__recvmsg_flags) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __recvmsg__re; \ + }); \ + _recvmsg__re; \ +}) + +#define __gethostname(name, namelen) ({ \ + STRPTR _gethostname_name = (name); \ + LONG _gethostname_namelen = (namelen); \ + LONG _gethostname__re = \ + ({ \ + register struct Library * const __gethostname__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __gethostname__re __asm("d0"); \ + register STRPTR __gethostname_name __asm("a0") = (_gethostname_name); \ + register LONG __gethostname_namelen __asm("d0") = (_gethostname_namelen); \ + __asm volatile ("jsr a6@(-282:W)" \ + : "=r"(__gethostname__re) \ + : "r"(__gethostname__bn), "r"(__gethostname_name), "r"(__gethostname_namelen) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __gethostname__re; \ + }); \ + _gethostname__re; \ +}) + +#define __gethostid() ({ \ + ULONG _gethostid__re = \ + ({ \ + register struct Library * const __gethostid__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register ULONG __gethostid__re __asm("d0"); \ + __asm volatile ("jsr a6@(-288:W)" \ + : "=r"(__gethostid__re) \ + : "r"(__gethostid__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __gethostid__re; \ + }); \ + _gethostid__re; \ +}) + +#define __SocketBaseTagList(tags) ({ \ + struct TagItem * _SocketBaseTagList_tags = (tags); \ + LONG _SocketBaseTagList__re = \ + ({ \ + register struct Library * const __SocketBaseTagList__bn __asm("a6") = (struct Library *) (__SocketBase);\ + register LONG __SocketBaseTagList__re __asm("d0"); \ + register struct TagItem * __SocketBaseTagList_tags __asm("a0") = (_SocketBaseTagList_tags); \ + __asm volatile ("jsr a6@(-294:W)" \ + : "=r"(__SocketBaseTagList__re) \ + : "r"(__SocketBaseTagList__bn), "r"(__SocketBaseTagList_tags) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __SocketBaseTagList__re; \ + }); \ + _SocketBaseTagList__re; \ +}) + +#endif /* __amigaos4__ */ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#if defined(__SASC) + +LONG __socket(LONG domain,LONG type,LONG protocol); +LONG __bind(LONG sock,struct sockaddr *name,LONG namelen); +LONG __listen(LONG sock,LONG backlog); +LONG __accept(LONG sock,struct sockaddr *addr,LONG *addrlen); +LONG __connect(LONG sock,struct sockaddr *name,LONG namelen); +LONG __sendto(LONG sock,APTR buf,LONG len,LONG flags,struct sockaddr *to,LONG tolen); +LONG __send(LONG sock,APTR buf,LONG len,LONG flags); +LONG __recvfrom(LONG sock,APTR buf,LONG len,LONG flags,struct sockaddr *addr,LONG *addrlen); +LONG __recv(LONG sock,APTR buf,LONG len,LONG flags); +LONG __shutdown(LONG sock,LONG how); +LONG __setsockopt(LONG sock,LONG level,LONG optname,APTR optval,LONG optlen); +LONG __getsockopt(LONG sock,LONG level,LONG optname,APTR optval,LONG *optlen); +LONG __getsockname(LONG sock,struct sockaddr *name,LONG *namelen); +LONG __getpeername(LONG sock,struct sockaddr *name,LONG *namelen); +LONG __IoctlSocket(LONG sock,ULONG req,APTR argp); +LONG __CloseSocket(LONG sock); +LONG __WaitSelect(LONG nfds,APTR read_fds,APTR write_fds,APTR except_fds,struct timeval *timeout,ULONG *signals); +VOID __SetSocketSignals(ULONG int_mask,ULONG io_mask,ULONG urgent_mask); +LONG __getdtablesize(VOID); +LONG __ObtainSocket(LONG id,LONG domain,LONG type,LONG protocol); +LONG __ReleaseSocket(LONG sock,LONG id); +LONG __ReleaseCopyOfSocket(LONG sock,LONG id); +LONG __Errno(VOID); +VOID __SetErrnoPtr(APTR errno_ptr,LONG size); +STRPTR __Inet_NtoA(ULONG ip); +ULONG __inet_addr(STRPTR cp); +ULONG __Inet_LnaOf(ULONG in); +ULONG __Inet_NetOf(ULONG in); +ULONG __Inet_MakeAddr(ULONG net,ULONG host); +ULONG __inet_network(STRPTR cp); +struct hostent *__gethostbyname(STRPTR name); +struct hostent *__gethostbyaddr(STRPTR addr,LONG len,LONG type); +struct netent *__getnetbyname(STRPTR name); +struct netent *__getnetbyaddr(LONG net,LONG type); +struct servent *__getservbyname(STRPTR name,STRPTR proto); +struct servent *__getservbyport(LONG port,STRPTR proto); +struct protoent *__getprotobyname(STRPTR name); +struct protoent *__getprotobynumber(LONG proto); +VOID __vsyslog(LONG pri,STRPTR msg,APTR args); +LONG __Dup2Socket(LONG old_socket,LONG new_socket); +LONG __sendmsg(LONG sock,struct msghdr *msg,LONG flags); +LONG __recvmsg(LONG sock,struct msghdr *msg,LONG flags); +LONG __gethostname(STRPTR name,LONG namelen); +ULONG __gethostid(VOID); +LONG __SocketBaseTagList(struct TagItem *tags); + +#pragma libcall __SocketBase __socket 01e 21003 +#pragma libcall __SocketBase __bind 024 18003 +#pragma libcall __SocketBase __listen 02a 1002 +#pragma libcall __SocketBase __accept 030 98003 +#pragma libcall __SocketBase __connect 036 18003 +#pragma libcall __SocketBase __sendto 03c 39218006 +#pragma libcall __SocketBase __send 042 218004 +#pragma libcall __SocketBase __recvfrom 048 a9218006 +#pragma libcall __SocketBase __recv 04e 218004 +#pragma libcall __SocketBase __shutdown 054 1002 +#pragma libcall __SocketBase __setsockopt 05a 3821005 +#pragma libcall __SocketBase __getsockopt 060 9821005 +#pragma libcall __SocketBase __getsockname 066 98003 +#pragma libcall __SocketBase __getpeername 06c 98003 +#pragma libcall __SocketBase __IoctlSocket 072 81003 +#pragma libcall __SocketBase __CloseSocket 078 001 +#pragma libcall __SocketBase __WaitSelect 07e 1ba98006 +#pragma libcall __SocketBase __SetSocketSignals 084 21003 +#pragma libcall __SocketBase __getdtablesize 08a 00 +#pragma libcall __SocketBase __ObtainSocket 090 321004 +#pragma libcall __SocketBase __ReleaseSocket 096 1002 +#pragma libcall __SocketBase __ReleaseCopyOfSocket 09c 1002 +#pragma libcall __SocketBase __Errno 0a2 00 +#pragma libcall __SocketBase __SetErrnoPtr 0a8 0802 +#pragma libcall __SocketBase __Inet_NtoA 0ae 001 +#pragma libcall __SocketBase __inet_addr 0b4 801 +#pragma libcall __SocketBase __Inet_LnaOf 0ba 001 +#pragma libcall __SocketBase __Inet_NetOf 0c0 001 +#pragma libcall __SocketBase __Inet_MakeAddr 0c6 1002 +#pragma libcall __SocketBase __inet_network 0cc 801 +#pragma libcall __SocketBase __gethostbyname 0d2 801 +#pragma libcall __SocketBase __gethostbyaddr 0d8 10803 +#pragma libcall __SocketBase __getnetbyname 0de 801 +#pragma libcall __SocketBase __getnetbyaddr 0e4 1002 +#pragma libcall __SocketBase __getservbyname 0ea 9802 +#pragma libcall __SocketBase __getservbyport 0f0 8002 +#pragma libcall __SocketBase __getprotobyname 0f6 801 +#pragma libcall __SocketBase __getprotobynumber 0fc 001 +#pragma libcall __SocketBase __vsyslog 102 98003 +#pragma libcall __SocketBase __Dup2Socket 108 1002 +#pragma libcall __SocketBase __sendmsg 10e 18003 +#pragma libcall __SocketBase __recvmsg 114 18003 +#pragma libcall __SocketBase __gethostname 11a 0802 +#pragma libcall __SocketBase __gethostid 120 00 +#pragma libcall __SocketBase __SocketBaseTagList 126 801 + +#endif /* __SASC */ + +/****************************************************************************/ + +#endif /* _SOCKET_HEADERS_H */ diff --git a/library/socket_hook_entry.c b/library/socket_hook_entry.c new file mode 100644 index 0000000..3eb198b --- /dev/null +++ b/library/socket_hook_entry.c @@ -0,0 +1,168 @@ +/* + * $Id: socket_hook_entry.c,v 1.1.1.1 2004-07-26 16:31:14 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +void +__socket_hook_entry( + struct Hook * UNUSED unused_hook, + struct fd * fd, + struct file_hook_message * message) +{ + struct FileInfoBlock * fib; + int error = OK; + int result; + + assert( message != NULL && fd != NULL ); + + switch(message->action) + { + case file_hook_action_read: + + SHOWMSG("file_hook_action_read"); + + assert( message->data != NULL ); + assert( message->size > 0 ); + + SHOWVALUE(message->data); + SHOWVALUE(message->size); + + PROFILE_OFF(); + + result = __recv((LONG)fd->fd_DefaultFile,message->data,message->size,0); + error = errno; + + PROFILE_ON(); + + break; + + case file_hook_action_write: + + SHOWMSG("file_hook_action_write"); + + assert( message->data != NULL ); + assert( message->size > 0 ); + + SHOWVALUE(message->data); + SHOWVALUE(message->size); + + PROFILE_OFF(); + + result = __send((LONG)fd->fd_DefaultFile,message->data,message->size,0); + error = errno; + + PROFILE_ON(); + + break; + + case file_hook_action_close: + + SHOWMSG("file_hook_action_close"); + + PROFILE_OFF(); + + __CloseSocket((LONG)fd->fd_DefaultFile); + + PROFILE_ON(); + + fd->fd_DefaultFile = -1; /* paranoia! */ + + result = 0; + + break; + + case file_hook_action_duplicate_fd: + + SHOWMSG("file_hook_action_duplicate_fd"); + + __duplicate_fd(message->duplicate_fd,fd); + + result = 0; + + break; + + case file_hook_action_seek: + case file_hook_action_seek_and_extend: + + SHOWMSG("file_hook_action_seek"); + + result = -1; + error = ESPIPE; + + break; + + case file_hook_action_examine: + + SHOWMSG("file_hook_action_examine"); + + fib = message->file_info; + + memset(fib,0,sizeof(*fib)); + + fib->fib_DirEntryType = ST_SOCKET; + + PROFILE_OFF(); + DateStamp(&fib->fib_Date); + PROFILE_ON(); + + result = 0; + + break; + + default: + + SHOWVALUE(message->action); + + result = -1; + error = EBADF; + + break; + } + + SHOWVALUE(result); + + message->result = result; + message->error = error; +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_inet_addr.c b/library/socket_inet_addr.c new file mode 100644 index 0000000..234343c --- /dev/null +++ b/library/socket_inet_addr.c @@ -0,0 +1,89 @@ +/* + * $Id: socket_inet_addr.c,v 1.1.1.1 2004-07-26 16:31:14 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +unsigned long +inet_addr(const char *addr) +{ + unsigned long result = 0xFFFFFFFFUL; + + ENTER(); + + SHOWSTRING(addr); + + assert(addr != NULL); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(addr == NULL) + { + SHOWMSG("invalid parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __inet_addr((char *)addr); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_inet_aton.c b/library/socket_inet_aton.c new file mode 100644 index 0000000..086be2c --- /dev/null +++ b/library/socket_inet_aton.c @@ -0,0 +1,201 @@ +/* + * $Id: socket_inet_aton.c,v 1.1.1.1 2004-07-26 16:31:15 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +/* + * Copyright (c) 1983, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +/* + * Check whether "cp" is a valid ascii representation + * of an Internet address and convert to a binary address. + * Returns 1 if the address is valid, 0 if not. + * This replaces inet_addr, the return value from which + * cannot distinguish between failure and a local broadcast address. + */ +int +inet_aton(const char *cp, struct in_addr *addr) +{ + ULONG val = 0; + int base, n; + char c; + LONG parts[4]; + LONG *pp = parts; + + assert( cp != NULL && addr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(cp == NULL || addr == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + return(0); + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + for (;;) { + /* + * Collect number up to ``.''. + * Values are specified as for C: + * 0x=hex, 0=octal, other=decimal. + */ + val = 0; base = 10; + if (*cp == '0') { + if (*++cp == 'x' || *cp == 'X') + base = 16, cp++; + else + base = 8; + } + while ((c = *cp) != '\0') { + if (isascii(c) && isdigit(c)) { + val = (val * base) + (c - '0'); + cp++; + continue; + } + if (base == 16 && isascii(c) && isxdigit(c)) { + val = (val << 4) + + (c + 10 - (islower(c) ? 'a' : 'A')); + cp++; + continue; + } + break; + } + if (*cp == '.') { + /* + * Internet format: + * a.b.c.d + * a.b.c (with c treated as 16-bits) + * a.b (with b treated as 24 bits) + */ + if (pp >= parts + 3 || val > 0xff) + return (0); + *pp++ = val, cp++; + } else + break; + } + /* + * Check for trailing characters. + */ + if (*cp && (!isascii(*cp) || !isspace(*cp))) + return (0); + /* + * Concoct the address according to + * the number of parts specified. + */ + n = pp - parts + 1; + switch (n) { + + case 1: /* a -- 32 bits */ + break; + + case 2: /* a.b -- 8.24 bits */ + if (val > 0xffffff) + return (0); + val |= parts[0] << 24; + break; + + case 3: /* a.b.c -- 8.8.16 bits */ + if (val > 0xffff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16); + break; + + case 4: /* a.b.c.d -- 8.8.8.8 bits */ + if (val > 0xff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); + break; + + default: + + return(0); + } + if (addr) + addr->s_addr = val; + return (1); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_inet_lnaof.c b/library/socket_inet_lnaof.c new file mode 100644 index 0000000..f05cb09 --- /dev/null +++ b/library/socket_inet_lnaof.c @@ -0,0 +1,66 @@ +/* + * $Id: socket_inet_lnaof.c,v 1.1.1.1 2004-07-26 16:31:15 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +unsigned long +inet_lnaof(struct in_addr in) +{ + unsigned long result; + + ENTER(); + + assert(__SocketBase != NULL); + + PROFILE_OFF(); + result = __Inet_LnaOf(in.s_addr); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_inet_makeaddr.c b/library/socket_inet_makeaddr.c new file mode 100644 index 0000000..25bf0ec --- /dev/null +++ b/library/socket_inet_makeaddr.c @@ -0,0 +1,66 @@ +/* + * $Id: socket_inet_makeaddr.c,v 1.1.1.1 2004-07-26 16:31:15 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +struct in_addr +inet_makeaddr(int net,int host) +{ + struct in_addr result; + + ENTER(); + + assert(__SocketBase != NULL); + + PROFILE_OFF(); + result.s_addr = __Inet_MakeAddr((ULONG)net,(ULONG)host); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result.s_addr); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_inet_netof.c b/library/socket_inet_netof.c new file mode 100644 index 0000000..1d0bd90 --- /dev/null +++ b/library/socket_inet_netof.c @@ -0,0 +1,66 @@ +/* + * $Id: socket_inet_netof.c,v 1.1.1.1 2004-07-26 16:31:15 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +unsigned long +inet_netof(struct in_addr in) +{ + unsigned long result; + + ENTER(); + + assert(__SocketBase != NULL); + + PROFILE_OFF(); + result = __Inet_NetOf(in.s_addr); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_inet_network.c b/library/socket_inet_network.c new file mode 100644 index 0000000..8b4fb3d --- /dev/null +++ b/library/socket_inet_network.c @@ -0,0 +1,87 @@ +/* + * $Id: socket_inet_network.c,v 1.1.1.1 2004-07-26 16:31:16 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +unsigned long +inet_network(const char *cp) +{ + unsigned long result = ~0UL; + + ENTER(); + + assert(cp != NULL); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(cp == NULL) + { + SHOWMSG("invalid cp parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __inet_network((char *)cp); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_inet_ntoa.c b/library/socket_inet_ntoa.c new file mode 100644 index 0000000..8278ebe --- /dev/null +++ b/library/socket_inet_ntoa.c @@ -0,0 +1,72 @@ +/* + * $Id: socket_inet_ntoa.c,v 1.1.1.1 2004-07-26 16:31:16 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +char * +inet_ntoa(struct in_addr in) +{ + char *result; + + ENTER(); + + SHOWVALUE(in.s_addr); + + assert(__SocketBase != NULL); + + PROFILE_OFF(); + result = __Inet_NtoA(in.s_addr); + PROFILE_ON(); + + SHOWSTRING(result); + + if(__check_abort_enabled) + __check_abort(); + + out: + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_init_exit.c b/library/socket_init_exit.c new file mode 100644 index 0000000..88d8d0c --- /dev/null +++ b/library/socket_init_exit.c @@ -0,0 +1,313 @@ +/* + * $Id: socket_init_exit.c,v 1.1.1.1 2004-07-26 16:31:16 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +#include "stdlib_protos.h" + +/****************************************************************************/ + +extern BOOL __detach; + +/****************************************************************************/ + +/* Code value. */ +#define SBTB_CODE 1 +#define SBTS_CODE 0x3FFF + +/* Set a parameter, passing it by value. */ +#ifndef SBTM_SETVAL +#define SBTM_SETVAL(code) (TAG_USER | (((code) & SBTS_CODE) << SBTB_CODE) | 1) +#endif /* SBTM_SETVAL */ + +#define SBTC_BREAKMASK 1 /* Interrupt signal mask */ +#define SBTC_LOGTAGPTR 11 /* Under which name log entries are filed */ +#define SBTC_ERRNOLONGPTR 24 /* Pointer to errno, length == sizeof(errno) */ + +/****************************************************************************/ + +struct DaemonMessage +{ + struct Message dm_Message; + ULONG dm_Pad1; + ULONG dm_Pad2; + LONG dm_ID; + ULONG dm_Pad3; + UBYTE dm_Family; + UBYTE dm_Type; +}; + +/****************************************************************************/ + +extern BOOL __termination_message_disabled; +extern char * __program_name; +extern BOOL __is_daemon; + +/****************************************************************************/ + +extern void __show_error(const char * message); + +/****************************************************************************/ + +extern void __socket_hook_entry(struct Hook * hook,struct fd * fd,struct file_hook_message * message); + +/****************************************************************************/ + +void +__socket_exit(void) +{ + ENTER(); + + /* Disable ^C checking. */ + if(__SocketBase != NULL) + { + struct TagItem tags[2]; + + tags[0].ti_Tag = SBTM_SETVAL(SBTC_BREAKMASK); + tags[0].ti_Data = 0; + tags[1].ti_Tag = TAG_END; + + PROFILE_OFF(); + __SocketBaseTagList(tags); + PROFILE_ON(); + } + + /* Careful: if this function is ever invoked, it must make sure that + * the socket file descriptors are invalidated. If that + * does not happen, the stdio cleanup function will + * crash (with bells on). + */ + if(__fd != NULL) + { + int i; + + for(i = 0 ; i < __num_fd ; i++) + { + if(FLAG_IS_SET(__fd[i]->fd_Flags,FDF_IS_SOCKET) && FLAG_IS_SET(__fd[i]->fd_Flags,FDF_IN_USE)) + close(i); + } + } + + #if defined(__amigaos4__) + { + if(__ISocket != NULL) + { + DropInterface((struct Interface *)__ISocket); + __ISocket = NULL; + } + } + #endif /* __amigaos4__ */ + + if(__SocketBase != NULL) + { + CloseLibrary(__SocketBase); + __SocketBase = NULL; + } + + LEAVE(); +} + +/****************************************************************************/ + +int +__socket_init(void) +{ + struct Process * this_process; + struct TagItem tags[4]; + int result = ERROR; + LONG status; + + ENTER(); + + PROFILE_OFF(); + + /* bsdsocket.library V3 is sufficient for all the tasks we + * may have to perform. + */ + __SocketBase = OpenLibrary("bsdsocket.library",3); + + #if defined(__amigaos4__) + { + if(__SocketBase != NULL) + { + __ISocket = (struct SocketIFace *)GetInterface(__SocketBase, "main", 1, 0); + if (__ISocket == NULL) + { + CloseLibrary(__SocketBase); + __SocketBase = NULL; + } + } + } + #endif /* __amigaos4__ */ + + PROFILE_ON(); + + if(__SocketBase == NULL) + { + SHOWMSG("bsdsocket.library V3 didn't open"); + + __show_error("\"bsdsocket.library\" V3 could not be opened."); + goto out; + } + + /* Wire the library's errno variable to our local errno. */ + tags[0].ti_Tag = SBTM_SETVAL(SBTC_ERRNOLONGPTR); + tags[0].ti_Data = (ULONG)&errno; + + /* Also enable ^C checking if desired. */ + tags[1].ti_Tag = SBTM_SETVAL(SBTC_BREAKMASK); + + if(__check_abort_enabled) + tags[1].ti_Data = SIGBREAKF_CTRL_C; + else + tags[1].ti_Data = 0; + + tags[2].ti_Tag = SBTM_SETVAL(SBTC_LOGTAGPTR); + tags[2].ti_Data = (ULONG)__program_name; + + tags[3].ti_Tag = TAG_END; + + PROFILE_OFF(); + status = __SocketBaseTagList(tags); + PROFILE_ON(); + + if(status != 0) + { + SHOWMSG("couldn't initialize the library"); + + __show_error("\"bsdsocket.library\" could not be initialized."); + goto out; + } + + /* Check if this program was launched as a server by the Internet + * superserver. + */ + this_process = (struct Process *)FindTask(NULL); + if(this_process->pr_CLI != ZERO && NOT __detach) + { + struct DaemonMessage * dm; + + /* The socket the superserver may have launched this program + * with is attached to the exit data entry of the process. + */ + dm = (struct DaemonMessage *)this_process->pr_ExitData; + if(TypeOfMem(dm) != 0 && TypeOfMem(((char *)dm) + sizeof(*dm)-1) != 0) + { + int daemon_socket; + struct fd * fd; + int sockfd; + int i; + + SHOWMSG("we have a daemon message; this is a server"); + + /* Try to grab that socket and attach is to the three + * standard I/O streams. + */ + + PROFILE_OFF(); + daemon_socket = __ObtainSocket(dm->dm_ID,dm->dm_Family,dm->dm_Type,0); + PROFILE_ON(); + + if(daemon_socket == -1) + { + __show_error("Network server streams could not be initialized."); + goto out; + } + + SHOWVALUE(daemon_socket); + + /* Whatever happens, the following likely won't end up + * in the console... + */ + __termination_message_disabled = TRUE; + + /* Shut down the three standard I/O streams. */ + for(i = STDIN_FILENO ; i <= STDERR_FILENO ; i++) + close(i); + + /* Put the socket into the three standard I/O streams. */ + for(i = STDIN_FILENO ; i <= STDERR_FILENO ; i++) + { + fd = __fd[i]; + + assert( fd != NULL && FLAG_IS_CLEAR(fd->fd_Flags,FDF_IN_USE) ); + + if(i == STDIN_FILENO) + { + sockfd = daemon_socket; + } + else + { + PROFILE_OFF(); + sockfd = __Dup2Socket(daemon_socket,-1); + PROFILE_ON(); + + if(sockfd == -1) + { + SHOWMSG("could not duplicate daemon socket"); + + __show_error("Network server streams could not be initialized."); + goto out; + } + } + + __initialize_fd(fd,(HOOKFUNC)__socket_hook_entry,(BPTR)sockfd,FDF_IN_USE | FDF_IS_SOCKET | FDF_READ | FDF_WRITE); + } + + /* This program now runs as an internet superserver client (daemon). */ + __is_daemon = TRUE; + + /* The standard I/O streams are no longer attached to a console. */ + __no_standard_io = TRUE; + } + } + + result = OK; + + out: + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_ioctl.c b/library/socket_ioctl.c new file mode 100644 index 0000000..fa0abd6 --- /dev/null +++ b/library/socket_ioctl.c @@ -0,0 +1,97 @@ +/* + * $Id: socket_ioctl.c,v 1.1.1.1 2004-07-26 16:31:16 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +#ifndef _STDARG_H +#include +#endif /* _STDARG_H */ + +/****************************************************************************/ + +int +ioctl(int sockfd,unsigned long request, ... /* char *arg */) +{ + va_list arg; + char * param; + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWVALUE(request); + + assert(__SocketBase != NULL); + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + va_start(arg,request); + + param = va_arg(arg,char *); + + SHOWPOINTER(param); + + PROFILE_OFF(); + result = __IoctlSocket((LONG)fd->fd_DefaultFile,request,param); + PROFILE_ON(); + + va_end(arg); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_isdaemon.c b/library/socket_isdaemon.c new file mode 100644 index 0000000..f78d147 --- /dev/null +++ b/library/socket_isdaemon.c @@ -0,0 +1,48 @@ +/* + * $Id: socket_isdaemon.c,v 1.1.1.1 2004-07-26 16:31:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +BOOL __is_daemon; + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_listen.c b/library/socket_listen.c new file mode 100644 index 0000000..6b39e7d --- /dev/null +++ b/library/socket_listen.c @@ -0,0 +1,81 @@ +/* + * $Id: socket_listen.c,v 1.1.1.1 2004-07-26 16:31:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +listen(int sockfd,int backlog) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWVALUE(backlog); + + assert(__SocketBase != NULL); + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __listen((LONG)fd->fd_DefaultFile,backlog); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_recv.c b/library/socket_recv.c new file mode 100644 index 0000000..aa2454d --- /dev/null +++ b/library/socket_recv.c @@ -0,0 +1,103 @@ +/* + * $Id: socket_recv.c,v 1.1.1.1 2004-07-26 16:31:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +recv(int sockfd,void *buff,size_t nbytes,int flags) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWPOINTER(buff); + SHOWVALUE(nbytes); + SHOWVALUE(flags); + + assert( (int)nbytes >= 0 ); + assert( buff != NULL ); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(buff == NULL) + { + SHOWMSG("invalid buffer parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __recv((LONG)fd->fd_DefaultFile,buff,(LONG)nbytes,flags); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_recvfrom.c b/library/socket_recvfrom.c new file mode 100644 index 0000000..07d3945 --- /dev/null +++ b/library/socket_recvfrom.c @@ -0,0 +1,104 @@ +/* + * $Id: socket_recvfrom.c,v 1.1.1.1 2004-07-26 16:31:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +recvfrom(int sockfd,void *buff,int len,int flags,struct sockaddr *from,int *fromlen) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWPOINTER(buff); + SHOWVALUE(len); + SHOWVALUE(flags); + SHOWPOINTER(from); + SHOWPOINTER(fromlen); + + assert( buff != NULL && from != NULL && fromlen != NULL ); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(buff == NULL || from == NULL || fromlen == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __recvfrom((LONG)fd->fd_DefaultFile,buff,len,flags,from,(LONG *)fromlen); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_recvmsg.c b/library/socket_recvmsg.c new file mode 100644 index 0000000..709eb9e --- /dev/null +++ b/library/socket_recvmsg.c @@ -0,0 +1,101 @@ +/* + * $Id: socket_recvmsg.c,v 1.1.1.1 2004-07-26 16:31:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +recvmsg(int sockfd,struct msghdr *msg,int flags) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWPOINTER(msg); + SHOWVALUE(flags); + + assert( msg != NULL ); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(msg == NULL) + { + SHOWMSG("invalid msg parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __recvmsg((LONG)fd->fd_DefaultFile,msg,flags); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_select.c b/library/socket_select.c new file mode 100644 index 0000000..9caa91a --- /dev/null +++ b/library/socket_select.c @@ -0,0 +1,1018 @@ +/* + * $Id: socket_select.c,v 1.1.1.1 2004-07-26 16:31:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +static void +copy_fd_set(fd_set * to,fd_set * from,int num_fds) +{ + ENTER(); + + SHOWPOINTER(to); + SHOWPOINTER(from); + SHOWVALUE(num_fds); + + if(to != NULL && from != NULL && num_fds > 0) + { + size_t num_bytes; + + num_bytes = sizeof(unsigned long) * ((num_fds + 31) / 32); + + SHOWVALUE(num_bytes); + + memmove(to,from,num_bytes); + } + + LEAVE(); +} + +/****************************************************************************/ + +static void +zero_fd_set(fd_set * set,int num_fds) +{ + ENTER(); + + SHOWPOINTER(set); + SHOWVALUE(num_fds); + + if(set != NULL && num_fds > 0) + { + size_t num_bytes; + + num_bytes = sizeof(unsigned long) * ((num_fds + 31) / 32); + + SHOWVALUE(num_bytes); + + memset(set,0,num_bytes); + } + + LEAVE(); +} + +/****************************************************************************/ + +static fd_set * +allocate_fd_set(int num_fds,fd_set * duplicate_this_set) +{ + fd_set * result = NULL; + size_t num_bytes; + fd_set * set; + + ENTER(); + + assert( num_fds > 0 ); + + SHOWVALUE(num_fds); + + num_bytes = sizeof(unsigned long) * ((num_fds + 31) / 32); + + SHOWVALUE(num_bytes); + + set = (fd_set *)malloc(num_bytes); + if(set != NULL) + { + if(duplicate_this_set != NULL) + copy_fd_set(set,duplicate_this_set,num_fds); + else + zero_fd_set(set,num_fds); + + result = set; + } + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +static void +free_fd_set(fd_set * set) +{ + if(set != NULL) + free(set); +} + +/****************************************************************************/ + +static struct fd * +get_file_descriptor(int file_descriptor) +{ + struct fd * result = NULL; + struct fd * fd; + + if(file_descriptor < 0 || file_descriptor >= __num_fd) + goto out; + + assert( __fd != NULL ); + + fd = __fd[file_descriptor]; + + assert( fd != NULL ); + + if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_IN_USE)) + goto out; + + result = fd; + + out: + + return(result); +} + +/****************************************************************************/ + +static void +fix_datestamp(struct DateStamp * ds) +{ + const LONG ticks_per_minute = 60 * TICKS_PER_SECOND; + const LONG minutes_per_day = 24 * 60; + + assert( ds != NULL ); + + while(ds->ds_Minute >= minutes_per_day || + ds->ds_Tick >= ticks_per_minute) + { + if(ds->ds_Minute >= minutes_per_day) + { + ds->ds_Days++; + + ds->ds_Minute -= minutes_per_day; + } + + if(ds->ds_Tick >= ticks_per_minute) + { + ds->ds_Minute++; + + ds->ds_Tick -= ticks_per_minute; + } + } +} + +/****************************************************************************/ + +static struct DateStamp * +timeval_to_datestamp(struct DateStamp * ds,const struct timeval * tv) +{ + assert( ds != NULL && tv != NULL ); + + ds->ds_Days = (tv->tv_secs / (24 * 60 * 60)); + ds->ds_Minute = (tv->tv_secs % (24 * 60 * 60)) / 60; + ds->ds_Tick = (tv->tv_secs % 60) * TICKS_PER_SECOND + (TICKS_PER_SECOND * tv->tv_micro) / 1000000; + + fix_datestamp(ds); + + return(ds); +} + +/****************************************************************************/ + +static void +add_dates(struct DateStamp * to,const struct DateStamp * from) +{ + assert( to != NULL && from != NULL ); + + to->ds_Tick += from->ds_Tick; + to->ds_Minute += from->ds_Minute; + to->ds_Days += from->ds_Days; + + fix_datestamp(to); +} + +/****************************************************************************/ + +static void +map_descriptor_sets( + const fd_set * input_fds, + int num_input_fds, + + fd_set * socket_fds, + int num_socket_fds, + int * total_socket_fd_ptr, + + fd_set * file_fds, + int num_file_fds, + int * total_file_fd_ptr) +{ + ENTER(); + + SHOWPOINTER(input_fds); + SHOWVALUE(num_input_fds); + + SHOWPOINTER(socket_fds); + SHOWVALUE(num_socket_fds); + + SHOWPOINTER(file_fds); + SHOWVALUE(num_file_fds); + + /* This routine maps file descriptor sets + * from one format to another. We map + * socket descriptors and regular file + * descriptor sets. + */ + if(input_fds != NULL && num_input_fds > 0) + { + int total_socket_fd; + int total_file_fd; + struct fd * fd; + int file_fd; + + total_socket_fd = (*total_socket_fd_ptr); + total_file_fd = (*total_file_fd_ptr); + + SHOWVALUE(total_socket_fd); + SHOWVALUE(total_file_fd); + + for(file_fd = 0 ; file_fd < num_input_fds ; file_fd++) + { + if(NOT FD_ISSET(file_fd,input_fds)) + continue; + + D(("descriptor %ld is set",file_fd)); + + fd = get_file_descriptor(file_fd); + if(fd == NULL) + { + SHOWMSG("but no file is attached to it"); + continue; + } + + /* Is this a socket descriptor? */ + if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_SOCKET)) + { + int socket_fd = (int)fd->fd_DefaultFile; + + D(("corresponds to socket #%ld",socket_fd)); + + if(socket_fds != NULL && socket_fd < num_socket_fds) + { + SHOWMSG("setting it"); + + FD_SET(socket_fd,socket_fds); + + if(total_socket_fd < socket_fd+1) + total_socket_fd = socket_fd+1; + } + else + { + SHOWMSG("can't set it, though"); + } + } + else + { + LONG is_interactive; + + /* We only watch files bound to + * console streams. + */ + PROFILE_OFF(); + is_interactive = IsInteractive(fd->fd_DefaultFile); + PROFILE_ON(); + + if(NOT is_interactive) + { + SHOWMSG("this is a file"); + continue; + } + + SHOWMSG("this is an interactive stream"); + + if(file_fds != NULL && file_fd < num_file_fds) + { + SHOWMSG("setting it"); + + FD_SET(file_fd,file_fds); + + if(total_file_fd < file_fd+1) + total_file_fd = file_fd+1; + } + else + { + SHOWMSG("can't set it, though"); + } + } + } + + (*total_socket_fd_ptr) = total_socket_fd; + (*total_file_fd_ptr) = total_file_fd; + + SHOWVALUE(total_socket_fd); + SHOWVALUE(total_file_fd); + } + + LEAVE(); +} + +/****************************************************************************/ + +static void +remap_descriptor_sets( + const fd_set * socket_fds, + int num_socket_fds, + + const fd_set * file_fds, + int num_file_fds, + + fd_set * output_fds, + int num_output_fds) +{ + ENTER(); + + SHOWPOINTER(socket_fds); + SHOWVALUE(num_socket_fds); + + SHOWPOINTER(file_fds); + SHOWVALUE(num_file_fds); + + SHOWPOINTER(output_fds); + SHOWVALUE(num_output_fds); + + /* This routine reverses the mapping established + * above. We map the file and socket descriptor + * sets back into the original set. + */ + if(output_fds != NULL && num_output_fds > 0) + { + zero_fd_set(output_fds,num_output_fds); + + if(socket_fds != NULL && num_socket_fds > 0) + { + struct fd * fd; + int output_fd; + int socket_fd; + + SHOWMSG("taking care of the sockets"); + + for(socket_fd = 0 ; socket_fd < num_socket_fds ; socket_fd++) + { + if(NOT FD_ISSET(socket_fd,socket_fds)) + continue; + + for(output_fd = 0 ; output_fd < num_output_fds ; output_fd++) + { + fd = get_file_descriptor(output_fd); + if(fd != NULL && FLAG_IS_SET(fd->fd_Flags,FDF_IS_SOCKET) && (int)fd->fd_DefaultFile == socket_fd) + { + assert( output_fd < num_output_fds ); + assert( FLAG_IS_SET(__fd[output_fd]->fd_Flags,FDF_IS_SOCKET) ); + + D(("setting file %ld for socket #%ld",output_fd,socket_fd)); + + FD_SET(output_fd,output_fds); + } + } + } + } + + if(file_fds != NULL && num_file_fds > 0) + { + int file_fd; + + SHOWMSG("taking care of the files"); + + for(file_fd = 0 ; file_fd < num_file_fds ; file_fd++) + { + if(FD_ISSET(file_fd,file_fds)) + { + int output_fd = file_fd; + + assert( output_fd < num_output_fds ); + assert( FLAG_IS_CLEAR(__fd[output_fd]->fd_Flags,FDF_IS_SOCKET) ); + + D(("setting file %ld",file_fd)); + + FD_SET(output_fd,output_fds); + } + } + } + } + else + { + SHOWMSG("no output necessary"); + } + + LEAVE(); +} + +/****************************************************************************/ + +static void +get_num_descriptors_used(int num_fds,int * num_socket_used_ptr,int * num_file_used_ptr) +{ + int num_socket_used = 0; + int num_file_used = 0; + int which_file_fd; + struct fd * fd; + + assert( num_socket_used_ptr != NULL ); + assert( num_file_used_ptr != NULL ); + + SHOWMSG("figuring out which file descriptors are in use"); + + for(which_file_fd = 0 ; which_file_fd < num_fds ; which_file_fd++) + { + fd = get_file_descriptor(which_file_fd); + if(fd != NULL) + { + if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_SOCKET)) + { + int which_socket_fd = (int)fd->fd_DefaultFile; + + if(num_socket_used < which_socket_fd+1) + num_socket_used = which_socket_fd+1; + } + else + { + if(num_file_used < which_file_fd+1) + num_file_used = which_file_fd+1; + } + } + } + + (*num_socket_used_ptr) = num_socket_used; + (*num_file_used_ptr) = num_file_used; +} + +/****************************************************************************/ + +int +select(int num_fds,fd_set *read_fds,fd_set *write_fds,fd_set *except_fds,struct timeval *timeout) +{ + fd_set * backup_socket_read_fds = NULL; + fd_set * backup_socket_write_fds = NULL; + fd_set * backup_socket_except_fds = NULL; + + fd_set * backup_file_read_fds = NULL; + fd_set * backup_file_write_fds = NULL; + + fd_set * socket_read_fds = NULL; + fd_set * socket_write_fds = NULL; + fd_set * socket_except_fds = NULL; + int total_socket_fd; + + fd_set * file_read_fds = NULL; + fd_set * file_write_fds = NULL; + int total_file_fd; + + struct fd * fd; + int result = -1; + + int num_socket_used; + int num_file_used; + int i; + + ENTER(); + + SHOWVALUE(num_fds); + SHOWPOINTER(read_fds); + SHOWPOINTER(write_fds); + SHOWPOINTER(except_fds); + SHOWPOINTER(timeout); + + if(timeout != NULL) + { + SHOWVALUE(timeout->tv_secs); + SHOWVALUE(timeout->tv_micro); + } + + assert(__SocketBase != NULL); + + if(__check_abort_enabled) + __check_abort(); + + /* Figure out the number of file and socket descriptors in use. */ + get_num_descriptors_used(num_fds,&num_socket_used,&num_file_used); + + SHOWVALUE(num_socket_used); + SHOWVALUE(num_file_used); + + /* Dynamically allocate the tables to keep track of which descriptor + * is ready for I/O. + */ + if(read_fds != NULL) + { + if(num_socket_used > 0) + { + SHOWMSG("allocating read socket fd_set"); + + socket_read_fds = allocate_fd_set(num_socket_used,NULL); + if(socket_read_fds == NULL) + goto out; + } + + if(num_file_used > 0) + { + SHOWMSG("allocating read file fd_set"); + + file_read_fds = allocate_fd_set(num_file_used,NULL); + if(file_read_fds == NULL) + goto out; + } + } + + if(write_fds != NULL) + { + if(num_socket_used > 0) + { + SHOWMSG("allocating write socket fd_set"); + + socket_write_fds = allocate_fd_set(num_socket_used,NULL); + if(socket_write_fds == NULL) + goto out; + } + + if(num_file_used > 0) + { + SHOWMSG("allocating write file fd_set"); + + file_write_fds = allocate_fd_set(num_file_used,NULL); + if(file_write_fds == NULL) + goto out; + } + } + + if(except_fds != NULL) + { + if(num_socket_used > 0) + { + SHOWMSG("allocating except socket fd_set"); + + socket_except_fds = allocate_fd_set(num_socket_used,NULL); + if(socket_except_fds == NULL) + goto out; + } + } + + total_socket_fd = 0; + total_file_fd = 0; + + SHOWMSG("mapping the fd_sets"); + + /* Translate from the tables the caller provided to us + * to the local copies, which take the files and sockets + * into account. + */ + map_descriptor_sets(read_fds, num_fds, socket_read_fds, num_socket_used, &total_socket_fd, file_read_fds, num_file_used, &total_file_fd); + map_descriptor_sets(write_fds, num_fds, socket_write_fds, num_socket_used, &total_socket_fd, file_write_fds, num_file_used, &total_file_fd); + map_descriptor_sets(except_fds, num_fds, socket_except_fds, num_socket_used, &total_socket_fd, NULL, 0, &total_file_fd); + + /* Wait for socket input? */ + if(total_socket_fd > 0) + { + SHOWMSG("we have to deal with sockets"); + + /* Wait for file input, too? */ + if((total_file_fd > 0) && (timeout == NULL || timeout->tv_secs > 0 || timeout->tv_micro > 0)) + { + struct DateStamp stop_when; + struct timeval zero; + ULONG break_mask; + BOOL got_input; + BOOL got_output; + + SHOWMSG("we also have to deal with files"); + + /* We may poll the sockets and files several times in a row. + * The results stored in the tables can tell only a single + * story, though. This is why we need to keep a backup copy + * of each table around, to be used for each iteration of + * the loop in which the sockets and files are checked. + */ + if(read_fds != NULL) + { + if(num_socket_used > 0) + { + SHOWMSG("allocating backup read socket fd_set"); + + backup_socket_read_fds = allocate_fd_set(num_socket_used,socket_read_fds); + if(backup_socket_read_fds == NULL) + goto out; + } + + if(num_file_used > 0) + { + SHOWMSG("allocating backup read file fd_set"); + + backup_file_read_fds = allocate_fd_set(num_file_used,file_read_fds); + if(backup_file_read_fds == NULL) + goto out; + } + } + + if(write_fds != NULL) + { + if(num_socket_used > 0) + { + SHOWMSG("allocating backup write socket fd_set"); + + backup_socket_write_fds = allocate_fd_set(num_socket_used,socket_write_fds); + if(backup_socket_write_fds == NULL) + goto out; + } + + if(num_file_used > 0) + { + SHOWMSG("allocating backup write file fd_set"); + + backup_file_write_fds = allocate_fd_set(num_file_used,file_write_fds); + if(backup_file_write_fds == NULL) + goto out; + } + } + + if(except_fds != NULL) + { + if(num_socket_used > 0) + { + SHOWMSG("allocating backup except socket fd_set"); + + backup_socket_except_fds = allocate_fd_set(num_socket_used,socket_except_fds); + if(backup_socket_except_fds == NULL) + goto out; + } + } + + /* We are going to poll all streams; for the timeout + * feature to work, we absolutely must know when to + * stop polling. + * + * Why aren't we using asynchronous DOS packets? + * The answer is that once a packet is sent, you + * cannot easily abort it. Polling is safer in + * that respect. Yes, I know that ACTION_STACK + * can be used to fake input to a console stream, + * but I'd rather not rely upon it. + */ + if(timeout != NULL) + { + struct DateStamp datestamp_timeout; + + PROFILE_OFF(); + DateStamp(&stop_when); + PROFILE_ON(); + + add_dates(&stop_when,timeval_to_datestamp(&datestamp_timeout,timeout)); + } + else + { + /* No timeout, poll until we are interrupted + * or get input from any of the files. It's + * not really necessary to initialize this + * timeval, but it keeps the compiler happy. + */ + memset(&stop_when,0,sizeof(stop_when)); + } + + while(TRUE) + { + /* Check for break signal. */ + if(__check_abort_enabled) + __check_abort(); + + /* Delay for a tick to avoid busy-waiting. */ + PROFILE_OFF(); + Delay(1); + PROFILE_ON(); + + /* This tells WaitSelect() to poll the sockets for input. */ + zero.tv_secs = 0; + zero.tv_micro = 0; + + /* Signals to stop on; we want to stop when a break signal arrives. */ + if(__check_abort_enabled) + break_mask = SIGBREAKF_CTRL_C; + else + break_mask = 0; + + /* Check for socket input. */ + PROFILE_OFF(); + result = __WaitSelect(total_socket_fd,socket_read_fds,socket_write_fds,socket_except_fds,&zero,&break_mask); + PROFILE_ON(); + + /* Stop if a break signal arrives. */ + if((result < 0 && errno == EINTR) || FLAG_IS_SET(break_mask,SIGBREAKF_CTRL_C)) + { + SetSignal(SIGBREAKF_CTRL_C,SIGBREAKF_CTRL_C); + __check_abort(); + } + + /* Stop if the return value from WaitSelect() is negative (timeout, abort or serious error). */ + if(result < 0) + break; + + /* Check all files for input. We also poll + * them for input, but each with a little + * delay of about 1 microsecond. We stop + * as soon as we find one file that has + * input in it. + */ + for(i = 0 ; i < total_file_fd ; i++) + { + got_input = got_output = FALSE; + + fd = get_file_descriptor(i); + if(fd != NULL) + { + if(file_read_fds != NULL && FD_ISSET(i,file_read_fds)) + { + if(FLAG_IS_SET(fd->fd_Flags,FDF_READ)) + { + assert( FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_SOCKET) ); + + /* Does this one have input? */ + PROFILE_OFF(); + + if(WaitForChar(fd->fd_DefaultFile,1)) + got_input = TRUE; + + PROFILE_ON(); + } + } + + if(file_write_fds != NULL && FD_ISSET(i,file_write_fds)) + { + /* If this is a writable stream, assume that we can + * write to it. ZZZ AmigaDOS needs a method to check + * if the write will block. + */ + if(FLAG_IS_SET(fd->fd_Flags,FDF_WRITE)) + { + assert( FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_SOCKET) ); + + got_output = TRUE; + } + } + } + + if(got_input || got_output) + { + /* Mark one more descriptor as + * having input/output. + */ + result++; + } + + if(file_read_fds != NULL && NOT got_input) + FD_CLR(i,file_read_fds); + + if(file_write_fds != NULL && NOT got_output) + FD_CLR(i,file_write_fds); + } + + /* Did we get any input? If so, stop polling. */ + if(result > 0) + break; + + /* If a timeout was set, check if we are already + * beyond the point of time when we should have + * stopped polling. + */ + if(timeout != NULL) + { + struct DateStamp now; + + PROFILE_OFF(); + DateStamp(&now); + PROFILE_ON(); + + if(CompareDates(&now,&stop_when) <= 0) + break; + } + + /* No I/O ready yet. Restore the sets and retry... */ + copy_fd_set(socket_read_fds, backup_socket_read_fds, num_socket_used); + copy_fd_set(socket_write_fds, backup_socket_write_fds, num_socket_used); + copy_fd_set(socket_except_fds, backup_socket_except_fds, num_socket_used); + + copy_fd_set(file_read_fds, backup_file_read_fds, num_file_used); + copy_fd_set(file_write_fds, backup_file_write_fds, num_file_used); + } + } + else + { + ULONG break_mask; + + if(__check_abort_enabled) + break_mask = SIGBREAKF_CTRL_C; + else + break_mask = 0; + + PROFILE_OFF(); + result = __WaitSelect(total_socket_fd,socket_read_fds,socket_write_fds,socket_except_fds,timeout,&break_mask); + PROFILE_ON(); + + if((result < 0 && errno == EINTR) || FLAG_IS_SET(break_mask,SIGBREAKF_CTRL_C)) + { + SetSignal(SIGBREAKF_CTRL_C,SIGBREAKF_CTRL_C); + __check_abort(); + } + } + } + else + { + /* Wait for file input? */ + if((total_file_fd > 0) && (timeout == NULL || timeout->tv_secs > 0 || timeout->tv_micro > 0)) + { + struct DateStamp stop_when; + BOOL got_input; + BOOL got_output; + + SHOWMSG("we have to deal with files"); + + if(num_file_used > 0) + { + if(read_fds != NULL) + { + SHOWMSG("allocating backup file read fd_set"); + + backup_file_read_fds = allocate_fd_set(num_file_used,file_read_fds); + if(backup_file_read_fds == NULL) + goto out; + } + + if(write_fds != NULL) + { + SHOWMSG("allocating backup file write fd_set"); + + backup_file_write_fds = allocate_fd_set(num_file_used,file_write_fds); + if(backup_file_write_fds == NULL) + goto out; + } + } + + if(timeout != NULL) + { + struct DateStamp datestamp_timeout; + + PROFILE_OFF(); + DateStamp(&stop_when); + PROFILE_ON(); + + add_dates(&stop_when,timeval_to_datestamp(&datestamp_timeout,timeout)); + } + else + { + memset(&stop_when,0,sizeof(stop_when)); + } + + while(TRUE) + { + if(__check_abort_enabled) + __check_abort(); + + PROFILE_OFF(); + Delay(1); + PROFILE_ON(); + + result = 0; + + for(i = 0 ; i < total_file_fd ; i++) + { + got_input = got_output = FALSE; + + fd = get_file_descriptor(i); + if(fd != NULL) + { + if(file_read_fds != NULL && FD_ISSET(i,file_read_fds)) + { + if(FLAG_IS_SET(fd->fd_Flags,FDF_READ)) + { + assert( FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_SOCKET) ); + + PROFILE_OFF(); + + if(WaitForChar(fd->fd_DefaultFile,1)) + got_input = TRUE; + + PROFILE_ON(); + } + } + + if(file_write_fds != NULL && FD_ISSET(i,file_write_fds)) + { + if(FLAG_IS_SET(fd->fd_Flags,FDF_WRITE)) + { + assert( FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_SOCKET) ); + + got_output = TRUE; + } + } + } + + if(got_input || got_output) + result++; + + if(file_read_fds != NULL && NOT got_input) + FD_CLR(i,file_read_fds); + + if(file_write_fds != NULL && NOT got_output) + FD_CLR(i,file_write_fds); + } + + if(result > 0) + break; + + if(timeout != NULL) + { + struct DateStamp now; + + PROFILE_OFF(); + DateStamp(&now); + PROFILE_ON(); + + if(CompareDates(&now,&stop_when) <= 0) + break; + } + + copy_fd_set(file_read_fds, backup_file_read_fds, num_file_used); + copy_fd_set(file_write_fds, backup_file_write_fds, num_file_used); + } + } + else + { + SHOWMSG("no files to worry about"); + } + } + + /* The descriptor sets remain unchanged in + * case of error. + */ + if(result >= 0) + { + SHOWMSG("remapping fd_sets"); + + remap_descriptor_sets(socket_read_fds, total_socket_fd, file_read_fds, total_file_fd, read_fds, num_fds); + remap_descriptor_sets(socket_write_fds, total_socket_fd, file_write_fds, total_file_fd, write_fds, num_fds); + remap_descriptor_sets(socket_except_fds, total_socket_fd, NULL, 0, except_fds, num_fds); + } + + if(__check_abort_enabled) + __check_abort(); + + out: + + free_fd_set(socket_read_fds); + free_fd_set(socket_write_fds); + free_fd_set(socket_except_fds); + + free_fd_set(file_read_fds); + free_fd_set(file_write_fds); + + free_fd_set(backup_socket_read_fds); + free_fd_set(backup_socket_write_fds); + free_fd_set(backup_socket_except_fds); + + free_fd_set(backup_file_read_fds); + free_fd_set(backup_file_write_fds); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_send.c b/library/socket_send.c new file mode 100644 index 0000000..4e23068 --- /dev/null +++ b/library/socket_send.c @@ -0,0 +1,103 @@ +/* + * $Id: socket_send.c,v 1.1.1.1 2004-07-26 16:31:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +send(int sockfd,void *buff,size_t nbytes,int flags) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWPOINTER(buff); + SHOWVALUE(nbytes); + SHOWVALUE(flags); + + assert( (int)nbytes >= 0 ); + assert( buff != NULL ); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(buff == NULL) + { + SHOWMSG("invalid buffer parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __send((LONG)fd->fd_DefaultFile,buff,(LONG)nbytes,flags); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_sendmsg.c b/library/socket_sendmsg.c new file mode 100644 index 0000000..c8b9ea4 --- /dev/null +++ b/library/socket_sendmsg.c @@ -0,0 +1,101 @@ +/* + * $Id: socket_sendmsg.c,v 1.1.1.1 2004-07-26 16:31:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +sendmsg(int sockfd,struct msghdr *msg,int flags) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWPOINTER(msg); + SHOWVALUE(flags); + + assert( msg != NULL ); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(msg == NULL) + { + SHOWMSG("invalid msg parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __sendmsg((LONG)fd->fd_DefaultFile,msg,flags); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_sendto.c b/library/socket_sendto.c new file mode 100644 index 0000000..312efa5 --- /dev/null +++ b/library/socket_sendto.c @@ -0,0 +1,104 @@ +/* + * $Id: socket_sendto.c,v 1.1.1.1 2004-07-26 16:31:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +sendto(int sockfd,void *buff,int len,int flags,struct sockaddr *to,int tolen) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWPOINTER(buff); + SHOWVALUE(len); + SHOWVALUE(flags); + SHOWPOINTER(to); + SHOWVALUE(tolen); + + assert( buff != NULL && to != NULL ); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(buff == NULL || to == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __sendto((LONG)fd->fd_DefaultFile,buff,len,flags,to,tolen); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_setsockopt.c b/library/socket_setsockopt.c new file mode 100644 index 0000000..a2ca38f --- /dev/null +++ b/library/socket_setsockopt.c @@ -0,0 +1,103 @@ +/* + * $Id: socket_setsockopt.c,v 1.1.1.1 2004-07-26 16:31:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +setsockopt(int sockfd,int level,int optname,void *optval,int optlen) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWVALUE(level); + SHOWVALUE(optname); + SHOWPOINTER(optval); + SHOWVALUE(optlen); + + assert( optval != NULL ); + assert(__SocketBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(optval == NULL) + { + SHOWMSG("invalid optval parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __setsockopt((LONG)fd->fd_DefaultFile,level,optname,optval,optlen); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_shutdown.c b/library/socket_shutdown.c new file mode 100644 index 0000000..5b525c4 --- /dev/null +++ b/library/socket_shutdown.c @@ -0,0 +1,81 @@ +/* + * $Id: socket_shutdown.c,v 1.1.1.1 2004-07-26 16:31:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +shutdown(int sockfd, int how) +{ + struct fd * fd; + int result = -1; + + ENTER(); + + SHOWVALUE(sockfd); + SHOWVALUE(how); + + assert(__SocketBase != NULL); + + assert( sockfd >= 0 && sockfd < __num_fd ); + assert( __fd[sockfd] != NULL ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IN_USE) ); + assert( FLAG_IS_SET(__fd[sockfd]->fd_Flags,FDF_IS_SOCKET) ); + + fd = __get_socket_descriptor(sockfd); + if(fd == NULL) + goto out; + + PROFILE_OFF(); + result = __shutdown((LONG)fd->fd_DefaultFile,how); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/socket_socket.c b/library/socket_socket.c new file mode 100644 index 0000000..cba3da0 --- /dev/null +++ b/library/socket_socket.c @@ -0,0 +1,98 @@ +/* + * $Id: socket_socket.c,v 1.1.1.1 2004-07-26 16:31:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(SOCKET_SUPPORT) + +/****************************************************************************/ + +#ifndef _SOCKET_HEADERS_H +#include "socket_headers.h" +#endif /* _SOCKET_HEADERS_H */ + +/****************************************************************************/ + +int +socket(int domain,int type,int protocol) +{ + int result = -1; + struct fd * fd; + int fd_slot_number; + LONG socket_fd; + + ENTER(); + + SHOWVALUE(domain); + SHOWVALUE(type); + SHOWVALUE(protocol); + + fd_slot_number = __find_vacant_fd_entry(); + if(fd_slot_number < 0) + { + if(__grow_fd_table() < 0) + { + SHOWMSG("couldn't find a vacant fd slot and no memory to create one"); + goto out; + } + + fd_slot_number = __find_vacant_fd_entry(); + assert( fd_slot_number >= 0 ); + } + + PROFILE_OFF(); + socket_fd = __socket(domain,type,protocol); + PROFILE_ON(); + + if(socket_fd < 0) + { + SHOWMSG("could not create socket"); + goto out; + } + + fd = __fd[fd_slot_number]; + + __initialize_fd(fd,(HOOKFUNC)__socket_hook_entry,(BPTR)socket_fd,FDF_IN_USE | FDF_IS_SOCKET | FDF_READ | FDF_WRITE); + + result = fd_slot_number; + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* SOCKET_SUPPORT */ diff --git a/library/stack.lib_rev.c b/library/stack.lib_rev.c new file mode 100644 index 0000000..c23878a --- /dev/null +++ b/library/stack.lib_rev.c @@ -0,0 +1,38 @@ +/* + * $Id: stack.lib_rev.c,v 1.1.1.1 2004-07-26 16:31:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "stack.lib_rev.h" + +/****************************************************************************/ + +char __stack_lib_version[] = VERSTAG; diff --git a/library/stack.lib_rev.h b/library/stack.lib_rev.h new file mode 100644 index 0000000..39e6b4c --- /dev/null +++ b/library/stack.lib_rev.h @@ -0,0 +1,6 @@ +#define VERSION 1 +#define REVISION 165 +#define DATE "26.7.2004" +#define VERS "stack.lib 1.165" +#define VSTRING "stack.lib 1.165 (26.7.2004)\r\n" +#define VERSTAG "\0$VER: stack.lib 1.165 (26.7.2004)" diff --git a/library/stack.lib_rev.rev b/library/stack.lib_rev.rev new file mode 100644 index 0000000..9e42f3e --- /dev/null +++ b/library/stack.lib_rev.rev @@ -0,0 +1 @@ +165 diff --git a/library/startup.c b/library/startup.c new file mode 100644 index 0000000..ef5b819 --- /dev/null +++ b/library/startup.c @@ -0,0 +1,48 @@ +/* + * $Id: startup.c,v 1.1.1.1 2004-07-26 16:31:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/****************************************************************************/ + +extern int _main(void); + +/****************************************************************************/ + +int +startup(void) +{ + int result; + + result = _main(); + + return(result); +} diff --git a/library/stat_chmod.c b/library/stat_chmod.c new file mode 100644 index 0000000..3eab8fd --- /dev/null +++ b/library/stat_chmod.c @@ -0,0 +1,155 @@ +/* + * $Id: stat_chmod.c,v 1.1.1.1 2004-07-26 16:31:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STAT_HEADERS_H +#include "stat_headers.h" +#endif /* _STAT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +chmod(const char * path_name, mode_t mode) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info path_name_nti; + #endif /* UNIX_PATH_SEMANTICS */ + ULONG protection; + LONG status; + int result = -1; + + ENTER(); + + SHOWSTRING(path_name); + SHOWVALUE(mode); + + assert( path_name != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL) + { + SHOWMSG("invalid path parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + + if(path_name_nti.is_root) + { + errno = EACCES; + goto out; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + protection = 0; + + if(FLAG_IS_SET(mode,S_IRUSR)) + SET_FLAG(protection,FIBF_READ); + + if(FLAG_IS_SET(mode,S_IWUSR)) + { + SET_FLAG(protection,FIBF_WRITE); + SET_FLAG(protection,FIBF_DELETE); + } + + if(FLAG_IS_SET(mode,S_IXUSR)) + SET_FLAG(protection,FIBF_EXECUTE); + + if(FLAG_IS_SET(mode,S_IRGRP)) + SET_FLAG(protection,FIBF_GRP_READ); + + if(FLAG_IS_SET(mode,S_IWGRP)) + { + SET_FLAG(protection,FIBF_GRP_WRITE); + SET_FLAG(protection,FIBF_GRP_DELETE); + } + + if(FLAG_IS_SET(mode,S_IXGRP)) + SET_FLAG(protection,FIBF_GRP_EXECUTE); + + if(FLAG_IS_SET(mode,S_IROTH)) + SET_FLAG(protection,FIBF_OTR_READ); + + if(FLAG_IS_SET(mode,S_IWOTH)) + { + SET_FLAG(protection,FIBF_OTR_WRITE); + SET_FLAG(protection,FIBF_OTR_DELETE); + } + + if(FLAG_IS_SET(mode,S_IXOTH)) + SET_FLAG(protection,FIBF_OTR_EXECUTE); + + SHOWSTRING(path_name); + SHOWVALUE(protection); + + PROFILE_OFF(); + status = SetProtection((STRPTR)path_name,(LONG)(protection ^ (FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE))); + PROFILE_ON(); + + if(status == DOSFALSE) + { + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stat_convertfileinfo.c b/library/stat_convertfileinfo.c new file mode 100644 index 0000000..482b7c5 --- /dev/null +++ b/library/stat_convertfileinfo.c @@ -0,0 +1,155 @@ +/* + * $Id: stat_convertfileinfo.c,v 1.1.1.1 2004-07-26 16:31:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STAT_HEADERS_H +#include "stat_headers.h" +#endif /* _STAT_HEADERS_H */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +void +__convert_file_info_to_stat( + const struct MsgPort * file_system, + const struct FileInfoBlock * fib, + struct stat * st) +{ + time_t mtime; + mode_t mode; + ULONG flags; + + ENTER(); + + assert( fib != NULL && st != NULL ); + + SHOWVALUE(fib->fib_DiskKey); + SHOWVALUE(fib->fib_DirEntryType); + SHOWSTRING(fib->fib_FileName); + SHOWVALUE(fib->fib_Protection); + SHOWVALUE(fib->fib_EntryType); + SHOWVALUE(fib->fib_Size); + SHOWVALUE(fib->fib_NumBlocks); + SHOWVALUE(fib->fib_Date.ds_Days); + SHOWVALUE(fib->fib_Date.ds_Minute); + SHOWVALUE(fib->fib_Date.ds_Tick); + SHOWSTRING(fib->fib_Comment); + SHOWVALUE(fib->fib_OwnerUID); + SHOWVALUE(fib->fib_OwnerGID); + + memset(st,0,sizeof(*st)); + + flags = fib->fib_Protection ^ (FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE); + + if(fib->fib_DirEntryType == ST_PIPEFILE) + mode = S_IFIFO; + else if (fib->fib_DirEntryType == ST_SOCKET) + mode = S_IFSOCK; + else if (fib->fib_DirEntryType < 0) + mode = S_IFREG; + else + mode = S_IFDIR; + + if(FLAG_IS_SET(flags,FIBF_READ)) + SET_FLAG(mode,S_IRUSR); + + if(FLAG_IS_SET(flags,FIBF_WRITE) && FLAG_IS_SET(flags,FIBF_DELETE)) + SET_FLAG(mode,S_IWUSR); + + if(FLAG_IS_SET(flags,FIBF_EXECUTE)) + SET_FLAG(mode,S_IXUSR); + + if(FLAG_IS_SET(flags,FIBF_GRP_READ)) + SET_FLAG(mode,S_IRGRP); + + if(FLAG_IS_SET(flags,FIBF_GRP_WRITE) && FLAG_IS_SET(flags,FIBF_GRP_DELETE)) + SET_FLAG(mode,S_IWGRP); + + if(FLAG_IS_SET(flags,FIBF_GRP_EXECUTE)) + SET_FLAG(mode,S_IXGRP); + + if(FLAG_IS_SET(flags,FIBF_OTR_READ)) + SET_FLAG(mode,S_IROTH); + + if(FLAG_IS_SET(flags,FIBF_OTR_WRITE) && FLAG_IS_SET(flags,FIBF_OTR_DELETE)) + SET_FLAG(mode,S_IWOTH); + + if(FLAG_IS_SET(flags,FIBF_OTR_EXECUTE)) + SET_FLAG(mode,S_IXOTH); + + mtime = UNIX_TIME_OFFSET + fib->fib_Date.ds_Days * 24*60*60 + fib->fib_Date.ds_Minute * 60 + (fib->fib_Date.ds_Tick / TICKS_PER_SECOND); + if(__default_locale != NULL) + mtime += 60 * __default_locale->loc_GMTOffset; + + if(fib->fib_DirEntryType < 0) + { + st->st_nlink = 1; + st->st_size = fib->fib_Size; + } + else + { + st->st_nlink = 2; + } + + st->st_ino = fib->fib_DiskKey; + st->st_dev = (dev_t)file_system; + st->st_mode = mode; + st->st_mtime = mtime; + st->st_atime = st->st_mtime; + st->st_ctime = st->st_mtime; + st->st_uid = fib->fib_OwnerUID; + st->st_gid = fib->fib_OwnerGID; + st->st_blksize = 512; + st->st_blocks = (st->st_size + st->st_blksize-1) / st->st_blksize; + + SHOWVALUE(st->st_nlink); + SHOWVALUE(st->st_size); + SHOWVALUE(st->st_ino); + SHOWVALUE(st->st_dev); + SHOWVALUE(st->st_mode); + SHOWVALUE(st->st_mtime); + SHOWVALUE(st->st_atime); + SHOWVALUE(st->st_ctime); + SHOWVALUE(st->st_uid); + SHOWVALUE(st->st_gid); + SHOWVALUE(st->st_blksize); + SHOWVALUE(st->st_blocks); + + LEAVE(); +} diff --git a/library/stat_data.c b/library/stat_data.c new file mode 100644 index 0000000..9052f88 --- /dev/null +++ b/library/stat_data.c @@ -0,0 +1,40 @@ +/* + * $Id: stat_data.c,v 1.1.1.1 2004-07-26 16:31:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STAT_HEADERS_H +#include "stat_headers.h" +#endif /* _STAT_HEADERS_H */ + +/****************************************************************************/ + +mode_t __current_umask = S_IWGRP | S_IWOTH; diff --git a/library/stat_fchmod.c b/library/stat_fchmod.c new file mode 100644 index 0000000..24efaba --- /dev/null +++ b/library/stat_fchmod.c @@ -0,0 +1,128 @@ +/* + * $Id: stat_fchmod.c,v 1.1.1.1 2004-07-26 16:31:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STAT_HEADERS_H +#include "stat_headers.h" +#endif /* _STAT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +fchmod(int file_descriptor, mode_t mode) +{ + DECLARE_UTILITYBASE(); + struct file_hook_message message; + ULONG protection; + int result = -1; + struct fd * fd; + + ENTER(); + + SHOWVALUE(file_descriptor); + SHOWVALUE(mode); + + assert( UtilityBase != NULL ); + + assert( file_descriptor >= 0 && file_descriptor < __num_fd ); + assert( __fd[file_descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + errno = EBADF; + goto out; + } + + protection = 0; + + if(FLAG_IS_SET(mode,S_IRUSR)) + SET_FLAG(protection,FIBF_READ); + + if(FLAG_IS_SET(mode,S_IWUSR)) + { + SET_FLAG(protection,FIBF_WRITE); + SET_FLAG(protection,FIBF_DELETE); + } + + if(FLAG_IS_SET(mode,S_IXUSR)) + SET_FLAG(protection,FIBF_EXECUTE); + + if(FLAG_IS_SET(mode,S_IRGRP)) + SET_FLAG(protection,FIBF_GRP_READ); + + if(FLAG_IS_SET(mode,S_IWGRP)) + { + SET_FLAG(protection,FIBF_GRP_WRITE); + SET_FLAG(protection,FIBF_GRP_DELETE); + } + + if(FLAG_IS_SET(mode,S_IXGRP)) + SET_FLAG(protection,FIBF_GRP_EXECUTE); + + if(FLAG_IS_SET(mode,S_IROTH)) + SET_FLAG(protection,FIBF_OTR_READ); + + if(FLAG_IS_SET(mode,S_IWOTH)) + { + SET_FLAG(protection,FIBF_OTR_WRITE); + SET_FLAG(protection,FIBF_OTR_DELETE); + } + + if(FLAG_IS_SET(mode,S_IXOTH)) + SET_FLAG(protection,FIBF_OTR_EXECUTE); + + SHOWMSG("calling the hook"); + + message.action = file_hook_action_change_attributes; + message.attributes = protection ^ (FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE); + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + + result = message.result; + errno = message.error; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stat_fstat.c b/library/stat_fstat.c new file mode 100644 index 0000000..f0e6207 --- /dev/null +++ b/library/stat_fstat.c @@ -0,0 +1,116 @@ +/* + * $Id: stat_fstat.c,v 1.1.1.1 2004-07-26 16:31:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STAT_HEADERS_H +#include "stat_headers.h" +#endif /* _STAT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +fstat(int file_descriptor, struct stat * buffer) +{ + DECLARE_UTILITYBASE(); + struct file_hook_message message; + D_S(struct FileInfoBlock,fib); + int result = -1; + struct fd * fd; + + ENTER(); + + SHOWVALUE(file_descriptor); + SHOWPOINTER(buffer); + + assert( buffer != NULL ); + assert( UtilityBase != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(buffer == NULL) + { + SHOWMSG("invalid buffer parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( file_descriptor >= 0 && file_descriptor < __num_fd ); + assert( __fd[file_descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + errno = EBADF; + goto out; + } + + SHOWMSG("calling the hook"); + + message.action = file_hook_action_examine; + message.file_info = fib; + message.file_system = NULL; + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + + result = message.result; + if(result != 0) + { + errno = message.error; + goto out; + } + + __convert_file_info_to_stat(message.file_system,fib,buffer); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stat_headers.h b/library/stat_headers.h new file mode 100644 index 0000000..09a09be --- /dev/null +++ b/library/stat_headers.h @@ -0,0 +1,53 @@ +/* + * $Id: stat_headers.h,v 1.1.1.1 2004-07-26 16:31:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STAT_HEADERS_H +#define _STAT_HEADERS_H + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +extern mode_t __current_umask; + +/****************************************************************************/ + +extern void __convert_file_info_to_stat(const struct MsgPort * file_system,const struct FileInfoBlock * fib,struct stat * st); + +/****************************************************************************/ + +#endif /* _STAT_HEADERS_H */ diff --git a/library/stat_lstat.c b/library/stat_lstat.c new file mode 100644 index 0000000..49e28d2 --- /dev/null +++ b/library/stat_lstat.c @@ -0,0 +1,83 @@ +/* + * $Id: stat_lstat.c,v 1.1.1.1 2004-07-26 16:31:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STAT_HEADERS_H +#include "stat_headers.h" +#endif /* _STAT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +lstat(const char * path_name, struct stat * buffer) +{ + int result = -1; + + ENTER(); + + SHOWSTRING(path_name); + SHOWPOINTER(buffer); + + assert( path_name != NULL && buffer != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL || buffer == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + result = stat(path_name,buffer); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stat_mkdir.c b/library/stat_mkdir.c new file mode 100644 index 0000000..13fd5a5 --- /dev/null +++ b/library/stat_mkdir.c @@ -0,0 +1,167 @@ +/* + * $Id: stat_mkdir.c,v 1.1.1.1 2004-07-26 16:31:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STAT_HEADERS_H +#include "stat_headers.h" +#endif /* _STAT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +mkdir(const char * path_name, mode_t mode) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info path_name_nti; + #endif /* UNIX_PATH_SEMANTICS */ + ULONG protection; + int result = -1; + BPTR dir_lock; + + ENTER(); + + SHOWSTRING(path_name); + SHOWVALUE(mode); + + assert( path_name != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL) + { + SHOWMSG("invalid path name parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + + if(path_name_nti.is_root) + { + errno = EACCES; + goto out; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + D(("trying to create '%s'",path_name)); + + PROFILE_OFF(); + dir_lock = CreateDir((STRPTR)path_name); + PROFILE_ON(); + + if(dir_lock == ZERO) + { + SHOWMSG("that didn't work"); + + __translate_access_io_error_to_errno(IoErr(),&errno); + goto out; + } + + PROFILE_OFF(); + UnLock(dir_lock); + PROFILE_ON(); + + protection = 0; + + if(FLAG_IS_SET(mode,S_IRUSR)) + SET_FLAG(protection,FIBF_READ); + + if(FLAG_IS_SET(mode,S_IWUSR)) + { + SET_FLAG(protection,FIBF_WRITE); + SET_FLAG(protection,FIBF_DELETE); + } + + if(FLAG_IS_SET(mode,S_IXUSR)) + SET_FLAG(protection,FIBF_EXECUTE); + + if(FLAG_IS_SET(mode,S_IRGRP)) + SET_FLAG(protection,FIBF_GRP_READ); + + if(FLAG_IS_SET(mode,S_IWGRP)) + { + SET_FLAG(protection,FIBF_GRP_WRITE); + SET_FLAG(protection,FIBF_GRP_DELETE); + } + + if(FLAG_IS_SET(mode,S_IXGRP)) + SET_FLAG(protection,FIBF_GRP_EXECUTE); + + if(FLAG_IS_SET(mode,S_IROTH)) + SET_FLAG(protection,FIBF_OTR_READ); + + if(FLAG_IS_SET(mode,S_IWOTH)) + { + SET_FLAG(protection,FIBF_OTR_WRITE); + SET_FLAG(protection,FIBF_OTR_DELETE); + } + + if(FLAG_IS_SET(mode,S_IXOTH)) + SET_FLAG(protection,FIBF_OTR_EXECUTE); + + SHOWSTRING(path_name); + SHOWVALUE(protection); + + PROFILE_OFF(); + SetProtection((STRPTR)path_name,(LONG)(protection ^ (FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE))); + PROFILE_ON(); + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stat_rmdir.c b/library/stat_rmdir.c new file mode 100644 index 0000000..0af0c0c --- /dev/null +++ b/library/stat_rmdir.c @@ -0,0 +1,162 @@ +/* + * $Id: stat_rmdir.c,v 1.1.1.1 2004-07-26 16:31:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STAT_HEADERS_H +#include "stat_headers.h" +#endif /* _STAT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +rmdir(const char * path_name) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info path_name_nti; + #endif /* UNIX_PATH_SEMANTICS */ + D_S(struct FileInfoBlock,fib); + BPTR dir_lock = ZERO; + int result = -1; + LONG status; + + ENTER(); + + SHOWSTRING(path_name); + + assert( path_name != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL) + { + SHOWMSG("invalid path name parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + + if(path_name_nti.is_root) + { + errno = EACCES; + goto out; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + D(("trying to get a lock on '%s'",path_name)); + + PROFILE_OFF(); + dir_lock = Lock((STRPTR)path_name,SHARED_LOCK); + PROFILE_ON(); + + if(dir_lock == ZERO) + { + SHOWMSG("that didn't work"); + + __translate_access_io_error_to_errno(IoErr(),&errno); + goto out; + } + + PROFILE_OFF(); + status = Examine(dir_lock,fib); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("couldn't examine it"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + if(fib->fib_DirEntryType < 0) + { + SHOWMSG("this is not a directory"); + + errno = ENOTDIR; + goto out; + } + + PROFILE_OFF(); + UnLock(dir_lock); + PROFILE_ON(); + + dir_lock = ZERO; + + SHOWMSG("trying to delete it"); + + PROFILE_OFF(); + status = DeleteFile((STRPTR)path_name); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("that didn't work"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + result = 0; + + out: + + PROFILE_OFF(); + UnLock(dir_lock); + PROFILE_ON(); + + RETURN(result); + return(result); +} diff --git a/library/stat_stat.c b/library/stat_stat.c new file mode 100644 index 0000000..0b481d3 --- /dev/null +++ b/library/stat_stat.c @@ -0,0 +1,169 @@ +/* + * $Id: stat_stat.c,v 1.1.1.1 2004-07-26 16:31:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STAT_HEADERS_H +#include "stat_headers.h" +#endif /* _STAT_HEADERS_H */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +stat(const char * path_name, struct stat * st) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info path_name_nti; + #endif /* UNIX_PATH_SEMANTICS */ + D_S(struct FileInfoBlock,fib); + struct FileLock * fl; + int result = -1; + LONG status; + BPTR file_lock = ZERO; + + ENTER(); + + SHOWSTRING(path_name); + SHOWPOINTER(st); + + assert( path_name != NULL && st != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL || st == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + + /* The pseudo root directory is a very special case indeed. + * We make up some pseudo data for it. + */ + if(path_name_nti.is_root) + { + struct DateStamp ds; + time_t mtime; + + SHOWMSG("seting up the root directory info"); + + memset(st,0,sizeof(*st)); + + PROFILE_OFF(); + DateStamp(&ds); + PROFILE_ON(); + + mtime = UNIX_TIME_OFFSET + ds.ds_Days * 24*60*60 + ds.ds_Minute * 60 + (ds.ds_Tick / TICKS_PER_SECOND); + if(__default_locale != NULL) + mtime += 60 * __default_locale->loc_GMTOffset; + + st->st_mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; + st->st_mtime = mtime; + st->st_atime = st->st_mtime; + st->st_ctime = st->st_mtime; + st->st_nlink = 2; + st->st_blksize = 512; + + result = 0; + goto out; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + D(("trying to get a lock on '%s'",path_name)); + + PROFILE_OFF(); + file_lock = Lock((STRPTR)path_name,SHARED_LOCK); + PROFILE_ON(); + + if(file_lock == ZERO) + { + SHOWMSG("that didn't work"); + + __translate_access_io_error_to_errno(IoErr(),&errno); + goto out; + } + + PROFILE_OFF(); + status = Examine(file_lock,fib); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("couldn't examine it"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + fl = BADDR(file_lock); + + __convert_file_info_to_stat(fl->fl_Task,fib,st); + + result = 0; + + out: + + PROFILE_OFF(); + UnLock(file_lock); + PROFILE_ON(); + + RETURN(result); + return(result); +} diff --git a/library/stat_umask.c b/library/stat_umask.c new file mode 100644 index 0000000..ec572d9 --- /dev/null +++ b/library/stat_umask.c @@ -0,0 +1,100 @@ +/* + * $Id: stat_umask.c,v 1.1.1.1 2004-07-26 16:31:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STAT_HEADERS_H +#include "stat_headers.h" +#endif /* _STAT_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +mode_t +umask(mode_t new_mask) +{ + mode_t result; + + ENTER(); + + SHOWVALUE(new_mask); + + assert(__UserGroupBase != NULL); + + PROFILE_OFF(); + result = __getumask(); + PROFILE_ON(); + + __umask(new_mask & (S_IRWXU | S_IRWXG | S_IRWXO)); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +mode_t +umask(mode_t new_mask) +{ + mode_t result; + + ENTER(); + + SHOWVALUE(new_mask); + + result = __current_umask; + + __current_umask = new_mask & (S_IRWXU | S_IRWXG | S_IRWXO); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/stdio_asprintf.c b/library/stdio_asprintf.c new file mode 100644 index 0000000..f87f87d --- /dev/null +++ b/library/stdio_asprintf.c @@ -0,0 +1,84 @@ +/* + * $Id: stdio_asprintf.c,v 1.1.1.1 2004-07-26 16:31:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +asprintf(char **ret, const char *format, ...) +{ + int result = -1; + va_list arg; + + ENTER(); + + SHOWPOINTER(ret); + SHOWSTRING(format); + + assert( ret != NULL && format != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(ret == NULL || format == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + va_start(arg,format); + result = vasprintf(ret,format,arg); + va_end(arg); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_clearerr.c b/library/stdio_clearerr.c new file mode 100644 index 0000000..2f5b315 --- /dev/null +++ b/library/stdio_clearerr.c @@ -0,0 +1,82 @@ +/* + * $Id: stdio_clearerr.c,v 1.1.1.1 2004-07-26 16:31:24 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#undef clearerr + +/****************************************************************************/ + +void +clearerr(FILE *stream) +{ + struct iob * file = (struct iob *)stream; + + ENTER(); + + SHOWPOINTER(stream); + + assert( stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(file) ); + + CLEAR_FLAG(file->iob_Flags,IOBF_ERROR); + CLEAR_FLAG(file->iob_Flags,IOBF_EOF_REACHED); + + out: + + LEAVE(); +} diff --git a/library/stdio_data.c b/library/stdio_data.c new file mode 100644 index 0000000..6e05490 --- /dev/null +++ b/library/stdio_data.c @@ -0,0 +1,48 @@ +/* + * $Id: stdio_data.c,v 1.1.1.1 2004-07-26 16:31:24 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +/* The file handle table. */ +struct iob ** __iob; +int __num_iob; + +/****************************************************************************/ + +/* The file descriptor table. */ +struct fd ** __fd; +int __num_fd; diff --git a/library/stdio_dropiobreadbuffer.c b/library/stdio_dropiobreadbuffer.c new file mode 100644 index 0000000..8589653 --- /dev/null +++ b/library/stdio_dropiobreadbuffer.c @@ -0,0 +1,113 @@ +/* + * $Id: stdio_dropiobreadbuffer.c,v 1.1.1.1 2004-07-26 16:31:24 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* This would otherwise generate far too much (useless) debug output. */ +#ifdef DEBUG +#undef DEBUG +#endif /* DEBUG */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +__drop_iob_read_buffer(struct iob * file) +{ + DECLARE_UTILITYBASE(); + int result = 0; + + ENTER(); + + SHOWPOINTER(file); + + assert( file != NULL ); + assert( UtilityBase != NULL ); + + if(__check_abort_enabled) + __check_abort(); + + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + if(FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE)) + { + CLEAR_FLAG(file->iob_Flags,IOBF_EOF_REACHED); + + if(__iob_read_buffer_is_valid(file)) + { + LONG num_unread_bytes; + + num_unread_bytes = __iob_num_unread_bytes(file); + + D(("%ld bytes are to be dropped",num_unread_bytes)); + + if(num_unread_bytes > 0) + { + struct file_hook_message message; + + SHOWMSG("calling the hook"); + + message.action = file_hook_action_seek; + message.position = -num_unread_bytes; + message.mode = SEEK_CUR; + message.result = 0; + + assert( file->iob_Hook != NULL ); + + CallHookPkt(file->iob_Hook,file,&message); + + if(message.result < 0) + { + SHOWMSG("that didn't work"); + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + + result = -1; + errno = message.error; + + goto out; + } + } + + file->iob_BufferReadBytes = 0; + file->iob_BufferPosition = 0; + } + } + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_duplicate_fd.c b/library/stdio_duplicate_fd.c new file mode 100644 index 0000000..fad2729 --- /dev/null +++ b/library/stdio_duplicate_fd.c @@ -0,0 +1,73 @@ +/* + * $Id: stdio_duplicate_fd.c,v 1.1.1.1 2004-07-26 16:31:24 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +void +__duplicate_fd(struct fd * duplicate_fd,struct fd * original_fd) +{ + HOOKFUNC hook_function; + + assert( duplicate_fd != NULL && original_fd != NULL ); + + /* Obtain the hook function associated with the file; note that + this is different depending upon which operating system + release is being used (compare "stdio_initializefd.c"). */ + #if defined(__amigaos4__) + { + hook_function = original_fd->fd_Hook->h_Entry; + } + #else + { + hook_function = original_fd->fd_Hook->h_SubEntry; + } + #endif /* __amigaos4__ */ + + /* Initialize the duplicate to match the original. */ + __initialize_fd(duplicate_fd,hook_function,original_fd->fd_DefaultFile,original_fd->fd_Flags); + + /* Figure out where the linked list of file descriptors associated + with this one starts. */ + if(original_fd->fd_Original != NULL) + duplicate_fd->fd_Original = original_fd->fd_Original; + else + duplicate_fd->fd_Original = original_fd; + + /* Add the duplicate at the beginning of the list. */ + duplicate_fd->fd_NextLink = duplicate_fd->fd_Original->fd_NextLink; + duplicate_fd->fd_Original->fd_NextLink = duplicate_fd; +} diff --git a/library/stdio_fclose.c b/library/stdio_fclose.c new file mode 100644 index 0000000..453772b --- /dev/null +++ b/library/stdio_fclose.c @@ -0,0 +1,152 @@ +/* + * $Id: stdio_fclose.c,v 1.1.1.1 2004-07-26 16:31:24 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +fclose(FILE *stream) +{ + DECLARE_UTILITYBASE(); + struct iob * file = (struct iob *)stream; + struct file_hook_message message; + int result = OK; + + ENTER(); + + SHOWPOINTER(stream); + + assert( stream != NULL ); + assert( UtilityBase != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + SHOWMSG("invalid stream parameter"); + + result = EOF; + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(file) ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE)) + { + SHOWMSG("this file is not even in use"); + + result = EOF; + + errno = EBADF; + goto out; + } + + /* Push back any buffered data to the stream. */ + if(__iob_write_buffer_is_valid(file) && __flush_iob_write_buffer(file) < 0) + result = EOF; + + /* Make sure that the stream is closed. */ + SHOWMSG("calling the hook"); + + message.action = file_hook_action_close; + message.result = OK; + + assert( file->iob_Hook != NULL ); + + CallHookPkt(file->iob_Hook,file,&message); + + if(result != EOF) + { + result = message.result; + errno = message.error; + } + + /* Now that the file is closed and we are in fact + * dealing with a temporary file, delete that file. + */ + if(FLAG_IS_SET(file->iob_Flags,IOBF_TEMP)) + { + BPTR old_current_dir; + + SHOWMSG("this is a temporary file; deleting it"); + + assert( file->iob_TempFileName != NULL ); + + PROFILE_OFF(); + + old_current_dir = CurrentDir(file->iob_TempFileLock); + DeleteFile(file->iob_TempFileName); + CurrentDir(old_current_dir); + + UnLock(file->iob_TempFileLock); + + PROFILE_ON(); + + free(file->iob_TempFileName); + } + + /* Get rid of any custom file buffer allocated. */ + if(file->iob_CustomBuffer != NULL) + free(file->iob_CustomBuffer); + + memset(file,0,sizeof(*file)); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_fdhookentry.c b/library/stdio_fdhookentry.c new file mode 100644 index 0000000..1da66cb --- /dev/null +++ b/library/stdio_fdhookentry.c @@ -0,0 +1,2204 @@ +/* + * $Id: stdio_fdhookentry.c,v 1.1.1.1 2004-07-26 16:31:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +/* This is used in place of ExamineFH() in order to work around a bug in + * dos.library V40 and below: a "NIL:" file handle will crash the + * ExamineFH() function. + */ +static LONG +safe_examine_file_handle(BPTR file_handle,struct FileInfoBlock *fib) +{ + struct FileHandle * fh = (struct FileHandle *)BADDR(file_handle); + LONG result = DOSFALSE; + + assert( fib != NULL ); + + if(fh == NULL || fh->fh_Type == NULL) + { + SetIoErr(ERROR_OBJECT_WRONG_TYPE); + goto out; + } + + PROFILE_OFF(); + result = ExamineFH(file_handle,fib); + PROFILE_ON(); + + out: + + return(result); +} + +/****************************************************************************/ + +/* Same as above, only for ParentOfFH(). */ +static BPTR +safe_parent_of_file_handle(BPTR file_handle) +{ + struct FileHandle * fh = (struct FileHandle *)BADDR(file_handle); + BPTR result = ZERO; + + if(fh == NULL || fh->fh_Type == NULL) + { + SetIoErr(ERROR_OBJECT_WRONG_TYPE); + goto out; + } + + PROFILE_OFF(); + result = ParentOfFH(file_handle); + PROFILE_ON(); + + out: + + return(result); +} + +/****************************************************************************/ + +#if defined(UNIX_PATH_SEMANTICS) + +/****************************************************************************/ + +/* System-wide global data structure all programs which use advisory file record + * locking with this runtime library will use. + */ +struct FileLockSemaphore +{ + struct SignalSemaphore fls_Semaphore; /* Standard signal semaphore part */ + UWORD fls_Size; /* Size of this data structure (may grow) */ + struct MinList fls_LockList; /* List of lock nodes */ +}; + +/* Each file which has regions locked is registered through the following + * data structure. + */ +struct FileLockNode +{ + struct MinNode fln_MinNode; /* Standard node */ + struct MinList fln_LockedRegionList; /* List of locked regions */ + + BPTR fln_FileParentDir; /* Refers to the file's parent directory */ + UBYTE fln_FileName[1]; /* Name of the file; together with the + * parent directory, this should uniquely + * identify the file. + */ +}; + +/* A single locked region, as associated with a file. */ +struct LockedRegionNode +{ + struct MinNode lrn_MinNode; /* Standard node */ + LONG lrn_Start; /* Where the region begins */ + LONG lrn_Stop; /* Where the region ends (inclusive) */ + LONG lrn_Length; /* Original length requested */ + pid_t lrn_Owner; /* Which process owns the region */ + BOOL lrn_Shared; /* Whether or not this region has been locked + * for shared access. + */ +}; + +/****************************************************************************/ + +static struct FileLockSemaphore * FileLockSemaphore; + +/****************************************************************************/ + +static void release_file_lock_semaphore(struct FileLockSemaphore *fls); +static struct FileLockSemaphore *obtain_file_lock_semaphore(BOOL shared); +static void remove_locked_region_node(struct FileLockSemaphore *fls, struct fd *fd, LONG start, LONG stop, LONG original_length); +static void delete_locked_region_node(struct LockedRegionNode *lrn); +static long create_locked_region_node(struct LockedRegionNode **result_ptr); +static void delete_file_lock_node(struct FileLockNode *fln); +static long create_file_lock_node(struct fd *fd, struct FileLockNode **result_ptr); +static long find_file_lock_node_by_file_handle(struct FileLockSemaphore *fls, BPTR file_handle, struct FileLockNode **result_ptr); +static long find_file_lock_node_by_drawer_and_name(struct FileLockSemaphore *fls, BPTR dir_lock, STRPTR file_name, struct FileLockNode **result_ptr); +static struct LockedRegionNode *find_colliding_region(struct FileLockNode *fln, LONG start, LONG stop, BOOL shared); + +/****************************************************************************/ + +static void +release_file_lock_semaphore(struct FileLockSemaphore * fls) +{ + ENTER(); + + SHOWPOINTER(fls); + + if(fls != NULL) + ReleaseSemaphore((struct SignalSemaphore *)fls); + + LEAVE(); +} + +/****************************************************************************/ + +static struct FileLockSemaphore * +obtain_file_lock_semaphore(BOOL shared) +{ + struct FileLockSemaphore * result = NULL; + + ENTER(); + + if(FileLockSemaphore == NULL && __file_lock_semaphore_name != NULL && __file_lock_semaphore_name[0] != '\0') + { + SHOWMSG("try to find the locking semaphore"); + + Forbid(); + + FileLockSemaphore = (struct FileLockSemaphore *)FindSemaphore((STRPTR)__file_lock_semaphore_name); + if(FileLockSemaphore == NULL) + { + SHOWMSG("didn't find it; we're going to make our own"); + + FileLockSemaphore = AllocMem(sizeof(*FileLockSemaphore) + strlen(__file_lock_semaphore_name)+1,MEMF_ANY|MEMF_PUBLIC); + if(FileLockSemaphore != NULL) + { + SHOWMSG("adding our own semaphore"); + + memset(FileLockSemaphore,0,sizeof(*FileLockSemaphore)); + + InitSemaphore(&FileLockSemaphore->fls_Semaphore); + + FileLockSemaphore->fls_Semaphore.ss_Link.ln_Name = (char *)(FileLockSemaphore + 1); + strcpy(FileLockSemaphore->fls_Semaphore.ss_Link.ln_Name,__file_lock_semaphore_name); + + FileLockSemaphore->fls_Semaphore.ss_Link.ln_Pri = 1; + + FileLockSemaphore->fls_Size = sizeof(*FileLockSemaphore); + NewList((struct List *)&FileLockSemaphore->fls_LockList); + + AddSemaphore(&FileLockSemaphore->fls_Semaphore); + } + else + { + SHOWMSG("not enough memory"); + } + } + else if (FileLockSemaphore->fls_Size < sizeof(*FileLockSemaphore)) + { + SHOWMSG("semaphore found, but it's too short"); + + SHOWVALUE(FileLockSemaphore->fls_Size); + SHOWVALUE(sizeof(*FileLockSemaphore)); + + FileLockSemaphore = NULL; + } + + Permit(); + } + + if(FileLockSemaphore != NULL) + { + SHOWMSG("got a semaphore, using it..."); + + PROFILE_OFF(); + + if(shared) + { + if(((struct Library *)SysBase)->lib_Version >= 39) + { + ObtainSemaphoreShared((struct SignalSemaphore *)FileLockSemaphore); + } + else + { + /* Workaround for shared semaphore nesting problem. */ + if(CANNOT AttemptSemaphoreShared((struct SignalSemaphore *)FileLockSemaphore)) + { + if(CANNOT AttemptSemaphore((struct SignalSemaphore *)FileLockSemaphore)) + ObtainSemaphoreShared((struct SignalSemaphore *)FileLockSemaphore); + } + } + } + else + { + ObtainSemaphore((struct SignalSemaphore *)FileLockSemaphore); + } + + PROFILE_ON(); + + result = FileLockSemaphore; + } + else + { + SHOWMSG("didn't get the semaphore"); + } + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +static void +remove_locked_region_node(struct FileLockSemaphore * fls,struct fd * fd,LONG start,LONG UNUSED stop,LONG original_length) +{ + ENTER(); + + assert( fls != NULL && fd != NULL ); + + if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_LOCKED)) + { + struct FileLockNode * which_lock = NULL; + + SHOWMSG("found a locked file"); + + /* Find the locked file this descriptor + * buffer belongs to. + */ + if(find_file_lock_node_by_file_handle(fls,fd->fd_DefaultFile,&which_lock) == OK) + { + struct LockedRegionNode * lrn; + struct LockedRegionNode * lrn_next; + pid_t this_task = getpid(); + + assert( which_lock != NULL ); + + D(("trying to unlock the region %ld..%ld",start,stop)); + + /* Find the region to unlock and remove it. */ + for(lrn = (struct LockedRegionNode *)which_lock->fln_LockedRegionList.mlh_Head ; + (lrn_next = (struct LockedRegionNode *)lrn->lrn_MinNode.mln_Succ) != NULL ; + lrn = lrn_next) + { + if(lrn->lrn_Owner == this_task && + lrn->lrn_Start == start && + lrn->lrn_Length == original_length) + { + SHOWMSG("unlocking all regions on this file"); + + Remove((struct Node *)lrn); + delete_locked_region_node(lrn); + } + } + + /* Check if there are any locked regions left. + * If not, mark the entire file as unlocked. + */ + if(IsListEmpty((struct List *)&which_lock->fln_LockedRegionList)) + { + SHOWMSG("no more regions are locked; removing the file lock node"); + + Remove((struct Node *)which_lock); + delete_file_lock_node(which_lock); + + /* If this is an alias, move up to the real thing. */ + if(fd->fd_Original != NULL) + fd = fd->fd_Original; + + do + { + CLEAR_FLAG(fd->fd_Flags,FDF_IS_LOCKED); + } + while((fd = fd->fd_NextLink) != NULL); + } + } + } + + LEAVE(); +} + +/****************************************************************************/ + +static void +delete_locked_region_node(struct LockedRegionNode * lrn) +{ + ENTER(); + + SHOWPOINTER(lrn); + + FreeVec(lrn); + + LEAVE(); +} + +/****************************************************************************/ + +static long +create_locked_region_node(struct LockedRegionNode ** result_ptr) +{ + struct LockedRegionNode * lrn; + LONG error = OK; + + ENTER(); + + assert( result_ptr != NULL ); + + lrn = AllocVec(sizeof(*lrn),MEMF_ANY|MEMF_PUBLIC|MEMF_CLEAR); + if(lrn == NULL) + { + SHOWMSG("not enough memory for locked region node"); + + error = ERROR_NO_FREE_STORE; + goto out; + } + + lrn->lrn_Owner = getpid(); + + out: + + (*result_ptr) = lrn; + + RETURN(error); + return(error); +} + +/****************************************************************************/ + +static void +delete_file_lock_node(struct FileLockNode * fln) +{ + ENTER(); + + SHOWPOINTER(fln); + + if(fln != NULL) + { + PROFILE_OFF(); + UnLock(fln->fln_FileParentDir); + PROFILE_ON(); + + FreeVec(fln); + } + + LEAVE(); +} + +/****************************************************************************/ + +static long +create_file_lock_node(struct fd * fd,struct FileLockNode ** result_ptr) +{ + struct FileLockNode * result = NULL; + struct FileLockNode * fln = NULL; + D_S(struct FileInfoBlock,fib); + LONG error = OK; + + ENTER(); + + assert( fd != NULL && result_ptr != NULL ); + + /* We store a lock on the file's parent directory + * and the name of the file for later use in + * comparisons. + */ + if(CANNOT safe_examine_file_handle(fd->fd_DefaultFile,fib)) + { + SHOWMSG("couldn't examine file handle"); + + error = IoErr(); + goto out; + } + + fln = AllocVec(sizeof(*fln) + strlen(fib->fib_FileName),MEMF_ANY|MEMF_PUBLIC); + if(fln == NULL) + { + SHOWMSG("not enough memory for lock node"); + + error = ERROR_NO_FREE_STORE; + goto out; + } + + memset(fln,0,sizeof(*fln)); + + fln->fln_FileParentDir = safe_parent_of_file_handle(fd->fd_DefaultFile); + if(fln->fln_FileParentDir == ZERO) + { + SHOWMSG("couldn't get parent directory"); + + error = IoErr(); + goto out; + } + + strcpy(fln->fln_FileName,fib->fib_FileName); + + NewList((struct List *)&fln->fln_LockedRegionList); + + result = fln; + fln = NULL; + + out: + + delete_file_lock_node(fln); + + (*result_ptr) = result; + + RETURN(error); + return(error); +} + +/****************************************************************************/ + +static long +find_file_lock_node_by_drawer_and_name( + struct FileLockSemaphore * fls, + BPTR dir_lock, + STRPTR file_name, + struct FileLockNode ** result_ptr) +{ + DECLARE_UTILITYBASE(); + struct FileLockNode * result = NULL; + struct FileLockNode * fln; + LONG status; + LONG error; + + ENTER(); + + assert( fls != NULL && dir_lock != ZERO && file_name != NULL && result_ptr != NULL ); + assert( UtilityBase != NULL ); + + #if DEBUG + { + char name[FILENAME_MAX]; + + if(NameFromLock(dir_lock,name,sizeof(name))) + { + if(AddPart(name,file_name,sizeof(name))) + D(("Looking for a lock on file |%s|",name)); + } + } + #endif /* DEBUG */ + + error = ERROR_OBJECT_NOT_FOUND; + + for(fln = (struct FileLockNode *)fls->fls_LockList.mlh_Head ; + fln->fln_MinNode.mln_Succ != NULL ; + fln = (struct FileLockNode *)fln->fln_MinNode.mln_Succ) + { + PROFILE_OFF(); + status = SameLock(fln->fln_FileParentDir,dir_lock); + PROFILE_ON(); + + if(status == LOCK_SAME) + { + if(Stricmp(fln->fln_FileName,file_name) == SAME) + { + error = OK; + + result = fln; + + break; + } + } + } + + if(result != NULL) + SHOWMSG("found one"); + else + SHOWMSG("didn't find one"); + + (*result_ptr) = result; + + RETURN(error); + return(error); +} + +/****************************************************************************/ + +static LONG +find_file_lock_node_by_file_handle( + struct FileLockSemaphore * fls, + BPTR file_handle, + struct FileLockNode ** result_ptr) +{ + D_S(struct FileInfoBlock,this_fib); + BPTR parent_dir = ZERO; + LONG error; + + ENTER(); + + assert( fls != NULL && file_handle != ZERO && result_ptr != NULL ); + + (*result_ptr) = NULL; + + if(CANNOT safe_examine_file_handle(file_handle,this_fib)) + { + SHOWMSG("couldn't examine file handle"); + + error = IoErr(); + goto out; + } + + /* Determine the file's parent directory and + * name. These will be compared against the + * global file lock data. + */ + parent_dir = safe_parent_of_file_handle(file_handle); + if(parent_dir == ZERO) + { + SHOWMSG("couldn't get parent directory"); + + error = IoErr(); + goto out; + } + + error = find_file_lock_node_by_drawer_and_name(fls,parent_dir,this_fib->fib_FileName,result_ptr); + if(error != OK) + { + SHOWMSG("couldn't find a lock node for the file"); + goto out; + } + + out: + + PROFILE_OFF(); + UnLock(parent_dir); + PROFILE_ON(); + + RETURN(error); + return(error); +} + +/****************************************************************************/ + +static struct LockedRegionNode * +find_colliding_region(struct FileLockNode * fln,LONG start,LONG stop,BOOL shared) +{ + struct LockedRegionNode * result = NULL; + struct LockedRegionNode * lrn; + pid_t this_task = getpid(); + + ENTER(); + + assert( fln != NULL && start <= stop ); + + SHOWVALUE(start); + SHOWVALUE(stop); + SHOWVALUE(shared); + + /* This routine looks for a locked region that overlaps + * with the specified region. It returns a pointer to the + * region that would collide with the specified region if + * a new lock were to be added. + */ + for(lrn = (struct LockedRegionNode *)fln->fln_LockedRegionList.mlh_Head ; + lrn->lrn_MinNode.mln_Succ != NULL ; + lrn = (struct LockedRegionNode *)lrn->lrn_MinNode.mln_Succ) + { + /* Do the regions overlap? */ + if(lrn->lrn_Start <= stop && start <= lrn->lrn_Stop) + { + /* Two shared regions may always overlap. + * How about the rest? + */ + if(NOT shared || NOT lrn->lrn_Shared) + { + /* The lock owner may add as many exclusive + * or shared locks to the same region as + * necessary. + */ + if(lrn->lrn_Owner == this_task) + { + /*kprintf("lock collision [%ld..%ld] : [%ld..%ld]\n",start,stop,lrn->lrn_Start,lrn->lrn_Stop);*/ + continue; + } + + /* So we found a region that would + * cause a collision. + */ + result = lrn; + break; + } + } + } + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +static void +cleanup_locked_records(struct fd * fd) +{ + ENTER(); + + assert( fd != NULL ); + + /* This routine removes all locked regions from a file + * before it is eventually closed. + */ + + if(FLAG_IS_SET(fd->fd_Flags,FDF_IS_LOCKED)) + { + struct FileLockSemaphore * fls; + + fls = obtain_file_lock_semaphore(FALSE); + if(fls != NULL) + { + BPTR file_handle = fd->fd_DefaultFile; + struct FileLockNode * which_lock = NULL; + pid_t this_task = getpid(); + LONG error; + + error = find_file_lock_node_by_file_handle(fls,file_handle,&which_lock); + if(error == OK) + { + struct LockedRegionNode * lrn_this; + struct LockedRegionNode * lrn_next; + + assert( which_lock != NULL ); + + SHOWMSG("unlocking all regions on this file"); + + for(lrn_this = (struct LockedRegionNode *)which_lock->fln_LockedRegionList.mlh_Head ; + (lrn_next = (struct LockedRegionNode *)lrn_this->lrn_MinNode.mln_Succ) != NULL ; + lrn_this = lrn_next) + { + if(lrn_this->lrn_Owner == this_task) + { + Remove((struct Node *)lrn_this); + + delete_locked_region_node(lrn_this); + } + } + + if(IsListEmpty((struct List *)&which_lock->fln_LockedRegionList)) + { + SHOWMSG("no more regions are locked; removing the file lock node"); + + Remove((struct Node *)which_lock); + + delete_file_lock_node(which_lock); + } + } + + if(error == OK || error == ERROR_OBJECT_NOT_FOUND) + { + /* If this is an alias, move up to the real thing. */ + if(fd->fd_Original != NULL) + fd = fd->fd_Original; + + do + { + CLEAR_FLAG(fd->fd_Flags,FDF_IS_LOCKED); + } + while((fd = fd->fd_NextLink) != NULL); + } + + release_file_lock_semaphore(fls); + } + } + + LEAVE(); +} + +/****************************************************************************/ + +static int +handle_record_locking(int cmd,struct flock * l,struct fd * fd,int * error_ptr) +{ + struct FileLockSemaphore * fls = NULL; + BPTR file_handle = fd->fd_DefaultFile; + struct LockedRegionNode * lrn = NULL; + struct FileLockNode * fln = NULL; + D_S(struct FileInfoBlock,fib); + BOOL fib_is_valid = FALSE; + BPTR parent_dir = ZERO; + LONG current_position; + int result = ERROR; + LONG original_len; + LONG error = OK; + LONG start = 0; + LONG len = 0; + LONG stop; + + ENTER(); + + /* This routine implements advisory file segment locking + * similar to 4.4BSD, but not quite the same. The functionality + * is a subset, somewhat similar to the functionality offered + * by the AmigaDOS LockRecord() and UnlockRecord() functions. + * This means for example that every unlock request must + * match the size and position of the corresponding locking + * request. + * + * This implementation was chosen because not every Amiga + * filing system implements record locking and Samba + * absolutely requires this functionality to work. + */ + assert( l != NULL && fd != NULL); + assert( F_RDLCK <= l->l_type && l->l_type <= F_WRLCK ); + assert( SEEK_SET <= l->l_whence && l->l_whence <= SEEK_END ); + assert( error_ptr != NULL ); + + if((cmd == F_SETLK || cmd == F_SETLKW) && (l->l_type != F_UNLCK)) + { + SHOWMSG("this is a lock request"); + + error = create_file_lock_node(fd,&fln); + if(error != OK) + { + SHOWMSG("could not create lock node"); + goto out; + } + + error = create_locked_region_node(&lrn); + if(error != OK) + { + SHOWMSG("could not create region node"); + goto out; + } + } + else + { + SHOWMSG("this is not a lock request"); + } + + original_len = l->l_len; + + /* Now calculate the position of the first byte to lock and the number + * of bytes to lock. + */ + switch(l->l_whence) + { + case SEEK_SET: + + SHOWMSG("SEEK_SET"); + + start = l->l_start; + + if(l->l_len == 0) + len = LONG_MAX; + else + len = l->l_len; + + SHOWVALUE(start); + SHOWVALUE(len); + + break; + + case SEEK_CUR: + + SHOWMSG("SEEK_CUR"); + + PROFILE_OFF(); + + current_position = Seek(file_handle,0,OFFSET_CURRENT); + + PROFILE_ON(); + + if(current_position == SEEK_ERROR) + { + SHOWMSG("could not obtain current seek position"); + + error = IoErr(); + goto out; + } + + start = current_position + l->l_start; + + if(l->l_len == 0) + len = LONG_MAX; + else + len = l->l_len; + + SHOWVALUE(start); + SHOWVALUE(len); + + break; + + case SEEK_END: + + SHOWMSG("SEEK_END"); + + if(CANNOT safe_examine_file_handle(file_handle,fib)) + { + SHOWMSG("could not examine file"); + + error = IoErr(); + goto out; + } + + fib_is_valid = TRUE; + + start = fib->fib_Size + l->l_start; + + if(l->l_len == 0) + len = LONG_MAX; + else + len = l->l_len; + + SHOWVALUE(start); + SHOWVALUE(len); + + break; + } + + SHOWVALUE(start); + SHOWVALUE(len); + + if(start < 0) + { + SHOWMSG("invalid start"); + + (*error_ptr) = EINVAL; + goto out; + } + + if(len < 0) + { + start += len; + if(start < 0) + { + SHOWMSG("invalid start"); + + (*error_ptr) = EINVAL; + goto out; + } + + stop = start - len - 1; + if(stop < start) + stop = LONG_MAX; + } + else + { + stop = start - 1 + len; + if(stop < start - 1) /* Check for overflow */ + stop = LONG_MAX; + } + + if(l->l_type == F_UNLCK) + { + SHOWMSG("F_UNLCK"); + + fls = obtain_file_lock_semaphore(FALSE); + if(fls == NULL) + { + SHOWMSG("couldn't obtain file locking semaphore"); + (*error_ptr) = EBADF; + goto out; + } + + D(("unlocking %ld..%ld",start,stop)); + + remove_locked_region_node(fls,fd,start,stop,original_len); + } + else if (cmd == F_SETLKW) + { + struct FileLockNode * existing_fln; + BOOL locked; + BOOL shared; + + SHOWMSG("F_SETLKW"); + + D((" locking %ld..%ld",start,stop)); + + if(NOT fib_is_valid && CANNOT safe_examine_file_handle(file_handle,fib)) + { + SHOWMSG("couldn't read this file's name"); + + error = IoErr(); + goto out; + } + + parent_dir = safe_parent_of_file_handle(file_handle); + if(parent_dir == ZERO) + { + SHOWMSG("couldn't get a lock on the file's parent directory"); + + error = IoErr(); + goto out; + } + + shared = (BOOL)(l->l_type == F_RDLCK); + + if(shared) + D(("this is a shared lock; waiting for completion")); + else + D(("this is an exclusive lock; waiting for completion")); + + /* Shared locks require readable files, exclusive locks require + writable files. */ + if((shared && FLAG_IS_CLEAR(fd->fd_Flags,FDF_READ)) || + (NOT shared && FLAG_IS_CLEAR(fd->fd_Flags,FDF_WRITE))) + { + (*error_ptr) = EBADF; + goto out; + } + + lrn->lrn_Start = start; + lrn->lrn_Stop = stop; + lrn->lrn_Length = original_len; + lrn->lrn_Shared = shared; + + /* Retry until we manage to lock the record. */ + locked = FALSE; + + do + { + fls = obtain_file_lock_semaphore(FALSE); + if(fls == NULL) + { + SHOWMSG("couldn't obtain file locking semaphore"); + (*error_ptr) = EBADF; + goto out; + } + + if(find_file_lock_node_by_drawer_and_name(fls,parent_dir,fib->fib_FileName,&existing_fln) == OK) + { + SHOWMSG("that file is already locked by someone"); + + if(find_colliding_region(existing_fln,start,stop,shared) == NULL) + { + SHOWMSG("but the locks don't collide"); + + AddTail((struct List *)&existing_fln->fln_LockedRegionList,(struct Node *)lrn); + lrn = NULL; + + locked = TRUE; + } + else + { + SHOWMSG("and the locks collide"); + } + } + else + { + SHOWMSG("nobody has any locks on this file"); + + AddTail((struct List *)&fls->fls_LockList,(struct Node *)fln); + AddTail((struct List *)&fln->fln_LockedRegionList,(struct Node *)lrn); + + fln = NULL; + lrn = NULL; + + locked = TRUE; + } + + release_file_lock_semaphore(fls); + fls = NULL; + + if(NOT locked) + { + const int rand_max = RAND_MAX / 65536; + int num_random_ticks; + + if(__check_abort_enabled && (SetSignal(0,0) & SIGBREAKF_CTRL_C) != 0) + { + SHOWMSG("lock polling loop stopped"); + + delete_file_lock_node(fln); + fln = NULL; + + delete_locked_region_node(lrn); + lrn = NULL; + + PROFILE_OFF(); + UnLock(parent_dir); + PROFILE_ON(); + + parent_dir = ZERO; + + (*error_ptr) = EINTR; + + __check_abort(); + goto out; + } + + /* Wait a little before retrying + * the locking operation. We add + * a little randomness here to + * reduce the likelihood of two + * competing processes trying to + * lock the same file at the + * same time. + */ + + num_random_ticks = ((TICKS_PER_SECOND / 2) * (rand() / 65536)) / rand_max; + + if(num_random_ticks > 0) + { + PROFILE_OFF(); + Delay(num_random_ticks); + PROFILE_ON(); + } + } + } + while(NOT locked); + + SHOWMSG("the file now has a lock set"); + + /* If this is an alias, move up to the real thing. */ + if(fd->fd_Original != NULL) + fd = fd->fd_Original; + + do + { + SET_FLAG(fd->fd_Flags,FDF_IS_LOCKED); + } + while((fd = fd->fd_NextLink) != NULL); + } + else if (cmd == F_SETLK) + { + BOOL shared = (BOOL)(l->l_type == F_RDLCK); + struct FileLockNode * existing_fln = NULL; + + SHOWMSG("F_SETLK"); + + if(shared) + D(("this is a shared lock")); + else + D(("this is an exclusive lock")); + + /* Shared locks require readable files, exclusive locks require + writable files. */ + if((shared && FLAG_IS_CLEAR(fd->fd_Flags,FDF_READ)) || + (NOT shared && FLAG_IS_CLEAR(fd->fd_Flags,FDF_WRITE))) + { + (*error_ptr) = EBADF; + goto out; + } + + lrn->lrn_Start = start; + lrn->lrn_Stop = stop; + lrn->lrn_Length = original_len; + lrn->lrn_Shared = shared; + + fls = obtain_file_lock_semaphore(FALSE); + if(fls == NULL) + { + SHOWMSG("couldn't obtain file locking semaphore"); + (*error_ptr) = EBADF; + goto out; + } + + error = find_file_lock_node_by_file_handle(fls,file_handle,&existing_fln); + if(error == OK) + { + SHOWMSG("that file is already locked by someone else"); + + if(find_colliding_region(existing_fln,start,stop,shared) != NULL) + { + SHOWMSG("and the locks collide"); + + (*error_ptr) = EACCES; + goto out; + } + + SHOWMSG("but the locks don't collide"); + + AddTail((struct List *)&existing_fln->fln_LockedRegionList,(struct Node *)lrn); + lrn = NULL; + } + else + { + if(error != ERROR_OBJECT_NOT_FOUND) + goto out; + + SHOWMSG("nobody has any locks on this file"); + + AddTail((struct List *)&fls->fls_LockList,(struct Node *)fln); + AddTail((struct List *)&fln->fln_LockedRegionList,(struct Node *)lrn); + + fln = NULL; + lrn = NULL; + } + + SHOWMSG("the file now has a lock set"); + + /* If this is an alias, move up to the real thing. */ + if(fd->fd_Original != NULL) + fd = fd->fd_Original; + + do + { + SET_FLAG(fd->fd_Flags,FDF_IS_LOCKED); + } + while((fd = fd->fd_NextLink) != NULL); + } + else if (cmd == F_GETLK) + { + struct FileLockNode * fln_found = NULL; + + SHOWMSG("F_GETLK"); + + fls = obtain_file_lock_semaphore(TRUE); + if(fls == NULL) + { + SHOWMSG("couldn't obtain file locking semaphore"); + (*error_ptr) = EBADF; + goto out; + } + + SHOWMSG("checking for possible lock collision"); + + error = find_file_lock_node_by_file_handle(fls,file_handle,&fln_found); + if(error == OK) + { + BOOL shared = (BOOL)(l->l_type == F_RDLCK); + struct LockedRegionNode * lrn_found; + + SHOWMSG("somebody has locked this file"); + + lrn_found = find_colliding_region(fln_found,start,stop,shared); + if(lrn_found != NULL) + { + SHOWMSG("there is a possible lock collision"); + + l->l_type = (lrn_found->lrn_Shared ? F_RDLCK : F_WRLCK); + l->l_whence = SEEK_SET; + l->l_start = lrn_found->lrn_Start; + l->l_len = lrn_found->lrn_Length; + l->l_pid = lrn_found->lrn_Owner; + + SHOWVALUE(l->l_type); + SHOWVALUE(l->l_whence); + SHOWVALUE(l->l_start); + SHOWVALUE(l->l_len); + SHOWVALUE(l->l_pid); + } + else + { + SHOWMSG("there is no lock collision"); + + l->l_type = F_UNLCK; + } + } + else + { + if(error != ERROR_OBJECT_NOT_FOUND) + goto out; + + SHOWMSG("nobody has locked this file"); + + l->l_type = F_UNLCK; + } + } + + result = OK; + + out: + + delete_file_lock_node(fln); + delete_locked_region_node(lrn); + + release_file_lock_semaphore(fls); + + PROFILE_OFF(); + UnLock(parent_dir); + PROFILE_ON(); + + if(result != OK && error != OK) + { + SetIoErr(error); + + __translate_io_error_to_errno(IoErr(),error_ptr); + } + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* UNIX_PATH_SEMANTICS */ + +/****************************************************************************/ + +/* Seek to the end of a file, then add a certain number of 0 bytes. */ +static int +grow_file_size(struct fd * fd,int num_bytes,int * error_ptr) +{ + unsigned char * aligned_buffer; + unsigned char * buffer; + struct FileHandle * fh; + D_S(struct InfoData,id); + LONG block_size; + int bytes_written; + int buffer_size; + int size; + int result = ERROR; + int position; + int current_position; + int alignment_skip; + + assert( fd != NULL ); + assert( error_ptr != NULL ); + + D(("we have to grow the file by %ld bytes",num_bytes)); + + block_size = 0; + + PROFILE_OFF(); + + fh = BADDR(fd->fd_DefaultFile); + if(fh != NULL && fh->fh_Type != NULL && DoPkt(fh->fh_Type,ACTION_DISK_INFO,MKBADDR(id),0,0,0,0)) + block_size = id->id_BytesPerBlock; + + PROFILE_ON(); + + if(block_size < 512) + block_size = 512; + + /* We have to fill up the file with zero bytes. + * That data comes from a local buffer. How + * large can we make it? + */ + buffer_size = 8 * block_size; + if(buffer_size > num_bytes) + buffer_size = num_bytes; + + /* Allocate a little more memory than required to allow for + * the buffer to be aligned to a cache line boundary. + */ + buffer = malloc((size_t)buffer_size + 15); + if(buffer == NULL) + { + SHOWMSG("not enough memory for write buffer"); + + (*error_ptr) = ENOMEM; + goto out; + } + + /* Align the buffer to a cache line boundary. */ + aligned_buffer = (unsigned char *)(((ULONG)(buffer + 15)) & ~15UL); + + memset(aligned_buffer,0,(size_t)buffer_size); + + PROFILE_OFF(); + + position = Seek(fd->fd_DefaultFile,0,OFFSET_END); + + PROFILE_ON(); + + if(position == -1) + { + SHOWMSG("could not move to the end of the file"); + + __translate_io_error_to_errno(IoErr(),error_ptr); + goto out; + } + + PROFILE_OFF(); + + current_position = Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT); + + PROFILE_ON(); + + /* Try to make the first write access align the file position + * to a block offset. Subsequent writes will then access the + * file at positions that are multiples of the block size. + */ + if(num_bytes > block_size && (current_position % block_size) != 0) + alignment_skip = block_size - (current_position % block_size); + else + alignment_skip = 0; + + while(num_bytes > 0) + { + if(__check_abort_enabled) + __check_abort(); + + size = buffer_size; + if(size > num_bytes) + size = num_bytes; + + /* If possible, even out the block offset. */ + if(alignment_skip > 0 && size > alignment_skip) + size = alignment_skip; + + alignment_skip = 0; + + PROFILE_OFF(); + + bytes_written = Write(fd->fd_DefaultFile,aligned_buffer,size); + + PROFILE_ON(); + + if(bytes_written != size) + { + __translate_io_error_to_errno(IoErr(),error_ptr); + goto out; + } + + num_bytes -= size; + } + + SHOWMSG("all done."); + + result = OK; + + out: + + if(buffer != NULL) + free(buffer); + + return(result); +} + +/****************************************************************************/ + +void +__fd_hook_entry( + struct Hook * UNUSED unused_hook, + struct fd * fd, + struct file_hook_message * message) +{ + char * buffer = NULL; + int result = -1; + int error = OK; + LONG position; + + ENTER(); + + assert( message != NULL && fd != NULL ); + assert( __is_valid_fd(fd) ); + + switch(message->action) + { + case file_hook_action_read: + + SHOWMSG("file_hook_action_read"); + + if(fd->fd_DefaultFile == ZERO) + { + SHOWMSG("file is closed"); + + error = EBADF; + break; + } + + assert( message->data != NULL ); + assert( message->size > 0 ); + + D(("read %ld bytes from position %ld to 0x%08lx",message->size,Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT),message->data)); + + PROFILE_OFF(); + + result = Read(fd->fd_DefaultFile,message->data,message->size); + + PROFILE_ON(); + + if(result < 0) + { + D(("read failed ioerr=%ld",IoErr())); + __translate_io_error_to_errno(IoErr(),&error); + break; + } + + if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) + fd->fd_Position += result; + + break; + + case file_hook_action_write: + + SHOWMSG("file_hook_action_write"); + + if(fd->fd_DefaultFile == ZERO) + { + SHOWMSG("file is closed"); + + error = EBADF; + break; + } + + assert( message->data != NULL ); + assert( message->size > 0 ); + + if(FLAG_IS_SET(fd->fd_Flags,FDF_APPEND)) + { + SHOWMSG("appending data"); + + PROFILE_OFF(); + + if(Seek(fd->fd_DefaultFile,0,OFFSET_END) >= 0) + { + if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) + fd->fd_Position = Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT); + } + + PROFILE_ON(); + } + + D(("write %ld bytes to position %ld from 0x%08lx",message->size,Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT),message->data)); + + PROFILE_OFF(); + + result = Write(fd->fd_DefaultFile,message->data,message->size); + + PROFILE_ON(); + + if(result < 0) + { + D(("write failed ioerr=%ld",IoErr())); + + __translate_io_error_to_errno(IoErr(),&error); + break; + } + + if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) + fd->fd_Position += result; + + break; + + /* This one implements Unix-like lseek() functionality. We report the + * new file position upon return and will try to extend the size of a + * file if the new seek position lies beyond the end of the file. + */ + case file_hook_action_seek_and_extend: + case file_hook_action_seek: + + SHOWMSG("file_hook_action_seek(_and_extend)"); + + if(fd->fd_DefaultFile != ZERO) + { + D_S(struct FileInfoBlock,fib); + BOOL fib_is_valid = FALSE; + LONG current_position; + LONG new_position; + LONG mode; + + assert( message->mode == SEEK_CUR || + message->mode == SEEK_SET || + message->mode == SEEK_END ); + + if(message->mode == SEEK_CUR) + mode = OFFSET_CURRENT; + else if (message->mode == SEEK_SET) + mode = OFFSET_BEGINNING; + else + mode = OFFSET_END; + + D(("seek&extended to offset %ld, mode %ld; current position = %ld",message->position,mode,Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT))); + + if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) + { + current_position = fd->fd_Position; + } + else + { + PROFILE_OFF(); + + current_position = Seek(fd->fd_DefaultFile,0,OFFSET_CURRENT); + + PROFILE_ON(); + + if(current_position < 0) + { + error = EBADF; + break; + } + } + + new_position = current_position; + + switch(mode) + { + case OFFSET_CURRENT: + + new_position += message->position; + break; + + case OFFSET_BEGINNING: + + new_position = message->position; + break; + + case OFFSET_END: + + if(safe_examine_file_handle(fd->fd_DefaultFile,fib)) + { + new_position = fib->fib_Size + message->position; + + fib_is_valid = TRUE; + } + + break; + } + + if(new_position == current_position) + { + result = new_position; + + if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) + fd->fd_Position = new_position; + } + else + { + PROFILE_OFF(); + + position = Seek(fd->fd_DefaultFile,message->position,mode); + + PROFILE_ON(); + + if(position >= 0) + { + if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) + fd->fd_Position = new_position; + + result = new_position; + } + else + { + D(("seek failed, mode=%ld (%ld), offset=%ld, ioerr=%ld",mode,message->mode,message->position,IoErr())); + + __translate_io_error_to_errno(IoErr(),&error); + + #if defined(UNIX_PATH_SEMANTICS) + { + /* Check if the file would have become larger as a + * result of this action. + */ + if(message->action != file_hook_action_seek_and_extend) + break; + + if(NOT fib_is_valid && CANNOT safe_examine_file_handle(fd->fd_DefaultFile,fib)) + break; + + if(new_position <= fib->fib_Size) + break; + + if(grow_file_size(fd,new_position - fib->fib_Size,&error) != OK) + break; + + if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) + fd->fd_Position = new_position; + + result = new_position; + } + #endif /* UNIX_PATH_SEMANTICS */ + } + } + } + else + { + SHOWMSG("file is closed"); + + error = EBADF; + } + + break; + + case file_hook_action_close: + + SHOWMSG("file_hook_action_close"); + + if(fd->fd_DefaultFile != ZERO) + { + BOOL name_and_path_valid = FALSE; + D_S(struct FileInfoBlock,fib); + BPTR parent_dir; + + memset(fib,0,sizeof(*fib)); + + #if defined(UNIX_PATH_SEMANTICS) + { + cleanup_locked_records(fd); + } + #endif /* UNIX_PATH_SEMANTICS */ + + PROFILE_OFF(); + + parent_dir = safe_parent_of_file_handle(fd->fd_DefaultFile); + if(parent_dir != ZERO) + { + if(safe_examine_file_handle(fd->fd_DefaultFile,fib)) + name_and_path_valid = TRUE; + } + + if(CANNOT Close(fd->fd_DefaultFile)) + __translate_io_error_to_errno(IoErr(),&error); + + PROFILE_ON(); + + fd->fd_DefaultFile = ZERO; + + #if defined(UNIX_PATH_SEMANTICS) + { + DECLARE_UTILITYBASE(); + + assert( UtilityBase != NULL ); + + /* Now that we have closed this file, know where it is and what its + * name would be, check if we tried to unlink it earlier. If we did, + * we'll try to finish the job here and now. + */ + if(name_and_path_valid) + { + struct UnlinkNode * node; + struct UnlinkNode * uln_next; + struct UnlinkNode * uln; + BOOL file_deleted = FALSE; + + assert( __unlink_list.mlh_Head != NULL ); + + /* Check all files to be unlinked when this program exits. */ + for(uln = (struct UnlinkNode *)__unlink_list.mlh_Head ; + (uln_next = (struct UnlinkNode *)uln->uln_MinNode.mln_Succ) != NULL ; + uln = uln_next) + { + node = NULL; + + /* If the file name matches, check if the path matches, too. */ + if(Stricmp(FilePart(uln->uln_Name),fib->fib_FileName) == SAME) + { + BPTR old_dir; + BPTR node_lock; + BPTR path_lock = ZERO; + + PROFILE_OFF(); + + /* Try to get a lock on the file first, then move on to + * the directory it is stored in. + */ + old_dir = CurrentDir(uln->uln_Lock); + + node_lock = Lock(uln->uln_Name,SHARED_LOCK); + if(node_lock != ZERO) + { + path_lock = ParentDir(node_lock); + + UnLock(node_lock); + } + + CurrentDir(old_dir); + + /* If we found the file's parent directory, check if it matches + * the parent directory of the file we just closed. + */ + if(path_lock != ZERO) + { + if(SameLock(path_lock,parent_dir) == LOCK_SAME) + node = uln; + + UnLock(path_lock); + } + + PROFILE_ON(); + } + + /* If we found that this file was set up for deletion, + * delete it here and now. + */ + if(node != NULL) + { + if(NOT file_deleted) + { + BPTR old_dir; + + PROFILE_OFF(); + + old_dir = CurrentDir(parent_dir); + + if(DeleteFile(fib->fib_FileName)) + { + file_deleted = TRUE; + name_and_path_valid = FALSE; + } + + CurrentDir(old_dir); + + PROFILE_ON(); + } + + if(file_deleted) + { + Remove((struct Node *)node); + free(node); + } + } + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + if(FLAG_IS_SET(fd->fd_Flags,FDF_CREATED) && name_and_path_valid) + { + ULONG flags; + BPTR old_dir; + + PROFILE_OFF(); + + old_dir = CurrentDir(parent_dir); + + flags = fib->fib_Protection ^ (FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE); + + CLEAR_FLAG(flags,FIBF_EXECUTE); + CLEAR_FLAG(flags,FIBF_OTR_EXECUTE); + CLEAR_FLAG(flags,FIBF_GRP_EXECUTE); + + SetProtection(fib->fib_FileName,(LONG)(flags ^ (FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE))); + + CurrentDir(old_dir); + + PROFILE_ON(); + } + + PROFILE_OFF(); + UnLock(parent_dir); + PROFILE_ON(); + + result = 0; + } + else + { + SHOWMSG("file is closed"); + + error = EBADF; + } + + break; + + case file_hook_action_lock_record: + + SHOWMSG("file_hook_action_lock_record"); + + #if defined(UNIX_PATH_SEMANTICS) + { + SHOWMSG("performing record locking"); + + if(fd->fd_DefaultFile == ZERO) + { + SHOWMSG("file is closed"); + + error = EBADF; + break; + } + + result = handle_record_locking(message->command,message->lock,fd,&error); + } + #else + { + SHOWMSG("no record locking support in this library"); + + error = EBADF; + } + #endif /* UNIX_PATH_SEMANTICS */ + + break; + + case file_hook_action_set_blocking: + + SHOWMSG("file_hook_action_set_blocking"); + + PROFILE_OFF(); + + if(fd->fd_DefaultFile != ZERO && ((struct FileHandle *)BADDR(fd->fd_DefaultFile))->fh_Type != NULL && IsInteractive(fd->fd_DefaultFile)) + { + LONG mode; + + SHOWMSG("changing the mode"); + + if(message->block) + mode = 0; /* buffered mode */ + else + mode = 1; /* single character mode */ + + if(CANNOT SetMode(fd->fd_DefaultFile,mode)) + { + error = EBADF; + break; + } + + result = 0; + } + else + { + SHOWMSG("can't do anything here"); + + error = EBADF; + } + + PROFILE_ON(); + + break; + + case file_hook_action_change_owner: + + SHOWMSG("file_hook_action_change_owner"); + + if(message->owner > 65535 || message->group > 65535) + { + SHOWMSG("owner or group not OK"); + + SHOWVALUE(message->owner); + SHOWVALUE(message->group); + + error = EINVAL; + break; + } + + if(fd->fd_DefaultFile != ZERO) + { + D_S(struct FileInfoBlock,fib); + + PROFILE_OFF(); + + if(safe_examine_file_handle(fd->fd_DefaultFile,fib)) + { + BPTR parent_dir; + + parent_dir = safe_parent_of_file_handle(fd->fd_DefaultFile); + if(parent_dir != ZERO) + { + BPTR old_current_dir; + + old_current_dir = CurrentDir(parent_dir); + + if(((struct Library *)DOSBase)->lib_Version >= 39) + { + SHOWMSG("changing owner"); + + if(SetOwner(fib->fib_FileName,(LONG)((((ULONG)message->owner) << 16) | message->group))) + { + result = 0; + } + else + { + SHOWMSG("that didn't work"); + + __translate_io_error_to_errno(IoErr(),&error); + } + } + else + { + D_S(struct bcpl_name,new_name); + struct DevProc * dvp; + unsigned int len; + + SHOWMSG("have to do this manually..."); + + len = strlen(fib->fib_FileName); + + assert( len < sizeof(new_name->name) ); + + dvp = GetDeviceProc(fib->fib_FileName,NULL); + if(dvp != NULL) + { + new_name->name[0] = len; + memmove(&new_name->name[1],fib->fib_FileName,len); + + if(DoPkt(dvp->dvp_Port,ACTION_SET_OWNER,dvp->dvp_Lock,MKBADDR(new_name),(LONG)((((ULONG)message->owner) << 16) | message->group),0,0)) + result = 0; + else + __translate_io_error_to_errno(IoErr(),&error); + + FreeDeviceProc(dvp); + } + else + { + __translate_io_error_to_errno(IoErr(),&error); + } + } + + CurrentDir(old_current_dir); + + UnLock(parent_dir); + } + else + { + SHOWMSG("couldn't find parent directory"); + + __translate_io_error_to_errno(IoErr(),&error); + } + } + else + { + SHOWMSG("couldn't examine file handle"); + + __translate_io_error_to_errno(IoErr(),&error); + } + + PROFILE_ON(); + } + else + { + SHOWMSG("file is closed"); + + error = EBADF; + } + + break; + + case file_hook_action_truncate: + + SHOWMSG("file_hook_action_truncate"); + + if(fd->fd_DefaultFile != ZERO) + { + D_S(struct FileInfoBlock,fib); + + SHOWMSG("trying to change file size"); + + if(CANNOT safe_examine_file_handle(fd->fd_DefaultFile,fib)) + { + __translate_io_error_to_errno(IoErr(),&error); + break; + } + + PROFILE_OFF(); + + if(message->size < fib->fib_Size) + { + /* Careful: seek to a position where the file can be safely truncated. */ + if(Seek(fd->fd_DefaultFile,message->size,OFFSET_BEGINNING) != -1 && SetFileSize(fd->fd_DefaultFile,message->size,OFFSET_BEGINNING) != -1) + { + if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) + fd->fd_Position = message->size; + + result = 0; + } + else + { + __translate_io_error_to_errno(IoErr(),&error); + } + } + else if (message->size > fib->fib_Size) + { + if(Seek(fd->fd_DefaultFile,fib->fib_Size,OFFSET_BEGINNING) != -1 && grow_file_size(fd,message->size - fib->fib_Size,&error) == OK) + { + if(FLAG_IS_SET(fd->fd_Flags,FDF_CACHE_POSITION)) + fd->fd_Position = message->size; + + result = 0; + } + else + { + __translate_io_error_to_errno(IoErr(),&error); + } + } + else + { + /* No action */ + result = 0; + } + + PROFILE_ON(); + } + else + { + SHOWMSG("file is already closed"); + + error = EBADF; + } + + break; + + case file_hook_action_examine: + + SHOWMSG("file_hook_action_examine"); + + if(fd->fd_DefaultFile != ZERO) + { + struct FileHandle * fh; + + if(CANNOT safe_examine_file_handle(fd->fd_DefaultFile,message->file_info)) + { + SHOWMSG("couldn't examine the file"); + + __translate_io_error_to_errno(IoErr(),&error); + break; + } + + fh = BADDR(fd->fd_DefaultFile); + + message->file_system = fh->fh_Type; + + result = 0; + } + else + { + SHOWMSG("file is already closed"); + + error = EBADF; + } + + break; + + case file_hook_action_info: + + SHOWMSG("file_hook_action_info"); + + if(fd->fd_DefaultFile != ZERO) + { + BPTR parent_dir; + + PROFILE_OFF(); + + parent_dir = safe_parent_of_file_handle(fd->fd_DefaultFile); + if(parent_dir != ZERO) + { + if(Info(parent_dir,message->info_data)) + { + result = 0; + } + else + { + SHOWMSG("couldn't get info on drive"); + + __translate_io_error_to_errno(IoErr(),&error); + } + + UnLock(parent_dir); + } + else + { + SHOWMSG("couldn't find parent directory"); + + __translate_io_error_to_errno(IoErr(),&error); + } + + PROFILE_ON(); + } + else + { + SHOWMSG("file is already closed"); + + error = EBADF; + } + + break; + + case file_hook_action_change_attributes: + + SHOWMSG("file_hook_action_change_attributes"); + + if(fd->fd_DefaultFile != ZERO) + { + BPTR parent_dir; + + PROFILE_OFF(); + + parent_dir = safe_parent_of_file_handle(fd->fd_DefaultFile); + if(parent_dir != ZERO) + { + D_S(struct FileInfoBlock,fib); + + if(safe_examine_file_handle(fd->fd_DefaultFile,fib)) + { + BPTR old_current_dir; + + old_current_dir = CurrentDir(parent_dir); + + if(SetProtection(fib->fib_FileName,(LONG)message->attributes)) + { + result = 0; + } + else + { + SHOWMSG("couldn't change protection bits; oh well, it was worth the effort..."); + + __translate_io_error_to_errno(IoErr(),&error); + } + + CurrentDir(old_current_dir); + } + else + { + SHOWMSG("couldn't examine file"); + + __translate_io_error_to_errno(IoErr(),&error); + } + + UnLock(parent_dir); + } + else + { + SHOWMSG("couldn't get a lock on the parent directory"); + + __translate_io_error_to_errno(IoErr(),&error); + } + + PROFILE_ON(); + } + else + { + SHOWMSG("file is already closed"); + + error = EBADF; + } + + break; + + case file_hook_action_duplicate_fd: + + SHOWMSG("file_hook_action_duplicate_fd"); + + __duplicate_fd(message->duplicate_fd,fd); + + result = 0; + break; + + case file_hook_action_is_interactive: + + SHOWMSG("file_hook_action_is_interactive"); + + PROFILE_OFF(); + + if(fd->fd_DefaultFile != ZERO && ((struct FileHandle *)BADDR(fd->fd_DefaultFile))->fh_Type != NULL && IsInteractive(fd->fd_DefaultFile)) + result = 1; + else + result = 0; + + PROFILE_ON(); + + break; + + default: + + SHOWVALUE(message->action); + + error = EBADF; + break; + } + + if(buffer != NULL) + free(buffer); + + SHOWVALUE(result); + + message->result = result; + message->error = error; + + LEAVE(); +} diff --git a/library/stdio_feof.c b/library/stdio_feof.c new file mode 100644 index 0000000..cbb57d2 --- /dev/null +++ b/library/stdio_feof.c @@ -0,0 +1,87 @@ +/* + * $Id: stdio_feof.c,v 1.1.1.1 2004-07-26 16:31:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#undef feof + +/****************************************************************************/ + +int +feof(FILE *stream) +{ + struct iob * file = (struct iob *)stream; + int result; + + ENTER(); + + SHOWPOINTER(stream); + + assert( stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + SHOWMSG("invalid stream parameter"); + + errno = EFAULT; + result = 0; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(file) ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + + result = FLAG_IS_SET(file->iob_Flags,IOBF_EOF_REACHED); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_ferror.c b/library/stdio_ferror.c new file mode 100644 index 0000000..9a86d77 --- /dev/null +++ b/library/stdio_ferror.c @@ -0,0 +1,86 @@ +/* + * $Id: stdio_ferror.c,v 1.1.1.1 2004-07-26 16:31:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#undef ferror + +/****************************************************************************/ + +int +ferror(FILE *stream) +{ + struct iob * file = (struct iob *)stream; + int result; + + ENTER(); + + SHOWPOINTER(stream); + + assert( stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + SHOWMSG("invalid stream parameter"); + + errno = EFAULT; + result = 0; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(file) ); + + result = FLAG_IS_SET(file->iob_Flags,IOBF_ERROR); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_fflush.c b/library/stdio_fflush.c new file mode 100644 index 0000000..8fd0e3b --- /dev/null +++ b/library/stdio_fflush.c @@ -0,0 +1,119 @@ +/* + * $Id: stdio_fflush.c,v 1.1.1.1 2004-07-26 16:31:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +fflush(FILE *stream) +{ + int result = EOF; + + ENTER(); + + SHOWPOINTER(stream); + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + /* Flush a particular stream? */ + if(stream != NULL) + { + struct iob * file = (struct iob *)stream; + + assert( __is_valid_iob(file) ); + + if(__iob_write_buffer_is_valid(file) && __flush_iob_write_buffer(file) < 0) + goto out; + } + else + { + int i; + + /* Flush all streams which still have unwritten data in the buffer. */ + for(i = 0 ; i < __num_iob ; i++) + { + if(__iob[i] != NULL && + FLAG_IS_SET(__iob[i]->iob_Flags,IOBF_IN_USE) && + FLAG_IS_SET(__iob[i]->iob_Flags,IOBF_WRITE) && + __iob_write_buffer_is_valid(__iob[i])) + { + if(__flush_iob_write_buffer(__iob[i]) < 0) + goto out; + } + } + } + } + #else + { + struct iob * file = (struct iob *)stream; + + assert( stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + SHOWMSG("invalid file handle"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + assert( __is_valid_iob(file) ); + + if(__iob_write_buffer_is_valid(file) && __flush_iob_write_buffer(file) < 0) + goto out; + } + #endif /* UNIX_PATH_SEMANTICS */ + + result = OK; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_fgetc.c b/library/stdio_fgetc.c new file mode 100644 index 0000000..74b27cb --- /dev/null +++ b/library/stdio_fgetc.c @@ -0,0 +1,159 @@ +/* + * $Id: stdio_fgetc.c,v 1.1.1.1 2004-07-26 16:31:29 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +__fgetc(FILE *stream) +{ + struct iob * file = (struct iob *)stream; + int result = EOF; + + assert( stream != NULL ); + + assert( __is_valid_iob(file) ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + if(__iob_read_buffer_is_empty(file)) + { + if(__fill_iob_read_buffer(file) < 0) + goto out; + + if(__iob_read_buffer_is_empty(file)) + { + SET_FLAG(file->iob_Flags,IOBF_EOF_REACHED); + + goto out; + } + } + + result = file->iob_Buffer[file->iob_BufferPosition++]; + + out: + + return(result); +} + +/****************************************************************************/ + +int +__fgetc_check(FILE * stream) +{ + struct iob * file = (struct iob *)stream; + int result = EOF; + + assert( stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE)) + { + SHOWMSG("this file is not even in use"); + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + + errno = EBADF; + goto out; + } + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_READ)) + { + SET_FLAG(file->iob_Flags,IOBF_ERROR); + + errno = EBADF; + goto out; + } + + if(__iob_write_buffer_is_valid(file) && __flush_iob_write_buffer(file) < 0) + goto out; + + result = 0; + + out: + + return(result); +} + +/****************************************************************************/ + +int +fgetc(FILE *stream) +{ + int result = EOF; + + assert( stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__fgetc_check(stream) != OK) + goto out; + + result = __getc(stream); + + out: + + return(result); +} diff --git a/library/stdio_fgetpos.c b/library/stdio_fgetpos.c new file mode 100644 index 0000000..47ffa88 --- /dev/null +++ b/library/stdio_fgetpos.c @@ -0,0 +1,90 @@ +/* + * $Id: stdio_fgetpos.c,v 1.1.1.1 2004-07-26 16:31:29 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +fgetpos(FILE *stream, fpos_t *pos) +{ + int result = EOF; + long position; + + ENTER(); + + SHOWPOINTER(stream); + SHOWPOINTER(pos); + + assert( stream != NULL && pos != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL || pos == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + position = ftell(stream); + if(position == -1) + { + SHOWMSG("ftell() didn't work."); + + goto out; + } + + (*pos) = position; + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_fgets.c b/library/stdio_fgets.c new file mode 100644 index 0000000..51a94cb --- /dev/null +++ b/library/stdio_fgets.c @@ -0,0 +1,135 @@ +/* + * $Id: stdio_fgets.c,v 1.1.1.1 2004-07-26 16:31:29 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +char * +fgets(char *s,int n,FILE *stream) +{ + char * result = s; + int c; + + ENTER(); + + SHOWPOINTER(s); + SHOWVALUE(n); + SHOWPOINTER(stream); + + assert( s != NULL && stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s == NULL || stream == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + result = NULL; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + if(n <= 0) + { + SHOWMSG("no work to be done"); + + result = NULL; + goto out; + } + + /* Take care of the checks and data structure changes that + * need to be handled only once for this stream. + */ + if(__fgetc_check(stream) != OK) + { + result = NULL; + goto out; + } + + /* So that we can tell error and 'end of file' conditions apart. */ + clearerr(stream); + + /* One off for the terminating '\0'. */ + n--; + + while(n-- > 0) + { + c = __getc(stream); + if(c == EOF) + { + if(ferror(stream)) + { + /* Just to be on the safe side. */ + (*s) = '\0'; + + result = NULL; + goto out; + } + + /* Make sure that we return NULL if we really + didn't read anything at all */ + if(s == result) + result = NULL; + + break; + } + + (*s++) = c; + + if(c == '\n') + break; + } + + (*s) = '\0'; + + SHOWSTRING(result); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_filliobreadbuffer.c b/library/stdio_filliobreadbuffer.c new file mode 100644 index 0000000..61f636f --- /dev/null +++ b/library/stdio_filliobreadbuffer.c @@ -0,0 +1,133 @@ +/* + * $Id: stdio_filliobreadbuffer.c,v 1.1.1.1 2004-07-26 16:31:29 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +/* +int +__iob_read_buffer_is_empty(struct iob * file) +{ + int result; + + assert( file != NULL ); + + result = (file->iob_BufferReadBytes == 0 || file->iob_BufferPosition == file->iob_BufferReadBytes); + + return(result); +} +*/ + +/****************************************************************************/ + +int +__fill_iob_read_buffer(struct iob * file) +{ + DECLARE_UTILITYBASE(); + struct file_hook_message message; + int result = -1; + + ENTER(); + + SHOWPOINTER(file); + + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file != NULL && (file->iob_BufferReadBytes == 0 || file->iob_BufferPosition == file->iob_BufferReadBytes) && file->iob_BufferWriteBytes == 0 ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_READ) ); + assert( file->iob_BufferSize > 0 ); + assert( UtilityBase != NULL ); + + if(__check_abort_enabled) + __check_abort(); + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE)) /* ZZZ this does not really belong here; paranoia? */ + goto out; + + /* Flush all line buffered streams before we proceed to fill this buffer. */ + if((file->iob_Flags & IOBF_BUFFER_MODE) == IOBF_BUFFER_MODE_LINE) + { + int i; + + for(i = 0 ; i < __num_iob ; i++) + { + if(__iob[i] != NULL && + FLAG_IS_SET(__iob[i]->iob_Flags,IOBF_IN_USE) && + FLAG_IS_SET(__iob[i]->iob_Flags,IOBF_WRITE) && + (__iob[i]->iob_Flags & IOBF_BUFFER_MODE) == IOBF_BUFFER_MODE_LINE && + __iob_write_buffer_is_valid(__iob[i])) + { + if(__flush_iob_write_buffer(__iob[i]) < 0) + goto out; + } + } + } + + SHOWMSG("calling the hook"); + + SHOWPOINTER(file->iob_Buffer); + SHOWVALUE(file->iob_BufferSize); + + message.action = file_hook_action_read; + message.data = file->iob_Buffer; + message.size = file->iob_BufferSize; + message.result = 0; + + assert( file->iob_Hook != NULL ); + + CallHookPkt(file->iob_Hook,file,&message); + + if(message.result < 0) + { + errno = message.error; + + D(("got error %ld",errno)); + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + file->iob_BufferReadBytes = message.result; + file->iob_BufferPosition = 0; + + SHOWVALUE(file->iob_BufferReadBytes); + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_findvacantfdentry.c b/library/stdio_findvacantfdentry.c new file mode 100644 index 0000000..8489a4e --- /dev/null +++ b/library/stdio_findvacantfdentry.c @@ -0,0 +1,90 @@ +/* + * $Id: stdio_findvacantfdentry.c,v 1.1.1.1 2004-07-26 16:31:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#ifndef NDEBUG + +/****************************************************************************/ + +BOOL +__is_valid_fd(struct fd * fd) +{ + BOOL result = FALSE; + + if(__fd != NULL && __num_fd > 0) + { + int i; + + for(i = 0 ; i < __num_fd ; i++) + { + if(__fd[i] == fd) + { + result = TRUE; + break; + } + } + } + + return(result); +} + +/****************************************************************************/ + +#endif /* NDEBUG */ + +/****************************************************************************/ + +int +__find_vacant_fd_entry(void) +{ + int result = -1; + int i; + + assert( __fd != NULL || __num_fd == 0 ); + + for(i = 0 ; i < __num_fd ; i++) + { + if(FLAG_IS_CLEAR(__fd[i]->fd_Flags,FDF_IN_USE)) + { + result = i; + break; + } + } + + return(result); +} diff --git a/library/stdio_findvacantiobentry.c b/library/stdio_findvacantiobentry.c new file mode 100644 index 0000000..90b91ae --- /dev/null +++ b/library/stdio_findvacantiobentry.c @@ -0,0 +1,87 @@ +/* + * $Id: stdio_findvacantiobentry.c,v 1.1.1.1 2004-07-26 16:31:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#ifndef NDEBUG + +/****************************************************************************/ + +BOOL +__is_valid_iob(struct iob * iob) +{ + BOOL result = FALSE; + + if(iob != NULL && FLAG_IS_SET(iob->iob_Flags,IOBF_INTERNAL)) + { + /* This is used by vsprintf(), etc. */ + result = TRUE; + } + else + { + if(__iob != NULL && __num_iob > 0 && 0 <= iob->iob_SlotNumber && iob->iob_SlotNumber < __num_iob && __iob[iob->iob_SlotNumber] == iob) + result = TRUE; + } + + return(result); +} + +/****************************************************************************/ + +#endif /* NDEBUG */ + +/****************************************************************************/ + +int +__find_vacant_iob_entry(void) +{ + int result = -1; + int i; + + assert( __iob != NULL || __num_iob == 0 ); + + for(i = 0 ; i < __num_iob ; i++) + { + if(FLAG_IS_CLEAR(__iob[i]->iob_Flags,IOBF_IN_USE)) + { + result = i; + break; + } + } + + return(result); +} diff --git a/library/stdio_flush.c b/library/stdio_flush.c new file mode 100644 index 0000000..d5ea596 --- /dev/null +++ b/library/stdio_flush.c @@ -0,0 +1,100 @@ +/* + * $Id: stdio_flush.c,v 1.1.1.1 2004-07-26 16:31:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +/* This is roughly equivalent to fflush(), but returns the last character + written to the buffer, or EOF if flushing produced an error. The putc() + macro and the internal __putc() macro need this functionality. This + function is called only if the last character written to the buffer + was a line feed, prompting the buffer contents to be flushed. It should + never be used in place of fflush(). */ +int +__flush(FILE *stream) +{ + struct iob * iob = (struct iob *)stream; + int result = EOF; + int last_c; + + ENTER(); + + SHOWPOINTER(stream); + + assert( stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + SHOWMSG("invalid stream parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(iob) ); + assert( iob->iob_BufferWriteBytes > 0 ); + assert( iob->iob_BufferSize > 0 ); + + last_c = iob->iob_Buffer[iob->iob_BufferWriteBytes - 1]; + + if(__flush_iob_write_buffer(iob) < 0) + { + /* Remove the last character stored in the buffer, which is + typically a '\n'. */ + iob->iob_BufferWriteBytes--; + goto out; + } + + result = last_c; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_flushiobwritebuffer.c b/library/stdio_flushiobwritebuffer.c new file mode 100644 index 0000000..db285d6 --- /dev/null +++ b/library/stdio_flushiobwritebuffer.c @@ -0,0 +1,118 @@ +/* + * $Id: stdio_flushiobwritebuffer.c,v 1.1.1.1 2004-07-26 16:31:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* This would otherwise generate far too much (useless) debug output. */ +#ifdef DEBUG +#undef DEBUG +#endif /* DEBUG */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +/* +int +__iob_write_buffer_is_full(struct iob * file) +{ + int result; + + assert( file != NULL ); + + result = (file->iob_BufferSize > 0 && (ULONG)file->iob_BufferWriteBytes == file->iob_BufferSize); + + return(result); +} +*/ + +/****************************************************************************/ + +int +__flush_iob_write_buffer(struct iob * file) +{ + DECLARE_UTILITYBASE(); + int result = 0; + + ENTER(); + + SHOWPOINTER(file); + + assert( file != NULL ); + assert( UtilityBase != NULL ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + if(__check_abort_enabled) + __check_abort(); + + if(FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) && file->iob_BufferWriteBytes > 0) + { + struct file_hook_message message; + + assert( FLAG_IS_SET(file->iob_Flags,IOBF_WRITE) ); + assert( file->iob_BufferSize > 0 ); + + D(("%ld bytes are to be written",file->iob_BufferWriteBytes)); + + SHOWMSG("calling the hook"); + + message.action = file_hook_action_write; + message.data = file->iob_Buffer; + message.size = file->iob_BufferWriteBytes; + message.result = 0; + + assert( file->iob_Hook != NULL ); + + CallHookPkt(file->iob_Hook,file,&message); + + if(message.result != file->iob_BufferWriteBytes) + { + SHOWMSG("that didn't work"); + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + + result = -1; + errno = message.error; + + goto out; + } + + file->iob_BufferWriteBytes = 0; + } + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_fopen.c b/library/stdio_fopen.c new file mode 100644 index 0000000..0fd4848 --- /dev/null +++ b/library/stdio_fopen.c @@ -0,0 +1,99 @@ +/* + * $Id: stdio_fopen.c,v 1.1.1.1 2004-07-26 16:31:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +FILE * +fopen(const char *filename, const char *mode) +{ + FILE * result = NULL; + int slot_number; + + ENTER(); + + SHOWSTRING(filename); + SHOWSTRING(mode); + + assert( filename != NULL && mode != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(filename == NULL || mode == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + slot_number = __find_vacant_iob_entry(); + if(slot_number < 0) + { + if(__grow_iob_table() < 0) + { + SHOWMSG("couldn't find a free file table, and no memory for a new one"); + goto out; + } + + slot_number = __find_vacant_iob_entry(); + assert( slot_number >= 0 ); + } + + if(__open_iob(filename,mode,-1,slot_number) < 0) + { + SHOWMSG("couldn't open the file"); + goto out; + } + + result = (FILE *)__iob[slot_number]; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_fprintf.c b/library/stdio_fprintf.c new file mode 100644 index 0000000..dfa4199 --- /dev/null +++ b/library/stdio_fprintf.c @@ -0,0 +1,80 @@ +/* + * $Id: stdio_fprintf.c,v 1.1.1.1 2004-07-26 16:31:31 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +fprintf(FILE *stream,const char *format,...) +{ + int result = -1; + va_list arg; + + ENTER(); + + SHOWPOINTER(stream); + SHOWSTRING(format); + + assert( stream != NULL && format != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL || format == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + va_start(arg,format); + result = vfprintf(stream,format,arg); + va_end(arg); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_fputc.c b/library/stdio_fputc.c new file mode 100644 index 0000000..a7fc6de --- /dev/null +++ b/library/stdio_fputc.c @@ -0,0 +1,159 @@ +/* + * $Id: stdio_fputc.c,v 1.1.1.1 2004-07-26 16:31:31 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +__fputc_check(FILE *stream) +{ + struct iob * file = (struct iob *)stream; + int result = EOF; + + assert( stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(file) ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE)) + { + SHOWMSG("this file is not even in use"); + + errno = EBADF; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_WRITE)) + { + SHOWMSG("this stream is not write enabled"); + + errno = EBADF; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + if(__iob_read_buffer_is_valid(file) && __drop_iob_read_buffer(file) < 0) + { + SHOWMSG("couldn't get rid of the read buffer."); + goto out; + } + + result = OK; + + out: + + return(result); +} + +/****************************************************************************/ + +int +__fputc(int c,FILE *stream,int buffer_mode) +{ + struct iob * file = (struct iob *)stream; + int result = EOF; + + assert( stream != NULL ); + + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + if(__iob_write_buffer_is_full(file) && __flush_iob_write_buffer(file) < 0) + goto out; + + file->iob_Buffer[file->iob_BufferWriteBytes++] = c; + + if((buffer_mode == IOBF_BUFFER_MODE_NONE || (buffer_mode == IOBF_BUFFER_MODE_LINE && c == '\n')) && __flush_iob_write_buffer(file) < 0) + { + /* Pretend that the last character was not written. */ + file->iob_BufferWriteBytes--; + goto out; + } + + /* Clip everything but the least significant eight bits. This + also takes care of the sign. Thus, a -1 (== EOF) always comes + out as 255. */ + result = (c & 0xff); + + out: + + return(result); +} + +/****************************************************************************/ + +int +fputc(int c,FILE *stream) +{ + struct iob * file = (struct iob *)stream; + int result = EOF; + + assert( stream != NULL ); + + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + + if(__fputc_check(stream) != OK) + goto out; + + result = __fputc(c,stream,(file->iob_Flags & IOBF_BUFFER_MODE)); + + out: + + return(result); +} diff --git a/library/stdio_fputs.c b/library/stdio_fputs.c new file mode 100644 index 0000000..6ea40dc --- /dev/null +++ b/library/stdio_fputs.c @@ -0,0 +1,110 @@ +/* + * $Id: stdio_fputs.c,v 1.1.1.1 2004-07-26 16:31:31 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +fputs(const char *s, FILE *stream) +{ + struct iob * file = (struct iob *)stream; + int result = EOF; + int buffer_mode; + int c; + + ENTER(); + + SHOWSTRING(s); + SHOWPOINTER(stream); + + assert( s != NULL && stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s == NULL || stream == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(file) ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + buffer_mode = (file->iob_Flags & IOBF_BUFFER_MODE); + if(buffer_mode == IOBF_BUFFER_MODE_NONE) + buffer_mode = IOBF_BUFFER_MODE_LINE; + + if(__fputc_check(stream) != OK) + goto out; + + while((c = (*s++)) != '\0') + { + if(__putc(c,stream,buffer_mode) == EOF) + goto out; + } + + result = OK; + + out: + + /* Note: if buffering is disabled for this stream, then we still + may have buffered data around, queued to be printed right now. + This is intended to improve performance as it takes more effort + to write a single character to a file than to write a bunch. */ + if(result == OK && (file->iob_Flags & IOBF_BUFFER_MODE) == IOBF_BUFFER_MODE_NONE) + { + if(__iob_write_buffer_is_valid(file) && __flush_iob_write_buffer(file) < 0) + { + SHOWMSG("couldn't flush the write buffer"); + result = EOF; + } + } + + RETURN(result); + return(result); +} diff --git a/library/stdio_fread.c b/library/stdio_fread.c new file mode 100644 index 0000000..b80451b --- /dev/null +++ b/library/stdio_fread.c @@ -0,0 +1,144 @@ +/* + * $Id: stdio_fread.c,v 1.1.1.1 2004-07-26 16:31:32 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +size_t +fread(void *ptr,size_t element_size,size_t count,FILE *stream) +{ + struct iob * file = (struct iob *)stream; + size_t result = 0; + + ENTER(); + + SHOWPOINTER(ptr); + SHOWVALUE(element_size); + SHOWVALUE(count); + SHOWPOINTER(stream); + + assert( ptr != NULL && stream != NULL ); + assert( (int)element_size >= 0 && (int)count >= 0 ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(ptr == NULL || stream == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(file) ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE)) + { + SHOWMSG("this file is not even in use"); + + errno = EBADF; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_READ)) + { + SHOWMSG("this file is not read-enabled"); + + errno = EBADF; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + if(element_size > 0 && count > 0) + { + size_t total_bytes_read = 0; + size_t total_size; + unsigned char * data = ptr; + int c; + + if(__fgetc_check((FILE *)file) < 0) + goto out; + + total_size = element_size * count; + + SHOWVALUE(total_size); + + while(total_size-- > 0) + { + c = __getc(file); + if(c == EOF) + break; + + (*data++) = c; + + total_bytes_read++; + } + + SHOWVALUE(total_bytes_read); + + result = total_bytes_read / element_size; + } + else + { + SHOWVALUE(element_size); + SHOWVALUE(count); + + SHOWMSG("either element size or count is zero"); + } + + D(("total number of elements read = %ld",result)); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_freopen.c b/library/stdio_freopen.c new file mode 100644 index 0000000..23828d5 --- /dev/null +++ b/library/stdio_freopen.c @@ -0,0 +1,98 @@ +/* + * $Id: stdio_freopen.c,v 1.1.1.1 2004-07-26 16:31:32 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +FILE * +freopen(const char *filename, const char *mode, FILE *stream) +{ + struct iob * file = (struct iob *)stream; + FILE * result = NULL; + int slot_number; + + ENTER(); + + SHOWSTRING(filename); + SHOWSTRING(mode); + SHOWPOINTER(stream); + + assert( filename != NULL && mode != NULL && stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(filename == NULL || mode == NULL || stream == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(file) ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + /* We need to remember this; it'll go away when we close + the file. */ + slot_number = file->iob_SlotNumber; + + fclose(stream); + + if(__open_iob(filename, mode, -1, slot_number) < 0) + { + SHOWMSG("couldn't reopen the file"); + goto out; + } + + result = (FILE *)file; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_fscanf.c b/library/stdio_fscanf.c new file mode 100644 index 0000000..cfbebd5 --- /dev/null +++ b/library/stdio_fscanf.c @@ -0,0 +1,82 @@ +/* + * $Id: stdio_fscanf.c,v 1.1.1.1 2004-07-26 16:31:32 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +fscanf(FILE *stream, const char *format, ...) +{ + int result = EOF; + va_list arg; + + ENTER(); + + SHOWPOINTER(stream); + SHOWSTRING(format); + + assert(stream != NULL && format != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL || format == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + va_start(arg,format); + result = __vfscanf(stream,format,arg); + va_end(arg); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_fseek.c b/library/stdio_fseek.c new file mode 100644 index 0000000..adf34c1 --- /dev/null +++ b/library/stdio_fseek.c @@ -0,0 +1,195 @@ +/* + * $Id: stdio_fseek.c,v 1.1.1.1 2004-07-26 16:31:33 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +fseek(FILE *stream, long int offset, int wherefrom) +{ + DECLARE_UTILITYBASE(); + struct iob * file = (struct iob *)stream; + int result = -1; + + ENTER(); + + SHOWPOINTER(stream); + SHOWVALUE(offset); + SHOWVALUE(wherefrom); + + assert(stream != NULL); + assert( UtilityBase != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + SHOWMSG("invalid stream parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(file) ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE)) + { + SHOWMSG("this file is not even in use"); + + errno = EBADF; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + if(wherefrom < SEEK_SET || wherefrom > SEEK_END) + { + SHOWMSG("invalid wherefrom parameter"); + + errno = EBADF; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + /* Try to turn the absolute position into a relative seek + * within the buffer, if possible. + */ + if(wherefrom == SEEK_SET && __iob_read_buffer_is_valid(file)) + { + long int current_position; + + current_position = ftell(stream); + if(current_position >= 0) + { + offset -= current_position; + + wherefrom = SEEK_CUR; + } + } + + /* We have to clear the EOF condition */ + CLEAR_FLAG(file->iob_Flags,IOBF_EOF_REACHED); + + if(wherefrom != SEEK_CUR || offset != 0) + { + BOOL buffer_position_adjusted = FALSE; + + /* Try to adjust the buffer position rather than adjusting + * the file position itself, which is very costly. + */ + if(wherefrom == SEEK_CUR && __iob_read_buffer_is_valid(file)) + { + /* Try to adjust the buffer read position. This also + * affects the number of bytes that can still be read. + */ + if ((offset < 0 && (-offset) <= file->iob_BufferPosition) || + (offset > 0 && offset <= __iob_num_unread_bytes(file))) + { + file->iob_BufferPosition += offset; + + buffer_position_adjusted = TRUE; + } + } + + if(NOT buffer_position_adjusted) + { + struct file_hook_message message; + + /* Oh dear, no luck. So we have to get rid of the + * current buffer contents and start with a clean + * slate. + */ + if(__iob_write_buffer_is_valid(file) && __flush_iob_write_buffer(file) < 0) + { + SHOWMSG("couldn't flush write buffer"); + + goto out; + } + + if(__iob_read_buffer_is_valid(file) && __drop_iob_read_buffer(file) < 0) + { + SHOWMSG("couldn't drop read buffer"); + + goto out; + } + + SHOWMSG("calling the hook"); + + SHOWPOINTER(&message); + + message.action = file_hook_action_seek; + message.position = offset; + message.mode = wherefrom; + message.result = 0; + + SHOWVALUE(message.position); + SHOWVALUE(message.mode); + + assert( file->iob_Hook != NULL ); + + CallHookPkt(file->iob_Hook,file,&message); + + if(message.result < 0) + { + errno = message.error; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + } + } + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_fsetpos.c b/library/stdio_fsetpos.c new file mode 100644 index 0000000..a25ad12 --- /dev/null +++ b/library/stdio_fsetpos.c @@ -0,0 +1,85 @@ +/* + * $Id: stdio_fsetpos.c,v 1.1.1.1 2004-07-26 16:31:33 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +fsetpos(FILE *stream, fpos_t *pos) +{ + int result = EOF; + + ENTER(); + + SHOWPOINTER(stream); + SHOWPOINTER(pos); + + assert( stream != NULL && pos != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL || pos == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + if(fseek(stream,(long int)(*pos),SEEK_SET) != 0) + { + SHOWMSG("fseek failed"); + goto out; + } + + result = OK; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_ftell.c b/library/stdio_ftell.c new file mode 100644 index 0000000..fc16075 --- /dev/null +++ b/library/stdio_ftell.c @@ -0,0 +1,128 @@ +/* + * $Id: stdio_ftell.c,v 1.1.1.1 2004-07-26 16:31:33 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +long int +ftell(FILE *stream) +{ + DECLARE_UTILITYBASE(); + struct iob * file = (struct iob *)stream; + struct file_hook_message message; + long result = -1; + + assert( stream != NULL ); + assert( UtilityBase != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(file) ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE)) + { + SHOWMSG("this file is not even in use"); + + errno = EBADF; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + SHOWMSG("calling the hook"); + + SHOWPOINTER(&message); + + message.action = file_hook_action_seek; + message.position = 0; + message.mode = SEEK_CUR; + message.result = 0; + + SHOWVALUE(message.position); + SHOWVALUE(message.mode); + + assert( file->iob_Hook != NULL ); + + CallHookPkt(file->iob_Hook,file,&message); + + result = message.result; + if(result < 0) + { + errno = message.error; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + + goto out; + } + + if(__iob_read_buffer_is_valid(file)) + { + /* Subtract the number of bytes still in the buffer which have + * not been read before. + */ + result -= __iob_num_unread_bytes(file); + } + else if (__iob_write_buffer_is_valid(file)) + { + /* Add the number of bytes still stored in the buffer which have + * not been written to disk yet. + */ + result += __iob_num_unwritten_bytes(file); + } + + out: + + return(result); +} diff --git a/library/stdio_fwrite.c b/library/stdio_fwrite.c new file mode 100644 index 0000000..6addfa6 --- /dev/null +++ b/library/stdio_fwrite.c @@ -0,0 +1,156 @@ +/* + * $Id: stdio_fwrite.c,v 1.1.1.1 2004-07-26 16:31:33 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +size_t +fwrite(const void *ptr,size_t element_size,size_t count,FILE *stream) +{ + struct iob * file = (struct iob *)stream; + size_t result = 0; + + ENTER(); + + SHOWPOINTER(ptr); + SHOWVALUE(element_size); + SHOWVALUE(count); + SHOWPOINTER(stream); + + assert( ptr != NULL && stream != NULL ); + assert( (int)element_size >= 0 && (int)count >= 0 ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(ptr == NULL || stream == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(file) ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE)) + { + SHOWMSG("this file is not even in use"); + + errno = EBADF; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_WRITE)) + { + SHOWMSG("this stream is not write-enabled"); + + errno = EBADF; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + if(element_size > 0 && count > 0) + { + unsigned char * data = (unsigned char *)ptr; + unsigned char c; + int buffer_mode; + size_t total_bytes_written = 0; + size_t total_size; + + total_size = element_size * count; + + if(__fputc_check((FILE *)file) < 0) + goto out; + + buffer_mode = (file->iob_Flags & IOBF_BUFFER_MODE); + if(buffer_mode == IOBF_BUFFER_MODE_NONE) + buffer_mode = IOBF_BUFFER_MODE_LINE; + + if(buffer_mode == IOBF_BUFFER_MODE_LINE) + { + while(total_size-- > 0) + { + c = (*data++); + + if(__putc_line_buffered(c,(FILE *)file) < 0) + goto out; + + total_bytes_written++; + } + + if((file->iob_Flags & IOBF_BUFFER_MODE) == IOBF_BUFFER_MODE_NONE) + { + if(__iob_write_buffer_is_valid(file) && __flush_iob_write_buffer(file) < 0) + goto out; + } + } + else + { + while(total_size-- > 0) + { + c = (*data++); + + if(__putc_fully_buffered(c,(FILE *)file) < 0) + goto out; + + total_bytes_written++; + } + } + + result = total_bytes_written / element_size; + } + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_get_file_descriptor.c b/library/stdio_get_file_descriptor.c new file mode 100644 index 0000000..a3f3fa6 --- /dev/null +++ b/library/stdio_get_file_descriptor.c @@ -0,0 +1,70 @@ +/* + * $Id: stdio_get_file_descriptor.c,v 1.1.1.1 2004-07-26 16:31:33 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +struct fd * +__get_file_descriptor(int file_descriptor) +{ + struct fd * result = NULL; + struct fd * fd; + + if(file_descriptor < 0 || file_descriptor >= __num_fd) + { + SHOWMSG("invalid file descriptor"); + goto out; + } + + fd = __fd[file_descriptor]; + if(fd == NULL) + { + SHOWMSG("invalid file descriptor"); + goto out; + } + + if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_IN_USE)) + { + SHOWMSG("this descriptor is not even in use"); + goto out; + } + + result = fd; + + out: + + return(result); +} diff --git a/library/stdio_getc.c b/library/stdio_getc.c new file mode 100644 index 0000000..fb67155 --- /dev/null +++ b/library/stdio_getc.c @@ -0,0 +1,72 @@ +/* + * $Id: stdio_getc.c,v 1.1.1.1 2004-07-26 16:31:33 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#undef getc + +/****************************************************************************/ + +int +getc(FILE *stream) +{ + int result = -1; + + assert( stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + result = fgetc(stream); + + out: + + return(result); +} diff --git a/library/stdio_getchar.c b/library/stdio_getchar.c new file mode 100644 index 0000000..ad544cd --- /dev/null +++ b/library/stdio_getchar.c @@ -0,0 +1,52 @@ +/* + * $Id: stdio_getchar.c,v 1.1.1.1 2004-07-26 16:31:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#undef getchar + +/****************************************************************************/ + +int +getchar(void) +{ + int result; + + result = fgetc(stdin); + + return(result); +} diff --git a/library/stdio_gets.c b/library/stdio_gets.c new file mode 100644 index 0000000..47f69b5 --- /dev/null +++ b/library/stdio_gets.c @@ -0,0 +1,122 @@ +/* + * $Id: stdio_gets.c,v 1.1.1.1 2004-07-26 16:31:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +char * +gets(char *s) +{ + char * result = s; + int c; + + ENTER(); + + SHOWPOINTER(s); + + assert( s != NULL && stdin != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s == NULL || stdin == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + result = NULL; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + /* Take care of the checks and data structure changes that + * need to be handled only once for this stream. + */ + if(__fgetc_check(stdin) != OK) + { + result = NULL; + goto out; + } + + /* So that we can tell error and 'end of file' conditions apart. */ + clearerr(stdin); + + while(TRUE) + { + c = __getc(stdin); + if(c == EOF) + { + if(ferror(stdin)) + { + /* Just to be on the safe side. */ + (*s) = '\0'; + + result = NULL; + goto out; + } + + /* Make sure that we return NULL if we really + didn't read anything at all */ + if(s == result) + result = NULL; + + break; + } + + if(c == '\n') + break; + + (*s++) = c; + } + + (*s) = '\0'; + + SHOWSTRING(result); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_growfdtable.c b/library/stdio_growfdtable.c new file mode 100644 index 0000000..cb534ee --- /dev/null +++ b/library/stdio_growfdtable.c @@ -0,0 +1,100 @@ +/* + * $Id: stdio_growfdtable.c,v 1.1.1.1 2004-07-26 16:31:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +__grow_fd_table(void) +{ + const int granularity = 10; + struct fd ** new_fd; + int new_num_fd; + int result = -1; + int i; + + new_num_fd = __num_fd + granularity; + + new_fd = malloc(sizeof(*new_fd) * new_num_fd); + if(new_fd == NULL) + { + SHOWMSG("not enough memory for new file descriptor table"); + + errno = ENOMEM; + goto out; + } + + for(i = __num_fd ; i < new_num_fd ; i++) + { + new_fd[i] = malloc(sizeof(*new_fd[i])); + if(new_fd[i] == NULL) + { + int j; + + SHOWMSG("not enough memory for new file descriptor table entry"); + + for(j = __num_fd ; j < i ; j++) + free(new_fd[j]); + + free(new_fd); + + errno = ENOMEM; + goto out; + } + + memset(new_fd[i],0,sizeof(*new_fd[i])); + } + + for(i = 0 ; i < __num_fd ; i++) + new_fd[i] = __fd[i]; + + free(__fd); + + __fd = new_fd; + __num_fd = new_num_fd; + + result = 0; + + out: + + return(result); +} diff --git a/library/stdio_growiobtable.c b/library/stdio_growiobtable.c new file mode 100644 index 0000000..67cf721 --- /dev/null +++ b/library/stdio_growiobtable.c @@ -0,0 +1,100 @@ +/* + * $Id: stdio_growiobtable.c,v 1.1.1.1 2004-07-26 16:31:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +__grow_iob_table(void) +{ + const int granularity = 10; + struct iob ** new_iob; + int new_num_iob; + int result = -1; + int i; + + new_num_iob = __num_iob + granularity; + + new_iob = malloc(sizeof(*new_iob) * new_num_iob); + if(new_iob == NULL) + { + SHOWMSG("not enough memory for file table"); + + errno = ENOMEM; + goto out; + } + + for(i = __num_iob ; i < new_num_iob ; i++) + { + new_iob[i] = malloc(sizeof(*new_iob[i])); + if(new_iob[i] == NULL) + { + int j; + + SHOWMSG("not enough memory for file table entry"); + + for(j = __num_iob ; j < i ; j++) + free(new_iob[j]); + + free(new_iob); + + errno = ENOMEM; + goto out; + } + + memset(new_iob[i],0,sizeof(*new_iob[i])); + } + + for(i = 0 ; i < __num_iob ; i++) + new_iob[i] = __iob[i]; + + free(__iob); + + __iob = new_iob; + __num_iob = new_num_iob; + + result = 0; + + out: + + return(result); +} diff --git a/library/stdio_headers.h b/library/stdio_headers.h new file mode 100644 index 0000000..8b90ee0 --- /dev/null +++ b/library/stdio_headers.h @@ -0,0 +1,415 @@ +/* + * $Id: stdio_headers.h,v 1.1.1.1 2004-07-26 16:31:35 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#define _STDIO_HEADERS_H + +/****************************************************************************/ + +#include +#include + +#include + +#include +#include +#include +#include + +#include + +#include + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ +#include +#include +#include +#include +#include +#include + +/****************************************************************************/ + +#ifndef _STDLIB_LOCALE_UTILITY_H +#include "stdlib_locale_utility.h" +#endif /* _STDLIB_LOCALE_UTILITY_H */ + +/****************************************************************************/ + +#ifndef _MATH_FP_SUPPORT_H +#include "math_fp_support.h" +#endif /* _MATH_FP_SUPPORT_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) +#include +#endif /* FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#include "macros.h" +#include "debug.h" + +/****************************************************************************/ + +/* The directory entry type a socket is identified with (in a FileInfoBlock). */ +#define ST_SOCKET (31082002) + +/****************************************************************************/ + +/* The three file buffering modes supported. */ +#define IOBF_BUFFER_MODE_FULL _IOFBF /* Buffer is flushed when it fills up */ +#define IOBF_BUFFER_MODE_LINE _IOLBF /* Buffer is flushed when it fills up + or when a line end character is sent + to it */ +#define IOBF_BUFFER_MODE_NONE _IONBF /* The buffer is never used */ + +/****************************************************************************/ + +/* CAREFUL: these mask/flag definitions must match the public definitions + in or there will be trouble! */ + +#define IOBF_BUFFER_MODE 3 /* This is actually a mask which covers + the first two bits, both of which + contain the buffering mode to use. */ +#define IOBF_EOF_REACHED (1<<2) /* If this flag is set, then the end of + the file was reached while reading + from it. */ +#define IOBF_READ (1<<3) /* If this flag is set then data can + be read from this file. */ +#define IOBF_WRITE (1<<4) /* If this flag is set then data can be + written to this file. */ +#define IOBF_IN_USE (1<<5) /* If this flag is set then this file + is not available for allocation */ +#define IOBF_ERROR (1<<6) /* An error was generated by an I/O + operation. */ +#define IOBF_TEMP (1<<7) /* If this flag is set then the file will + be deleted after it has been closed */ +#define IOBF_NO_NUL (1<<8) /* Don't NUL-terminate strings written to + this stream. */ +#define IOBF_INTERNAL (1<<9) /* Not a regular file, but a buffered + file handle made up on the spot in + vsprintf(), etc. */ + +/****************************************************************************/ + +/* Each file handle is represented by the following structure. Note that this + must match the layout of the public 'FILE' structure in or + things will take a turn for the worse! */ +struct iob +{ + ULONG iob_Flags; /* Properties and options + associated with this file */ + + UBYTE * iob_Buffer; /* Points to the file buffer */ + LONG iob_BufferSize; /* Size of the buffer in bytes */ + LONG iob_BufferPosition; /* Current read position + in the buffer (grows when any + data is read from the buffer) */ + LONG iob_BufferReadBytes; /* Number of bytes available for + reading (shrinks when any data + is read from the buffer) */ + LONG iob_BufferWriteBytes; /* Number of bytes written to the + buffer which still need to be + flushed to disk (grows when any + data is written to the buffer) */ + + /************************************************************************/ + /* Public portion ends here */ + /************************************************************************/ + + struct Hook * iob_Hook; /* The hook to invoke for file + operations, such as read, + write and seek. */ + + int iob_SlotNumber; /* Points back to the iob table + entry number. */ + + int iob_Descriptor; /* Associated file descriptor */ + + STRPTR iob_String; /* Alternative source of data; + a pointer to a string */ + LONG iob_StringSize; /* Number of bytes that may be + stored in the string */ + LONG iob_StringPosition; /* Current read/write position + in the string */ + LONG iob_StringLength; /* Number of characters stored + in the string */ + + char * iob_File; /* For access tracking with the + memory allocator. */ + int iob_Line; + + struct Hook iob_DefaultHook; /* Static hook */ + + APTR iob_CustomBuffer; /* A custom buffer allocated + by setvbuf() */ + + char * iob_TempFileName; /* If this is a temporary + file, this is its name */ + BPTR iob_TempFileLock; /* The directory in which this + temporary file is stored */ + + UBYTE iob_SingleByte; /* Fall-back buffer for 'unbuffered' + files */ +}; + +/****************************************************************************/ + +#define __getc(f) \ + ((((struct iob *)(f))->iob_BufferPosition < ((struct iob *)(f))->iob_BufferReadBytes) ? \ + ((struct iob *)(f))->iob_Buffer[((struct iob *)(f))->iob_BufferPosition++] : \ + __fgetc((FILE *)(f))) + +#define __putc(c,f,m) \ + (((((struct iob *)(f))->iob_BufferWriteBytes < ((struct iob *)(f))->iob_BufferSize)) ? \ + (((struct iob *)(f))->iob_Buffer[((struct iob *)(f))->iob_BufferWriteBytes++] = (c), \ + (((m) == IOBF_BUFFER_MODE_LINE && \ + ((struct iob *)(f))->iob_Buffer[((struct iob *)(f))->iob_BufferWriteBytes-1] == '\n') ? \ + __flush(f) : \ + (((struct iob *)(f))->iob_Buffer[((struct iob *)(f))->iob_BufferWriteBytes-1]))) : \ + __fputc((c),(f),(m))) + +#define __putc_fully_buffered(c,f) \ + (((((struct iob *)(f))->iob_BufferWriteBytes < ((struct iob *)(f))->iob_BufferSize)) ? \ + (((struct iob *)(f))->iob_Buffer[((struct iob *)(f))->iob_BufferWriteBytes++] = (c)) : \ + __fputc((c),(f),IOBF_BUFFER_MODE_FULL)) + +#define __putc_line_buffered(c,f) \ + (((((struct iob *)(f))->iob_BufferWriteBytes < ((struct iob *)(f))->iob_BufferSize)) ? \ + (((struct iob *)(f))->iob_Buffer[((struct iob *)(f))->iob_BufferWriteBytes++] = (c), \ + (((c) == '\n') ? \ + __flush(f) : \ + ((c)))) : \ + __fputc((c),(f),IOBF_BUFFER_MODE_LINE)) + +/****************************************************************************/ + +#define FDF_READ (1UL<<0) /* Data can be read from this file */ +#define FDF_WRITE (1UL<<1) /* Data can be written to this file */ +#define FDF_APPEND (1UL<<2) /* Before any data is written to it, + the file position must be set to the + end of the file */ +#define FDF_NO_CLOSE (1UL<<3) /* Never close this file */ +#define FDF_NON_BLOCKING (1UL<<4) /* File was switched into non-blocking + mode (console streams only) */ +#define FDF_IS_SOCKET (1UL<<5) /* This is not a disk file but a socket */ +#define FDF_IS_LOCKED (1UL<<6) /* This file has an advisory record lock set */ +#define FDF_IN_USE (1UL<<7) /* This file is in use */ +#define FDF_CREATED (1UL<<8) /* This file was newly created and may need + to have its protection bits updated after + it has been closed */ +#define FDF_CACHE_POSITION (1UL<<9) /* Cache the file position. */ + +/****************************************************************************/ + +struct fd +{ + struct Hook * fd_Hook; /* Hook to invoke to perform actions */ + ULONG fd_Flags; /* File properties */ + struct fd * fd_Original; /* NULL if this is not a dup()ed file + descriptor; points to original + descriptor if non-NULL */ + struct fd * fd_NextLink; /* Points to next duplicate of this + file descriptor; NULL for none */ + struct Hook fd_DefaultHook; /* Static hook */ + BPTR fd_DefaultFile; /* A dos.library file handle */ + LONG fd_Position; /* Cached file position (seek offset). */ +}; + +/****************************************************************************/ + +/* Files and directories to be unlinked when the program exits. */ +struct UnlinkNode +{ + struct MinNode uln_MinNode; + + BPTR uln_Lock; /* Lock on the directory to which the + name is relative */ + STRPTR uln_Name; /* The name of the file to remove */ +}; + +/****************************************************************************/ + +struct bcpl_name +{ + unsigned char name[256]; +}; + +/****************************************************************************/ + +/* Actions that can be performed by the file handle hook. */ +enum file_hook_action_t +{ + file_hook_action_read, + file_hook_action_write, + file_hook_action_seek, + file_hook_action_close, + file_hook_action_lock_record, + file_hook_action_set_blocking, + file_hook_action_change_owner, + file_hook_action_truncate, + file_hook_action_examine, + file_hook_action_change_attributes, + file_hook_action_info, + file_hook_action_duplicate_fd, + file_hook_action_seek_and_extend, + file_hook_action_is_interactive +}; + +/****************************************************************************/ + +/* A message sent to a file handle hook. */ +struct file_hook_message +{ + enum file_hook_action_t action; /* What to do */ + char * data; /* Where to read/write the data */ + long size; /* How much data to write */ + + long position; /* The seek position */ + long mode; /* The seek mode */ + + struct flock * lock; /* Record locking request */ + int command; /* What kind of locking command was sent */ + + int block; /* Whether or not this file should + be set non-blocking */ + + uid_t owner; + gid_t group; + + struct FileInfoBlock * file_info; + struct MsgPort * file_system; + + struct InfoData * info_data; + + struct fd * duplicate_fd; + + ULONG attributes; + + int error; /* Error code, if any... */ + + long result; /* Whatever this produced */ +}; + +/****************************************************************************/ + +/* The file handle table. */ +extern struct iob ** __iob; +extern int __num_iob; + +/****************************************************************************/ + +/* The file descriptor table. */ +extern struct fd ** __fd; +extern int __num_fd; + +/****************************************************************************/ + +extern char * __file_lock_semaphore_name; + +/****************************************************************************/ + +extern BOOL __no_standard_io; + +/****************************************************************************/ + +/*extern int __iob_write_buffer_is_full(struct iob * file);*/ + +#define __iob_write_buffer_is_full(file) \ + (((struct iob *)file)->iob_BufferSize > 0 && \ + ((struct iob *)file)->iob_BufferWriteBytes == ((struct iob *)file)->iob_BufferSize) + +/****************************************************************************/ + +#define __iob_write_buffer_is_valid(file) \ + (((struct iob *)file)->iob_BufferWriteBytes > 0) + +/****************************************************************************/ + +#define __iob_num_unwritten_bytes(file) \ + (((struct iob *)file)->iob_BufferWriteBytes) + +/****************************************************************************/ + +/*extern int __iob_read_buffer_is_empty(struct iob * file);*/ + +#define __iob_read_buffer_is_empty(file) \ + (((struct iob *)file)->iob_BufferReadBytes == 0 || \ + ((struct iob *)file)->iob_BufferPosition == ((struct iob *)file)->iob_BufferReadBytes) + +/****************************************************************************/ + +#define __iob_num_unread_bytes(file) \ + ((((struct iob *)file)->iob_BufferReadBytes > 0 && \ + ((struct iob *)file)->iob_BufferPosition < ((struct iob *)file)->iob_BufferReadBytes) \ + ? (((struct iob *)file)->iob_BufferReadBytes - ((struct iob *)file)->iob_BufferPosition) \ + : 0) + +/****************************************************************************/ + +#define __iob_read_buffer_is_valid(file) \ + (((struct iob *)file)->iob_BufferReadBytes > 0) + +/****************************************************************************/ + +#ifndef _STDIO_PROTOS_H +#include "stdio_protos.h" +#endif /* _STDIO_PROTOS_H */ + +/****************************************************************************/ + +#endif /* _STDIO_HEADERS_H */ diff --git a/library/stdio_init_exit.c b/library/stdio_init_exit.c new file mode 100644 index 0000000..cb90b13 --- /dev/null +++ b/library/stdio_init_exit.c @@ -0,0 +1,241 @@ +/* + * $Id: stdio_init_exit.c,v 1.1.1.1 2004-07-26 16:31:36 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +#include "stdlib_protos.h" + +/****************************************************************************/ + +void +__stdio_exit(void) +{ + int i; + + ENTER(); + + __check_abort_enabled = FALSE; + + if(__iob != NULL) + { + for(i = 0 ; i < __num_iob ; i++) + { + if(FLAG_IS_SET(__iob[i]->iob_Flags,IOBF_IN_USE)) + fclose((FILE *)__iob[i]); + } + + __num_iob = 0; + __iob = NULL; + } + + if(__fd != NULL) + { + for(i = 0 ; i < __num_fd ; i++) + { + if(FLAG_IS_SET(__fd[i]->fd_Flags,FDF_IN_USE)) + close(i); + } + + __num_fd = 0; + __fd = NULL; + } + + LEAVE(); +} + +/****************************************************************************/ + +int +__stdio_init(void) +{ + const int num_standard_files = 3; + BPTR default_file; + ULONG fd_flags,iob_flags; + int result = ERROR; + char * buffer; + char * aligned_buffer; + int i; + + ENTER(); + + __iob = malloc(sizeof(*__iob) * num_standard_files); + if(__iob == NULL) + goto out; + + for(i = 0 ; i < num_standard_files ; i++) + { + __iob[i] = malloc(sizeof(*__iob[i])); + if(__iob[i] == NULL) + goto out; + + memset(__iob[i],0,sizeof(*__iob[i])); + } + + __num_iob = num_standard_files; + + __fd = malloc(sizeof(*__fd) * num_standard_files); + if(__fd == NULL) + goto out; + + for(i = 0 ; i < num_standard_files ; i++) + { + __fd[i] = malloc(sizeof(*__fd[i])); + if(__fd[i] == NULL) + goto out; + + memset(__fd[i],0,sizeof(*__fd[i])); + } + + __num_fd = num_standard_files; + + /* Now initialize the standard I/O streams (input, output, error). */ + for(i = STDIN_FILENO ; i <= STDERR_FILENO ; i++) + { + PROFILE_OFF(); + + switch(i) + { + case STDIN_FILENO: + + iob_flags = IOBF_IN_USE | IOBF_READ | IOBF_NO_NUL | IOBF_BUFFER_MODE_LINE; + fd_flags = FDF_IN_USE | FDF_READ | FDF_NO_CLOSE; + default_file = Input(); + break; + + case STDOUT_FILENO: + + iob_flags = IOBF_IN_USE | IOBF_WRITE | IOBF_NO_NUL | IOBF_BUFFER_MODE_LINE; + fd_flags = FDF_IN_USE | FDF_WRITE | FDF_NO_CLOSE; + default_file = Output(); + break; + + case STDERR_FILENO: + default: + + iob_flags = IOBF_IN_USE | IOBF_WRITE | IOBF_NO_NUL | IOBF_BUFFER_MODE_NONE; + fd_flags = FDF_IN_USE | FDF_WRITE; + default_file = ZERO; + break; + } + + PROFILE_ON(); + + /* Allocate a little more memory than necessary. */ + buffer = malloc(BUFSIZ + 15); + if(buffer == NULL) + goto out; + + /* Align the buffer start address to a cache line boundary. */ + aligned_buffer = (char *)((ULONG)(buffer + 15) & ~15UL); + + __initialize_fd(__fd[i],(HOOKFUNC)__fd_hook_entry,default_file,fd_flags); + + __initialize_iob(__iob[i],(HOOKFUNC)__iob_hook_entry, + buffer, + aligned_buffer,BUFSIZ, + i, + i, + iob_flags); + } + + /* If the program was launched from Workbench, we continue by + * duplicating the default output stream for use as the + * standard error stream. + */ + if(__WBenchMsg != NULL) + { + PROFILE_OFF(); + __fd[STDERR_FILENO]->fd_DefaultFile = Output(); + PROFILE_ON(); + + SET_FLAG(__fd[STDERR_FILENO]->fd_Flags,FDF_NO_CLOSE); + } + else + { + struct Process * this_process = (struct Process *)FindTask(NULL); + + /* Is the standard error stream configured? If so, use it. + * Otherwise, try to duplicate the standard output stream. + */ + if(this_process->pr_CES != ZERO) + { + __fd[STDERR_FILENO]->fd_DefaultFile = this_process->pr_CES; + + SET_FLAG(__fd[STDERR_FILENO]->fd_Flags,FDF_NO_CLOSE); + } + else if (__fd[STDOUT_FILENO]->fd_DefaultFile != ZERO) + { + struct FileHandle * fh = (struct FileHandle *)BADDR(__fd[STDOUT_FILENO]->fd_DefaultFile); + + /* Careful, this could be "NIL:". */ + if(fh->fh_Type != NULL) + __fd[STDERR_FILENO]->fd_DefaultFile = Open("CONSOLE:",MODE_NEWFILE); + } + } + + PROFILE_OFF(); + + /* Check if the standard error output refers to a console or must + * be considered unusable for console output. + */ + if(__fd[STDERR_FILENO]->fd_DefaultFile == ZERO || + ((struct FileHandle *)BADDR(__fd[STDERR_FILENO]->fd_DefaultFile))->fh_Type == NULL || + NOT IsInteractive(__fd[STDERR_FILENO]->fd_DefaultFile)) + { + /* The standard I/O streams are no longer attached to a console. */ + __no_standard_io = TRUE; + } + + PROFILE_ON(); + + result = OK; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_initializefd.c b/library/stdio_initializefd.c new file mode 100644 index 0000000..49fec9b --- /dev/null +++ b/library/stdio_initializefd.c @@ -0,0 +1,65 @@ +/* + * $Id: stdio_initializefd.c,v 1.1.1.1 2004-07-26 16:31:36 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +void +__initialize_fd( + struct fd * fd, + HOOKFUNC hook_function, + BPTR default_file, + ULONG flags) +{ + assert( fd != NULL && hook_function != NULL ); + + memset(fd,0,sizeof(*fd)); + + fd->fd_DefaultFile = default_file; + fd->fd_Flags = flags; + fd->fd_Hook = &fd->fd_DefaultHook; + + #if defined(__amigaos4__) + { + fd->fd_Hook->h_Entry = (HOOKFUNC)hook_function; + } + #else + { + fd->fd_Hook->h_Entry = (HOOKFUNC)HookEntry; + fd->fd_Hook->h_SubEntry = (HOOKFUNC)hook_function; + } + #endif /* __amigaos4__ */ +} diff --git a/library/stdio_initializeiob.c b/library/stdio_initializeiob.c new file mode 100644 index 0000000..e357b2f --- /dev/null +++ b/library/stdio_initializeiob.c @@ -0,0 +1,73 @@ +/* + * $Id: stdio_initializeiob.c,v 1.1.1.1 2004-07-26 16:31:36 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +void +__initialize_iob( + struct iob * iob, + HOOKFUNC hook_function, + STRPTR custom_buffer, + STRPTR buffer, + int buffer_size, + int file_descriptor, + int slot_number, + ULONG flags) +{ + assert( iob != NULL && hook_function != NULL ); + + memset(iob,0,sizeof(*iob)); + + iob->iob_CustomBuffer = custom_buffer; + iob->iob_Buffer = buffer; + iob->iob_BufferSize = buffer_size; + iob->iob_Descriptor = file_descriptor; + iob->iob_SlotNumber = slot_number; + iob->iob_Flags = flags; + iob->iob_Hook = &iob->iob_DefaultHook; + + #if defined(__amigaos4__) + { + iob->iob_Hook->h_Entry = (HOOKFUNC)hook_function; + } + #else + { + iob->iob_Hook->h_Entry = (HOOKFUNC)HookEntry; + iob->iob_Hook->h_SubEntry = (HOOKFUNC)hook_function; + } + #endif /* __amigaos4__ */ +} diff --git a/library/stdio_iobhookentry.c b/library/stdio_iobhookentry.c new file mode 100644 index 0000000..d0b9648 --- /dev/null +++ b/library/stdio_iobhookentry.c @@ -0,0 +1,122 @@ +/* + * $Id: stdio_iobhookentry.c,v 1.1.1.1 2004-07-26 16:31:36 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +void +__iob_hook_entry( + struct Hook * UNUSED unused_hook, + struct iob * file_iob, + struct file_hook_message * message) +{ + int result; + int error; + + assert( message != NULL && file_iob != NULL ); + + switch(message->action) + { + case file_hook_action_read: + + SHOWMSG("file_hook_action_read"); + + SHOWVALUE(file_iob->iob_Descriptor); + SHOWPOINTER(message->data); + SHOWVALUE(message->size); + + assert( message->data != NULL ); + assert( message->size > 0 ); + assert( FLAG_IS_SET(file_iob->iob_Flags,IOBF_IN_USE) ); + + result = __read(file_iob->iob_Descriptor,message->data,(size_t)message->size,&error); + break; + + case file_hook_action_write: + + SHOWMSG("file_hook_action_write"); + + SHOWVALUE(file_iob->iob_Descriptor); + SHOWPOINTER(message->data); + SHOWVALUE(message->size); + + assert( message->data != NULL ); + assert( message->size > 0 ); + assert( FLAG_IS_SET(file_iob->iob_Flags,IOBF_IN_USE) ); + + result = __write(file_iob->iob_Descriptor,message->data,(size_t)message->size,&error); + + break; + + case file_hook_action_seek: + + SHOWMSG("file_hook_action_seek"); + + SHOWVALUE(file_iob->iob_Descriptor); + SHOWVALUE(message->position); + SHOWVALUE(message->mode); + + assert( FLAG_IS_SET(file_iob->iob_Flags,IOBF_IN_USE) ); + + result = __lseek(file_iob->iob_Descriptor,message->position,message->mode,&error); + break; + + case file_hook_action_close: + + SHOWMSG("file_hook_action_close"); + + SHOWVALUE(file_iob->iob_Descriptor); + + assert( FLAG_IS_SET(file_iob->iob_Flags,IOBF_IN_USE) ); + + result = __close(file_iob->iob_Descriptor,&error); + break; + + default: + + SHOWVALUE(message->action); + + result = -1; + error = EBADF; + + break; + } + + SHOWVALUE(result); + + message->result = result; + message->error = error; +} diff --git a/library/stdio_isinfinity.c b/library/stdio_isinfinity.c new file mode 100644 index 0000000..800c008 --- /dev/null +++ b/library/stdio_isinfinity.c @@ -0,0 +1,81 @@ +/* + * $Id: stdio_isinfinity.c,v 1.1.1.1 2004-07-26 16:31:37 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#if defined (FLOATING_POINT_SUPPORT) + +int +__is_infinity(long double number) +{ + const unsigned long * const raw = (const unsigned long * const)&number; + int result = 0; + + ENTER(); + + /* This assumes that a) 'number' is stored in big endian format + * and b) it is stored in IEEE 754 format. + */ + if(sizeof(number) == 4) /* single precision */ + { + /* Exponent = 255 and fraction = 0.0 */ + if((raw[0] & 0x7FFFFFFF) == 0x7F800000) + result = 1; + } + else if (sizeof(number) == 8) /* double precision */ + { + /* Exponent = 2047 and fraction = 0.0 */ + if(((raw[0] & 0x7FFFFFFF) == 0x7FF00000) && (raw[1] == 0)) + { + result = 1; + } + } + else if (sizeof(number) == 12) /* extended precision */ + { + /* Exponent = 32767 and fraction = 0.0 */ + if(((raw[0] & 0x7FFF0000) == 0x7FFF0000) && + (raw[1] & 0x7FFFFFFF) == 0 && (raw[2] == 0)) + { + result = 1; + } + } + + RETURN(result); + return(result); +} + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/stdio_isnotanumber.c b/library/stdio_isnotanumber.c new file mode 100644 index 0000000..b0f3222 --- /dev/null +++ b/library/stdio_isnotanumber.c @@ -0,0 +1,85 @@ +/* + * $Id: stdio_isnotanumber.c,v 1.1.1.1 2004-07-26 16:31:37 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#if defined (FLOATING_POINT_SUPPORT) + +int +__is_not_a_number(long double number) +{ + const unsigned long * const raw = (const unsigned long * const)&number; + int result = 0; + + ENTER(); + + /* This assumes that a) 'number' is stored in big endian format + * and b) it is stored in IEEE 754 format. + */ + if(sizeof(number) == 4) /* single precision */ + { + /* Exponent = 255 and fraction != 0.0 */ + if((raw[0] & 0x7F800000) == 0x7F800000 && + (raw[0] & 0x007FFFFF) != 0) + { + result = 1; + } + } + else if (sizeof(number) == 8) /* double precision */ + { + /* Exponent = 2047 and fraction != 0.0 */ + if(((raw[0] & 0x7FF00000) == 0x7FF00000) && + ((raw[0] & 0x000FFFFF) != 0 || (raw[1] != 0))) + { + result = 1; + } + } + else if (sizeof(number) == 12) /* extended precision */ + { + /* Exponent = 32767 and fraction != 0.0 */ + if(((raw[0] & 0x7FFF0000) == 0x7FFF0000) && + ((raw[1] & 0x7FFFFFFF) != 0 || raw[2] != 0)) + { + result = 1; + } + } + + RETURN(result); + return(result); +} + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/stdio_locksemaphorename.c b/library/stdio_locksemaphorename.c new file mode 100644 index 0000000..2d06846 --- /dev/null +++ b/library/stdio_locksemaphorename.c @@ -0,0 +1,40 @@ +/* + * $Id: stdio_locksemaphorename.c,v 1.1.1.1 2004-07-26 16:31:37 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +char * __file_lock_semaphore_name = "Advisory File Locking"; diff --git a/library/stdio_nostdio.c b/library/stdio_nostdio.c new file mode 100644 index 0000000..bbd142e --- /dev/null +++ b/library/stdio_nostdio.c @@ -0,0 +1,40 @@ +/* + * $Id: stdio_nostdio.c,v 1.1.1.1 2004-07-26 16:31:37 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +BOOL __no_standard_io; diff --git a/library/stdio_openiob.c b/library/stdio_openiob.c new file mode 100644 index 0000000..b3e4a2b --- /dev/null +++ b/library/stdio_openiob.c @@ -0,0 +1,214 @@ +/* + * $Id: stdio_openiob.c,v 1.1.1.1 2004-07-26 16:31:37 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +__open_iob(const char *filename, const char *mode, int file_descriptor, int slot_number) +{ + ULONG file_flags; + int result = -1; + char actual_mode[8]; + int open_mode; + size_t mode_len,len,i; + struct fd * fd = NULL; + STRPTR buffer = NULL; + STRPTR aligned_buffer; + struct iob * file; + + ENTER(); + + SHOWSTRING(filename); + SHOWSTRING(mode); + SHOWVALUE(slot_number); + + assert( mode != NULL && 0 <= slot_number && slot_number < __num_iob ); + + file = __iob[slot_number]; + + assert( FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE) ); + + if(__check_abort_enabled) + __check_abort(); + + /* Figure out if the file descriptor provided is any use. */ + if(file_descriptor >= 0) + { + assert( file_descriptor < __num_fd ); + assert( __fd[file_descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + errno = EBADF; + goto out; + } + } + + /* Options can follow the mode string, separated by a comma. + * We don't support any of those. + */ + len = mode_len = strlen(mode); + for(i = 0 ; i < len ; i++) + { + if(mode[i] == ',') + { + mode_len = i; + break; + } + } + + /* Keep only the first few letters of the mode string. */ + if(mode_len > sizeof(actual_mode)-1) + mode_len = sizeof(actual_mode)-1; + + memmove(actual_mode,mode,mode_len); + actual_mode[mode_len] = '\0'; + + SHOWSTRING(actual_mode); + + if(strcmp(actual_mode,"r") == SAME || strcmp(actual_mode,"rb") == SAME) + { + SHOWMSG("read-only"); + + open_mode = O_RDONLY; + file_flags = IOBF_READ; + } + else if (strcmp(actual_mode,"w") == SAME || strcmp(actual_mode,"wb") == SAME) + { + SHOWMSG("write-only"); + + open_mode = O_WRONLY | O_CREAT | O_TRUNC; + file_flags = IOBF_WRITE; + } + else if (strcmp(actual_mode,"a") == SAME || strcmp(actual_mode,"ab") == SAME) + { + SHOWMSG("write-only; append"); + + open_mode = O_WRONLY | O_CREAT | O_APPEND; + file_flags = IOBF_WRITE; + } + else if (strcmp(actual_mode,"r+") == SAME || strcmp(actual_mode,"rb+") == SAME || strcmp(actual_mode,"r+b") == SAME) + { + SHOWMSG("read/write; don't overwrite"); + + open_mode = O_RDWR; + file_flags = IOBF_READ | IOBF_WRITE; + } + else if (strcmp(actual_mode,"w+") == SAME || strcmp(actual_mode,"wb+") == SAME || strcmp(actual_mode,"w+b") == SAME) + { + SHOWMSG("read/write; overwrite"); + + open_mode = O_RDWR | O_CREAT | O_TRUNC; + file_flags = IOBF_READ | IOBF_WRITE; + } + else if (strcmp(actual_mode,"a+") == SAME || strcmp(actual_mode,"ab+") == SAME || strcmp(actual_mode,"a+b") == SAME) + { + SHOWMSG("read/write; append; don't overwrite"); + + open_mode = O_RDWR | O_CREAT | O_APPEND; + file_flags = IOBF_READ | IOBF_WRITE; + } + else + { + SHOWMSG("unsupported file open mode"); + + errno = EINVAL; + goto out; + } + + SHOWMSG("allocating file buffer"); + + /* Allocate a little more memory than necessary. */ + buffer = malloc(BUFSIZ + 15); + if(buffer == NULL) + { + SHOWMSG("that didn't work"); + + errno = ENOBUFS; + goto out; + } + + /* Align the buffer start address to a cache line boundary. */ + aligned_buffer = (char *)((ULONG)(buffer + 15) & ~15UL); + + if(file_descriptor < 0) + { + assert( filename != NULL ); + + file_descriptor = open(filename,open_mode); + if(file_descriptor < 0) + { + SHOWMSG("couldn't open the file"); + goto out; + } + } + else + { + /* Update the append flag. */ + if(FLAG_IS_SET(open_mode,O_APPEND)) + SET_FLAG(fd->fd_Flags,FDF_APPEND); + else + CLEAR_FLAG(fd->fd_Flags,FDF_APPEND); + } + + __initialize_iob(file,(HOOKFUNC)__iob_hook_entry, + buffer, + aligned_buffer,BUFSIZ, + file_descriptor, + slot_number, + IOBF_IN_USE | file_flags | IOBF_NO_NUL); + + buffer = NULL; + + result = 0; + + out: + + if(buffer != NULL) + free(buffer); + + RETURN(result); + return(result); +} diff --git a/library/stdio_perror.c b/library/stdio_perror.c new file mode 100644 index 0000000..9cadb58 --- /dev/null +++ b/library/stdio_perror.c @@ -0,0 +1,57 @@ +/* + * $Id: stdio_perror.c,v 1.1.1.1 2004-07-26 16:31:38 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +void +perror(const char * s) +{ + char * error_message; + int error = errno; + + if(s != NULL) + fprintf(stderr,"%s: ",s); + + error_message = strerror(error); + + if(error_message != NULL) + fprintf(stderr,"%s",error_message); + else + fprintf(stderr,"error %d",error); + + fprintf(stderr,"\n"); +} diff --git a/library/stdio_popen.c b/library/stdio_popen.c new file mode 100644 index 0000000..8dccd7d --- /dev/null +++ b/library/stdio_popen.c @@ -0,0 +1,362 @@ +/* + * $Id: stdio_popen.c,v 1.1.1.1 2004-07-26 16:31:38 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +pclose(FILE *stream) +{ + int result = -1; + + ENTER(); + + SHOWPOINTER(stream); + + assert(stream != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + SHOWMSG("invalid stream parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + fclose(stream); + + /* ZZZ we actually could catch the program's termination code + * by passing an exit function address to SystemTags() below. + */ + result = 0; + + out: + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#define SET_TAG(t,v,d) \ + do \ + { \ + (t)->ti_Tag = (Tag)(v); \ + (t)->ti_Data = (ULONG)(d); \ + (t)++; \ + } \ + while(0) + +#define END_TAG(t) \ + (void)((t)->ti_Tag = TAG_END) + +/****************************************************************************/ + +FILE * +popen(const char *command, const char *type) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info command_nti; + #endif /* UNIX_PATH_SEMANTICS */ + char * command_copy = NULL; + BPTR input = ZERO; + BPTR output = ZERO; + char pipe_file_name[40]; + struct TagItem tags[5]; + struct TagItem * tag; + FILE * result = NULL; + LONG status; + unsigned long task_address; + time_t now; + size_t type_len; + char actual_type[8]; + int i; + + ENTER(); + + SHOWSTRING(command); + SHOWSTRING(type); + + assert(command != NULL && type != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(command == NULL || type == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + char just_the_command_name[MAXPATHLEN+1]; + BOOL quotes_needed = FALSE; + char * command_name; + size_t command_len; + BOOL have_quote; + size_t len; + + /* We may need to replace the path specified for the command, + so let's figure out first how long the command name, + including everything, really is. */ + len = strlen(command); + command_len = len; + + have_quote = FALSE; + for(i = 0 ; i < (int)len ; i++) + { + if(command[i] == '\"') + { + quotes_needed = TRUE; + + have_quote ^= TRUE; + } + + if((command[i] == ' ' || command[i] == '\t') && NOT have_quote) + { + command_len = i; + break; + } + } + + /* This may be too long for proper translation... */ + if(command_len > MAXPATHLEN) + { + errno = ENAMETOOLONG; + result = NULL; + goto out; + } + + /* Grab the command name itself, then have it translated. */ + command_name = just_the_command_name; + for(i = 0; (size_t)i < command_len; i++) + { + if(command[i] != '\"') + (*command_name++) = command[i]; + } + + (*command_name) = '\0'; + + command_name = just_the_command_name; + + if(__translate_unix_to_amiga_path_name((const char **)&command_name,&command_nti) != 0) + { + result = NULL; + goto out; + } + + /* Now put it all together again */ + command_copy = malloc(1 + strlen(command_name) + 1 + strlen(&command[command_len]) + 1); + if(command_copy == NULL) + { + errno = ENOMEM; + result = NULL; + goto out; + } + + if(quotes_needed) + { + command_copy[0] = '\"'; + strcpy(&command_copy[1],command_name); + strcat(command_copy,"\""); + } + else + { + strcpy(command_copy,command_name); + } + + strcat(command_copy,&command[command_len]); + + command = command_copy; + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + /* Skip any options following the comma. */ + type_len = strlen(type); + for(i = 0 ; i < (int)type_len ; i++) + { + if(type[i] == ',') + { + type_len = i; + break; + } + } + + /* Keep only the first few letters of the type string. */ + if(type_len > sizeof(actual_type)-1) + type_len = sizeof(actual_type)-1; + + memmove(actual_type,type,type_len); + actual_type[type_len] = '\0'; + + /* The current PIPE: device only supports unidirectional connections. */ + if(strcmp(actual_type,"r+") == SAME) + { + SHOWMSG("unsupported access mode"); + + errno = EINVAL; + goto out; + } + + strcpy(pipe_file_name,"PIPE:"); + + task_address = (unsigned long)FindTask(NULL); + + for(i = strlen(pipe_file_name) ; task_address != 0 && i < (int)sizeof(pipe_file_name)-1 ; i++) + { + pipe_file_name[i] = '0' + (task_address % 8); + task_address = task_address / 8; + } + + pipe_file_name[i++] = '.'; + + time(&now); + + for( ; now != 0 && i < (int)sizeof(pipe_file_name)-1 ; i++) + { + pipe_file_name[i] = '0' + (now % 8); + now = now / 8; + } + + pipe_file_name[i] = '\0'; + + SHOWSTRING(pipe_file_name); + + PROFILE_OFF(); + + if(strcmp(actual_type,"r") == SAME) + { + input = Open("NIL:",MODE_NEWFILE); + if(input != ZERO) + output = Open(pipe_file_name,MODE_NEWFILE); + } + else if (strcmp(actual_type,"w") == SAME) + { + input = Open(pipe_file_name,MODE_NEWFILE); + if(input != ZERO) + output = Open("NIL:",MODE_NEWFILE); + } + else + { + errno = EINVAL; + goto out; + } + + PROFILE_ON(); + + if(input == ZERO || output == ZERO) + { + SHOWMSG("couldn't open the streams"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + tag = tags; + + SET_TAG(tag,SYS_Input, input); + SET_TAG(tag,SYS_Output, output); + SET_TAG(tag,SYS_Asynch, TRUE); + SET_TAG(tag,SYS_UserShell, TRUE); + END_TAG(tag); + + PROFILE_OFF(); + status = SystemTagList((STRPTR)command,tags); + PROFILE_ON(); + + if(status == -1) + { + SHOWMSG("SystemTagList() failed"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + input = output = ZERO; + + result = fopen(pipe_file_name,type); + + out: + + if(command_copy != NULL) + free(command_copy); + + PROFILE_OFF(); + + if(input != ZERO) + Close(input); + + if(output != ZERO) + Close(output); + + PROFILE_ON(); + + RETURN(result); + return(result); +} diff --git a/library/stdio_printf.c b/library/stdio_printf.c new file mode 100644 index 0000000..ea4dc56 --- /dev/null +++ b/library/stdio_printf.c @@ -0,0 +1,79 @@ +/* + * $Id: stdio_printf.c,v 1.1.1.1 2004-07-26 16:31:38 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +printf(const char *format, ...) +{ + int result = -1; + va_list arg; + + ENTER(); + + SHOWSTRING(format); + + assert( format != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(format == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + va_start(arg,format); + result = vfprintf(stdout,format,arg); + va_end(arg); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_protos.h b/library/stdio_protos.h new file mode 100644 index 0000000..3639c5b --- /dev/null +++ b/library/stdio_protos.h @@ -0,0 +1,221 @@ +/* + * $Id: stdio_protos.h,v 1.1.1.1 2004-07-26 16:31:39 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_PROTOS_H +#define _STDIO_PROTOS_H + +/****************************************************************************/ + +#ifndef UTILITY_HOOKS_H +#include +#endif /* UTILITY_HOOKS_H */ + +/****************************************************************************/ + +#ifndef _STDIO_H +#include +#endif /* _STDIO_H */ + +/****************************************************************************/ + +#ifndef _MATH_FP_SUPPORT_H +#include "math_fp_support.h" +#endif /* _MATH_FP_SUPPORT_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H + +/* Forward declarations */ +struct file_hook_message; +struct iob; +struct fd; + +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +/* stdio_translateioerror.c */ +extern void __translate_io_error_to_errno(LONG io_error,int * errno_ptr); +extern void __translate_access_io_error_to_errno(LONG io_error,int * errno_ptr); + +/****************************************************************************/ + +/* stdio_get_file_descriptor.c */ +extern struct fd * __get_file_descriptor(int file_descriptor); + +/****************************************************************************/ + +/* stdio_iobhookentry.c */ +extern void __iob_hook_entry(struct Hook * hook,struct iob * iob,struct file_hook_message * message); + +/****************************************************************************/ + +/* stdio_fdhookentry.c */ +extern void __fd_hook_entry(struct Hook * hook,struct fd * fd,struct file_hook_message * message); + +/****************************************************************************/ + +/* stdio_initializefd.c */ +extern void __initialize_fd(struct fd * fd,HOOKFUNC hook_function,BPTR default_file,ULONG flags); + +/****************************************************************************/ + +/* stdio_findvacantfdentry.c */ +extern BOOL __is_valid_fd(struct fd * fd); +extern int __find_vacant_fd_entry(void); + +/****************************************************************************/ + +/* stdio_initializeiob.c */ +extern void __initialize_iob(struct iob * iob,HOOKFUNC hook_function,STRPTR custom_buffer,STRPTR buffer,int buffer_size,int file_descriptor,int slot_number,ULONG flags); + +/****************************************************************************/ + +/* stdio_findvacantiobentry.c */ +extern BOOL __is_valid_iob(struct iob * iob); +extern int __find_vacant_iob_entry(void); + +/****************************************************************************/ + +/* stdio_growfdtable.c */ +extern int __grow_fd_table(void); + +/****************************************************************************/ + +/* stdio_growiobtable.c */ +extern int __grow_iob_table(void); + +/****************************************************************************/ + +/* stdio_openiob.c */ +extern int __open_iob(const char *filename, const char *mode, int file_descriptor, int slot_number); + +/****************************************************************************/ + +/* stdio_filliobreadbuffer.c */ +extern int __fill_iob_read_buffer(struct iob * file); + +/****************************************************************************/ + +/* stdio_dropiobreadbuffer.c */ +extern int __drop_iob_read_buffer(struct iob * file); + +/****************************************************************************/ + +/* stdio_flushiobwritebuffer.c */ +extern int __flush_iob_write_buffer(struct iob * file); + +/****************************************************************************/ + +/* stdio_vfscanf.c */ +extern int __vfscanf(FILE *stream, const char *format, va_list arg); + +/****************************************************************************/ + +/* fcntl_write.c */ +extern ssize_t __write(int file_descriptor, const void * buffer, size_t num_bytes, int * error_ptr); + +/****************************************************************************/ + +/* fcntl_lseek.c */ +extern off_t __lseek(int file_descriptor, off_t offset, int mode, int * error_ptr); + +/****************************************************************************/ + +/* fcntl_close.c */ +extern int __close(int file_descriptor,int * error_ptr); + +/****************************************************************************/ + +/* stdio_fgetc.c */ +extern int __fgetc_check(FILE * stream); +extern int __fgetc(FILE *stream); + +/****************************************************************************/ + +/* stdio_fputc.c */ +extern int __fputc_check(FILE *stream); +extern int __fputc(int c,FILE *stream,int buffer_mode); + +/****************************************************************************/ + +/* stdio_sscanf_hook_entry.c */ +extern void __sscanf_hook_entry(struct Hook *UNUSED unused_hook,struct iob *string,struct file_hook_message *message); + +/****************************************************************************/ + +/* stdio_vasprintf_hook_entry.c */ +extern void __vasprintf_hook_entry(struct Hook *UNUSED unused_hook,struct iob *string,struct file_hook_message *message); + +/****************************************************************************/ + +/* stdio_vsprintf_hook_entry.c */ +extern void __vsprintf_hook_entry(struct Hook *UNUSED unused_hook,struct iob *string,struct file_hook_message *message); + +/****************************************************************************/ + +/* stdio_vsnprintf_hook_entry.c */ +extern void __vsnprintf_hook_entry(struct Hook *UNUSED unused_hook,struct iob *string,struct file_hook_message *message); + +/****************************************************************************/ + +/* fcntl_read.c */ +extern ssize_t __read(int file_descriptor, void * buffer, size_t num_bytes, int * error_ptr); + +/****************************************************************************/ + +/* stdio_duplicate_fd.c */ +extern void __duplicate_fd(struct fd * duplicate_fd,struct fd * original_fd); + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +/* stdio_isnotanumber.c */ +extern int __is_not_a_number(long double number); + +/****************************************************************************/ + +/* stdio_isinfinity.c */ +extern int __is_infinity(long double number); + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#endif /* _STDIO_PROTOS_H */ diff --git a/library/stdio_putc.c b/library/stdio_putc.c new file mode 100644 index 0000000..84ff945 --- /dev/null +++ b/library/stdio_putc.c @@ -0,0 +1,72 @@ +/* + * $Id: stdio_putc.c,v 1.1.1.1 2004-07-26 16:31:39 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#undef putc + +/****************************************************************************/ + +int +putc(int c,FILE *stream) +{ + int result = -1; + + assert( stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + result = fputc(c,stream); + + out: + + return(result); +} diff --git a/library/stdio_putchar.c b/library/stdio_putchar.c new file mode 100644 index 0000000..7517971 --- /dev/null +++ b/library/stdio_putchar.c @@ -0,0 +1,52 @@ +/* + * $Id: stdio_putchar.c,v 1.1.1.1 2004-07-26 16:31:39 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#undef putchar + +/****************************************************************************/ + +int +putchar(int c) +{ + int result; + + result = fputc(c,stdout); + + return(result); +} diff --git a/library/stdio_puts.c b/library/stdio_puts.c new file mode 100644 index 0000000..ad6a2d5 --- /dev/null +++ b/library/stdio_puts.c @@ -0,0 +1,112 @@ +/* + * $Id: stdio_puts.c,v 1.1.1.1 2004-07-26 16:31:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +puts(const char *s) +{ + struct iob * file = (struct iob *)stdout; + int result = EOF; + int buffer_mode; + int c; + + ENTER(); + + SHOWSTRING(s); + + assert( s != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(file) ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + buffer_mode = (file->iob_Flags & IOBF_BUFFER_MODE); + if(buffer_mode == IOBF_BUFFER_MODE_NONE) + buffer_mode = IOBF_BUFFER_MODE_LINE; + + if(__fputc_check(stdout) != OK) + goto out; + + while((c = (*s++)) != '\0') + { + if(__putc(c,stdout,buffer_mode) == EOF) + goto out; + } + + if(__putc('\n',stdout,buffer_mode) == EOF) + goto out; + + result = OK; + + out: + + /* Note: if buffering is disabled for this stdout, then we still + may have buffered data around, queued to be printed right now. + This is intended to improve performance as it takes more effort + to write a single character to a file than to write a bunch. */ + if(result == OK && (file->iob_Flags & IOBF_BUFFER_MODE) == IOBF_BUFFER_MODE_NONE) + { + if(__iob_write_buffer_is_valid(file) && __flush_iob_write_buffer(file) < 0) + { + SHOWMSG("couldn't flush the write buffer"); + result = EOF; + } + } + + RETURN(result); + return(result); +} diff --git a/library/stdio_remove.c b/library/stdio_remove.c new file mode 100644 index 0000000..39e27bc --- /dev/null +++ b/library/stdio_remove.c @@ -0,0 +1,100 @@ +/* + * $Id: stdio_remove.c,v 1.1.1.1 2004-07-26 16:31:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +remove(const char *filename) +{ + int result = -1; + + ENTER(); + + SHOWSTRING(filename); + + assert( filename != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(filename == NULL) + { + SHOWMSG("invalid path name"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + result = unlink(filename); + } + #else + { + LONG status; + + D(("trying to delete '%s'",filename)); + + PROFILE_OFF(); + status = DeleteFile((STRPTR)filename); + PROFILE_ON(); + + if(status == DOSFALSE) + { + __translate_access_io_error_to_errno(IoErr(),&errno); + goto out; + } + + result = 0; + } + #endif /* UNIX_PATH_SEMANTICS */ + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_rename.c b/library/stdio_rename.c new file mode 100644 index 0000000..368fcc9 --- /dev/null +++ b/library/stdio_rename.c @@ -0,0 +1,149 @@ +/* + * $Id: stdio_rename.c,v 1.1.1.1 2004-07-26 16:31:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +rename(const char *oldname,const char *newname) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info old_nti; + struct name_translation_info new_nti; + #endif /* UNIX_PATH_SEMANTICS */ + int result = -1; + LONG status; + + ENTER(); + + SHOWSTRING(oldname); + SHOWSTRING(newname); + + assert( oldname != NULL && newname != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(oldname == NULL || newname == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&oldname,&old_nti) != 0) + goto out; + + if(__translate_unix_to_amiga_path_name(&newname,&new_nti) != 0) + goto out; + + if(old_nti.is_root || new_nti.is_root) + { + errno = EACCES; + goto out; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + D(("renaming '%s' to '%s'",oldname,newname)); + + PROFILE_OFF(); + status = Rename((STRPTR)oldname,(STRPTR)newname); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("that didn't work"); + + #if defined(UNIX_PATH_SEMANTICS) + { + BOOL renamed; + + if(IoErr() != ERROR_OBJECT_EXISTS) + { + SHOWMSG("that was some other error"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + SHOWMSG("deleting the target file and renaming the source file"); + + /* ZZZ there should be a safer solution for this */ + + PROFILE_OFF(); + renamed = (BOOL)(DeleteFile((STRPTR)newname) && Rename((STRPTR)oldname,(STRPTR)newname)); + PROFILE_ON(); + + if(NOT renamed) + { + SHOWMSG("that didn't work"); + + __translate_access_io_error_to_errno(IoErr(),&errno); + goto out; + } + } + #else + { + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + #endif /* UNIX_PATH_SEMANTICS */ + } + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_rewind.c b/library/stdio_rewind.c new file mode 100644 index 0000000..f9399d0 --- /dev/null +++ b/library/stdio_rewind.c @@ -0,0 +1,51 @@ +/* + * $Id: stdio_rewind.c,v 1.1.1.1 2004-07-26 16:31:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +void +rewind(FILE *stream) +{ + assert( stream != NULL ); + + if(__check_abort_enabled) + __check_abort(); + + clearerr(stream); + + fseek(stream,0,SEEK_SET); +} diff --git a/library/stdio_scanf.c b/library/stdio_scanf.c new file mode 100644 index 0000000..321bc86 --- /dev/null +++ b/library/stdio_scanf.c @@ -0,0 +1,81 @@ +/* + * $Id: stdio_scanf.c,v 1.1.1.1 2004-07-26 16:31:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +scanf(const char *format, ...) +{ + int result = -1; + va_list arg; + + ENTER(); + + SHOWSTRING(format); + + assert(format != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(format == NULL) + { + SHOWMSG("invalid format parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + va_start(arg,format); + result = __vfscanf(stdin,format,arg); + va_end(arg); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_setbuf.c b/library/stdio_setbuf.c new file mode 100644 index 0000000..c7a1d7f --- /dev/null +++ b/library/stdio_setbuf.c @@ -0,0 +1,79 @@ +/* + * $Id: stdio_setbuf.c,v 1.1.1.1 2004-07-26 16:31:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +void +setbuf(FILE *stream,char *buf) +{ + ENTER(); + + SHOWPOINTER(stream); + SHOWPOINTER(buf); + + assert(stream != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + SHOWMSG("invalid stream parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + if(buf == NULL) + setvbuf(stream,NULL,IOBF_BUFFER_MODE_NONE,0); + else + setvbuf(stream,buf,IOBF_BUFFER_MODE_FULL,BUFSIZ); + + out: + + LEAVE(); +} diff --git a/library/stdio_setvbuf.c b/library/stdio_setvbuf.c new file mode 100644 index 0000000..3a83786 --- /dev/null +++ b/library/stdio_setvbuf.c @@ -0,0 +1,195 @@ +/* + * $Id: stdio_setvbuf.c,v 1.1.1.1 2004-07-26 16:31:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +setvbuf(FILE *stream,char *buf,int bufmode,size_t size) +{ + struct iob * file = (struct iob *)stream; + char *new_buffer = NULL; + int result = EOF; + + ENTER(); + + SHOWPOINTER(stream); + SHOWPOINTER(buf); + SHOWVALUE(bufmode); + SHOWVALUE(size); + + assert( stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + SHOWMSG("invalid stream parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + if(bufmode < IOBF_BUFFER_MODE_FULL || + bufmode > IOBF_BUFFER_MODE_NONE) + { + SHOWMSG("invalid buffer mode"); + + errno = EINVAL; + goto out; + } + + if((int)size < 0) + { + SHOWMSG("invalid buffer size"); + + errno = EINVAL; + goto out; + } + + assert( __is_valid_iob(file) ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE)) + { + SHOWMSG("this file is not even in use"); + + errno = EBADF; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + /* A buffer size of 0 bytes defaults to unbuffered operation. */ + if(size == 0) + bufmode = IOBF_BUFFER_MODE_NONE; + + /* If a certain buffer size is requested but no buffer was provided, + allocate some memory for it. */ + if(size > 0 && buf == NULL) + { + /* Allocate a little more memory than necessary. */ + new_buffer = malloc(size + 15); + if(new_buffer == NULL) + { + errno = ENOBUFS; + goto out; + } + } + + /* Get rid of any buffered data. We're going to replace the buffer. */ + if(__iob_write_buffer_is_valid(file) && __flush_iob_write_buffer(file) < 0) + { + SHOWMSG("could not flush write buffer"); + goto out; + } + + if(__iob_read_buffer_is_valid(file) && __drop_iob_read_buffer(file) < 0) + { + SHOWMSG("could not drop read buffer"); + goto out; + } + + /* Get rid of any buffer specially allocated for this stream. */ + if(file->iob_CustomBuffer != NULL) + { + free(file->iob_CustomBuffer); + file->iob_CustomBuffer = NULL; + } + + if(bufmode == IOBF_BUFFER_MODE_NONE) + { + /* Use the default buffer, which is one byte in size. */ + new_buffer = &file->iob_SingleByte; + size = 1; + } + else + { + /* Replace the old buffer. */ + if(buf != NULL) + { + new_buffer = (UBYTE *)buf; + } + else + { + /* Remember this, so we can release it later. */ + file->iob_CustomBuffer = new_buffer; + + /* Align the buffer start address to a cache line boundary. */ + new_buffer = (char *)((ULONG)(new_buffer + 15) & ~15UL); + } + } + + assert( file->iob_BufferPosition == 0 ); + assert( file->iob_BufferReadBytes == 0 ); + assert( file->iob_BufferWriteBytes == 0 ); + + file->iob_Buffer = new_buffer; + file->iob_BufferSize = size; + + file->iob_Flags &= ~IOBF_BUFFER_MODE; + file->iob_Flags |= bufmode; + + new_buffer = NULL; + + result = OK; + + out: + + if(new_buffer != NULL) + free(new_buffer); + + RETURN(result); + return(result); +} diff --git a/library/stdio_snprintf.c b/library/stdio_snprintf.c new file mode 100644 index 0000000..da53eab --- /dev/null +++ b/library/stdio_snprintf.c @@ -0,0 +1,84 @@ +/* + * $Id: stdio_snprintf.c,v 1.1.1.1 2004-07-26 16:31:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +snprintf(char *s, size_t size, const char *format, ...) +{ + int result = -1; + va_list arg; + + ENTER(); + + assert( format != NULL ); + + SHOWPOINTER(s); + SHOWVALUE(size); + SHOWSTRING(format); + + assert( size == 0 || s != NULL ); + assert( (int)size >= 0); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if((size > 0 && s == NULL) || format == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + va_start(arg,format); + result = vsnprintf(s,size,format,arg); + va_end(arg); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_sprintf.c b/library/stdio_sprintf.c new file mode 100644 index 0000000..1620360 --- /dev/null +++ b/library/stdio_sprintf.c @@ -0,0 +1,80 @@ +/* + * $Id: stdio_sprintf.c,v 1.1.1.1 2004-07-26 16:31:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +sprintf(char *s, const char *format, ...) +{ + int result = -1; + va_list arg; + + ENTER(); + + SHOWPOINTER(s); + SHOWSTRING(format); + + assert( s != NULL && format != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s == NULL || format == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + va_start(arg,format); + result = vsprintf(s,format,arg); + va_end(arg); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_sscanf.c b/library/stdio_sscanf.c new file mode 100644 index 0000000..0b66302 --- /dev/null +++ b/library/stdio_sscanf.c @@ -0,0 +1,94 @@ +/* + * $Id: stdio_sscanf.c,v 1.1.1.1 2004-07-26 16:31:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +sscanf(const char *s,const char *format, ...) +{ + struct iob string_iob; + int result = EOF; + char local_buffer[32]; + va_list arg; + + ENTER(); + + SHOWSTRING(s); + SHOWSTRING(format); + + assert( s != NULL && format != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s == NULL || format == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + __initialize_iob(&string_iob,(HOOKFUNC)__sscanf_hook_entry, + NULL, + local_buffer,sizeof(local_buffer), + -1, + -1, + IOBF_IN_USE | IOBF_READ | IOBF_BUFFER_MODE_FULL | IOBF_INTERNAL); + + string_iob.iob_String = (STRPTR)s; + string_iob.iob_StringLength = strlen(s); + + va_start(arg,format); + result = __vfscanf((FILE *)&string_iob,format,arg); + va_end(arg); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_sscanf_hook_entry.c b/library/stdio_sscanf_hook_entry.c new file mode 100644 index 0000000..8c24dd2 --- /dev/null +++ b/library/stdio_sscanf_hook_entry.c @@ -0,0 +1,94 @@ +/* + * $Id: stdio_sscanf_hook_entry.c,v 1.1.1.1 2004-07-26 16:31:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +void +__sscanf_hook_entry( + struct Hook * UNUSED unused_hook, + struct iob * string_iob, + struct file_hook_message * message) +{ + int result = -1; + int error = OK; + int num_bytes; + + assert( message != NULL && string_iob != NULL ); + + if(message->action != file_hook_action_read) + { + error = EBADF; + goto out; + } + + assert( string_iob->iob_StringPosition >= 0 ); + assert( string_iob->iob_StringLength >= 0 ); + + if(string_iob->iob_StringPosition < string_iob->iob_StringLength) + { + int num_bytes_left; + + num_bytes_left = string_iob->iob_StringLength - string_iob->iob_StringPosition; + + num_bytes = message->size; + if(num_bytes > num_bytes_left) + num_bytes = num_bytes_left; + + assert( message->data != NULL ); + assert( num_bytes >= 0 ); + + memmove(message->data,&string_iob->iob_String[string_iob->iob_StringPosition],(size_t)num_bytes); + string_iob->iob_StringPosition += num_bytes; + } + else + { + num_bytes = 0; + } + + result = num_bytes; + + out: + + message->result = result; + message->error = error; +} diff --git a/library/stdio_tmpfile.c b/library/stdio_tmpfile.c new file mode 100644 index 0000000..b39ef09 --- /dev/null +++ b/library/stdio_tmpfile.c @@ -0,0 +1,119 @@ +/* + * $Id: stdio_tmpfile.c,v 1.1.1.1 2004-07-26 16:31:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +FILE * +tmpfile(void) +{ + BPTR temp_file_lock = ZERO; + char * temp_file_name; + FILE * result = NULL; + struct iob * file; + + ENTER(); + + if(__check_abort_enabled) + __check_abort(); + + temp_file_name = malloc(L_tmpnam); + if(temp_file_name == NULL) + { + SHOWMSG("not enough memory for temp file name"); + goto out; + } + + /* Get a temp_file_lock on the current directory; it will be needed + * later when the temporary file is deleted. + */ + + PROFILE_OFF(); + temp_file_lock = Lock("",SHARED_LOCK); + PROFILE_ON(); + + if(temp_file_lock == ZERO) + { + SHOWMSG("couldn't get a temp_file_lock on the current directory"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + /* Find a new temporary file name. */ + tmpnam(temp_file_name); + + SHOWSTRING(temp_file_name); + + /* Open that file; we're going to need it in a minute. */ + file = (struct iob *)fopen(temp_file_name,"w+"); + if(file == NULL) + { + SHOWMSG("file didn't open"); + goto out; + } + + /* Remember this for later when the temporary file is + * to be deleted. + */ + SET_FLAG(file->iob_Flags,IOBF_TEMP); + + file->iob_TempFileName = temp_file_name; + temp_file_name = NULL; + + file->iob_TempFileLock = temp_file_lock; + temp_file_lock = ZERO; + + result = (FILE *)file; + + out: + + PROFILE_OFF(); + UnLock(temp_file_lock); + PROFILE_ON(); + + if(temp_file_name != NULL) + free(temp_file_name); + + RETURN(result); + return(result); +} diff --git a/library/stdio_tmpnam.c b/library/stdio_tmpnam.c new file mode 100644 index 0000000..8acf5b6 --- /dev/null +++ b/library/stdio_tmpnam.c @@ -0,0 +1,122 @@ +/* + * $Id: stdio_tmpnam.c,v 1.1.1.1 2004-07-26 16:31:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +char * +tmpnam(char *buf) +{ + static char local_buffer[L_tmpnam]; + static unsigned short counter; + struct Process * this_process; + APTR old_window_pointer; + unsigned short c; + char * result = NULL; /* ZZZ compiler claims that this assignment is unnecessary. */ + BPTR lock; + int i; + + ENTER(); + + if(__check_abort_enabled) + __check_abort(); + + /* If no user-supplied buffer is available, use the local one. */ + if(buf == NULL) + buf = local_buffer; + + this_process = (struct Process *)FindTask(NULL); + + old_window_pointer = this_process->pr_WindowPtr; + + while(TRUE) + { + if(__check_abort_enabled) + __check_abort(); + + c = (counter++); + + /* Build another temporary file name, which begins with the + * letters 'tmp' followed by an octal number. + */ + strcpy(buf,"tmp"); + + for(i = 0 ; i < 10 ; i++) + { + buf[3 + 10 - (i+1)] = '0' + (c % 8); + c = (c / 8); + } + + buf[3 + 10] = '\0'; + + D(("checking if '%s' exists",buf)); + + /* Turn off DOS error requesters. */ + this_process->pr_WindowPtr = (APTR)-1; + + /* Does this object exist already? */ + PROFILE_OFF(); + lock = Lock(buf,SHARED_LOCK); + PROFILE_ON(); + + /* Restore DOS requesters. */ + this_process->pr_WindowPtr = old_window_pointer; + + if(lock == ZERO) + { + /* If the object does not exist yet then we + * are finished. + */ + if(IoErr() == ERROR_OBJECT_NOT_FOUND) + result = buf; + else + __translate_io_error_to_errno(IoErr(),&errno); + + break; + } + + /* OK, so it exists already. Start over... */ + + PROFILE_OFF(); + UnLock(lock); + PROFILE_ON(); + } + + SHOWSTRING(result); + + RETURN(result); + return(result); +} diff --git a/library/stdio_translateioerror.c b/library/stdio_translateioerror.c new file mode 100644 index 0000000..65f74ca --- /dev/null +++ b/library/stdio_translateioerror.c @@ -0,0 +1,118 @@ +/* + * $Id: stdio_translateioerror.c,v 1.1.1.1 2004-07-26 16:31:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +void +__translate_io_error_to_errno(LONG io_err,int * errno_ptr) +{ + static const struct { LONG io_err; LONG errno; } map_table[] = + { + { ERROR_NO_FREE_STORE, ENOMEM }, + { ERROR_TASK_TABLE_FULL, ENOMEM }, + { ERROR_BAD_TEMPLATE, EINVAL }, + { ERROR_BAD_NUMBER, EINVAL }, + { ERROR_REQUIRED_ARG_MISSING, EINVAL }, + { ERROR_KEY_NEEDS_ARG, EINVAL }, + { ERROR_TOO_MANY_ARGS, EINVAL }, + { ERROR_UNMATCHED_QUOTES, EINVAL }, + { ERROR_LINE_TOO_LONG, ENAMETOOLONG }, + { ERROR_FILE_NOT_OBJECT, ENOEXEC }, + { ERROR_OBJECT_IN_USE, EBUSY }, + { ERROR_OBJECT_EXISTS, EEXIST }, + { ERROR_DIR_NOT_FOUND, ENOENT }, + { ERROR_OBJECT_NOT_FOUND, ENOENT }, + { ERROR_BAD_STREAM_NAME, EINVAL }, + { ERROR_OBJECT_TOO_LARGE, EFBIG }, + { ERROR_ACTION_NOT_KNOWN, ENOSYS }, + { ERROR_INVALID_COMPONENT_NAME, EINVAL }, + { ERROR_INVALID_LOCK, EBADF }, + { ERROR_OBJECT_WRONG_TYPE, EFTYPE }, + { ERROR_DISK_NOT_VALIDATED, EROFS }, + { ERROR_DISK_WRITE_PROTECTED, EROFS }, + { ERROR_RENAME_ACROSS_DEVICES, EXDEV }, + { ERROR_DIRECTORY_NOT_EMPTY, ENOTEMPTY }, + { ERROR_TOO_MANY_LEVELS, ENAMETOOLONG }, + { ERROR_DEVICE_NOT_MOUNTED, ENXIO }, + { ERROR_COMMENT_TOO_BIG, ENAMETOOLONG }, + { ERROR_DISK_FULL, ENOSPC }, + { ERROR_DELETE_PROTECTED, EACCES }, + { ERROR_WRITE_PROTECTED, EACCES }, + { ERROR_READ_PROTECTED, EACCES }, + { ERROR_NOT_A_DOS_DISK, EFTYPE }, + { ERROR_NO_DISK, EACCES }, + { ERROR_IS_SOFT_LINK, EFTYPE }, + { ERROR_BAD_HUNK, ENOEXEC }, + { ERROR_NOT_IMPLEMENTED, ENOSYS }, + { ERROR_LOCK_COLLISION, EACCES }, + { ERROR_BREAK, EINTR }, + { ERROR_NOT_EXECUTABLE, ENOEXEC } + }; + + unsigned int i; + int error; + + assert( errno_ptr != NULL ); + + error = EIO; + + for(i = 0 ; i < NUM_ENTRIES(map_table) ; i++) + { + if(map_table[i].io_err == io_err) + { + error = map_table[i].errno; + break; + } + } + + (*errno_ptr) = error; +} + +/****************************************************************************/ + +/* Same as above, except that we translate ERROR_OBJECT_WRONG_TYPE + into ENOTDIR by default. */ +void +__translate_access_io_error_to_errno(LONG io_err,int * errno_ptr) +{ + assert( errno_ptr != NULL ); + + if(io_err == ERROR_OBJECT_WRONG_TYPE) + (*errno_ptr) = ENOTDIR; + else + __translate_io_error_to_errno(io_err,errno_ptr); +} diff --git a/library/stdio_ungetc.c b/library/stdio_ungetc.c new file mode 100644 index 0000000..a0a82d3 --- /dev/null +++ b/library/stdio_ungetc.c @@ -0,0 +1,140 @@ +/* + * $Id: stdio_ungetc.c,v 1.1.1.1 2004-07-26 16:31:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +ungetc(int c,FILE *stream) +{ + struct iob * file = (struct iob *)stream; + int result = EOF; + + assert( stream != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL) + { + SHOWMSG("null file pointer!"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(file) ); + assert( FLAG_IS_SET(file->iob_Flags,IOBF_IN_USE) ); + assert( file->iob_BufferSize > 0 ); + + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_IN_USE)) + { + SHOWMSG("this file is not even in use"); + + errno = EBADF; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + /* Pushing back characters only works for files that can be read from. */ + if(FLAG_IS_CLEAR(file->iob_Flags,IOBF_READ)) + { + SHOWMSG("can't even read from this file"); + + errno = EACCES; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + /* Pushing back an EOF is forbidden. */ + if(c == EOF) + { + SHOWMSG("cannot push back an EOF"); + + errno = EINVAL; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + /* The following should never happen. */ + if(c < 0) + D(("warning -- pushback of negative number %ld!",c)); + + /* Get rid of the write buffer, if it's still around. */ + if(__iob_write_buffer_is_valid(file) > 0 && __flush_iob_write_buffer(file) < 0) + { + SHOWMSG("could not flush write buffer"); + goto out; + } + + /* We need to replace one of the characters in the buffer, which must + * have been read before. The ISO standard requires that it must + * be possible to push back at least one single character. + */ + if(file->iob_BufferPosition == 0) + { + SHOWMSG("no room to push back"); + + errno = ENOBUFS; + + SET_FLAG(file->iob_Flags,IOBF_ERROR); + goto out; + } + + CLEAR_FLAG(file->iob_Flags,IOBF_EOF_REACHED); + + /* Replace the character just read. */ + file->iob_Buffer[--file->iob_BufferPosition] = c; + + result = c; + + out: + + return(result); +} diff --git a/library/stdio_vasprintf.c b/library/stdio_vasprintf.c new file mode 100644 index 0000000..3439c07 --- /dev/null +++ b/library/stdio_vasprintf.c @@ -0,0 +1,132 @@ +/* + * $Id: stdio_vasprintf.c,v 1.1.1.1 2004-07-26 16:31:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#include "stdlib_protos.h" + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#undef vasprintf + +/****************************************************************************/ + +int +__vasprintf(const char *file,int line,char **ret,const char *format,va_list arg) +{ + struct iob string_iob; + int result = EOF; + char local_buffer[32]; + + ENTER(); + + SHOWPOINTER(ret); + SHOWSTRING(format); + + assert( ret != NULL && format != NULL && arg != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(ret == NULL || format == NULL || format == arg) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + (*ret) = NULL; + + __initialize_iob(&string_iob,(HOOKFUNC)__vasprintf_hook_entry, + NULL, + local_buffer,sizeof(local_buffer), + -1, + -1, + IOBF_IN_USE | IOBF_WRITE | IOBF_BUFFER_MODE_NONE | IOBF_INTERNAL); + + string_iob.iob_String = NULL; + string_iob.iob_StringSize = 0; + string_iob.iob_File = (char *)file; + string_iob.iob_Line = line; + + result = vfprintf((FILE *)&string_iob,format,arg); + if(result < 0) + { + SHOWMSG("ouch. that didn't work"); + + if(string_iob.iob_String != NULL) + __free(string_iob.iob_String,string_iob.iob_File,string_iob.iob_Line); + + goto out; + } + + SHOWSTRING(string_iob.iob_String); + + (*ret) = string_iob.iob_String; + + out: + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +int +vasprintf(char **ret,const char *format,va_list arg) +{ + int result; + + result = __vasprintf(NULL,0,ret,format,arg); + + return(result); +} diff --git a/library/stdio_vasprintf_hook_entry.c b/library/stdio_vasprintf_hook_entry.c new file mode 100644 index 0000000..0172527 --- /dev/null +++ b/library/stdio_vasprintf_hook_entry.c @@ -0,0 +1,117 @@ +/* + * $Id: stdio_vasprintf_hook_entry.c,v 1.1.1.1 2004-07-26 16:31:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#include "stdlib_protos.h" + +/****************************************************************************/ + +void +__vasprintf_hook_entry( + struct Hook * UNUSED unused_hook, + struct iob * string_iob, + struct file_hook_message * message) +{ + int result = -1; + int error = OK; + int num_bytes_left; + int num_bytes; + + assert( message != NULL && string_iob != NULL ); + assert( message->action == file_hook_action_write ); + + if(message->action != file_hook_action_write) + { + error = EBADF; + goto out; + } + + if(string_iob->iob_StringPosition + message->size > string_iob->iob_StringSize) + { + const int granularity = 64; + + size_t new_size; + char * buffer; + + new_size = string_iob->iob_StringPosition + message->size + granularity; + + buffer = __malloc(new_size,string_iob->iob_File,string_iob->iob_Line); + if(buffer == NULL) + { + error = ENOBUFS; + goto out; + } + + if(string_iob->iob_String != NULL) + { + memmove(buffer,string_iob->iob_String,(size_t)string_iob->iob_StringSize); + + __free(string_iob->iob_String,string_iob->iob_File,string_iob->iob_Line); + } + + string_iob->iob_String = buffer; + string_iob->iob_StringSize = new_size; + } + + assert( string_iob->iob_StringPosition <= string_iob->iob_StringSize ); + + num_bytes_left = string_iob->iob_StringSize - string_iob->iob_StringPosition; + + num_bytes = message->size; + if(num_bytes > num_bytes_left) + num_bytes = num_bytes_left; + + assert( num_bytes >= 0 ); + assert( message->data != NULL ); + + memmove(&string_iob->iob_String[string_iob->iob_StringPosition],message->data,(size_t)num_bytes); + string_iob->iob_StringPosition += num_bytes; + + result = num_bytes; + + out: + + message->result = result; + message->error = error; +} diff --git a/library/stdio_vfprintf.c b/library/stdio_vfprintf.c new file mode 100644 index 0000000..163239b --- /dev/null +++ b/library/stdio_vfprintf.c @@ -0,0 +1,1534 @@ +/* + * $Id: stdio_vfprintf.c,v 1.1.1.1 2004-07-26 16:31:46 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +/*#define DEBUG*/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +/* + * Uncomment this to activate '%lld' support and the like. Better still, + * define this is in the Makefile! + */ +/*#define USE_64_BIT_INTS*/ + +/****************************************************************************/ + +/* Data conversion flags for vfprintf() below. */ +#define FORMATF_LeftJustified (1<<0) /* Output must be left justified */ +#define FORMATF_ProduceSign (1<<1) /* Numbers always begin with a leading + sign character */ +#define FORMATF_ProduceSpace (1<<2) /* Numbers always begin with a '-' + character or a blank space */ +#define FORMATF_AlternateConversion (1<<3) /* Use alternative conversion format */ +#define FORMATF_CapitalLetters (1<<4) /* Output must use upper case characters */ +#define FORMATF_IsNegative (1<<5) /* Number is negative */ +#define FORMATF_HexPrefix (1<<6) /* Prepend '0x' to the output */ +#define FORMATF_ZeroPrefix (1<<7) /* Prepend '0' to the output */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +static int +get_num_leading_digits(long double v) +{ + int num_digits; + + if(v < 10.0) + { + num_digits = 1; + } + else + { + /* For some reason log10() can crash on GCC 68k... */ + #if (!defined(__GNUC__) || defined(__PPC__)) + { + num_digits = 1 + floor(log10(v)); + } + #else + { + /* Perform the conversion one digit at a time... */ + num_digits = 0; + + while(floor(v) > 0.0) + { + num_digits++; + + v /= 10.0; + } + } + #endif /* __GNUC__ && !__PPC__ */ + } + + return(num_digits); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +int +vfprintf(FILE * stream,const char * format, va_list arg) +{ + enum parameter_size_t + { + parameter_size_long, + parameter_size_long_long, + parameter_size_short, + parameter_size_long_double, + parameter_size_default + }; + + struct iob * iob = (struct iob *)stream; + int format_flags; + char fill_character; + int minimum_field_width; + int precision; + enum parameter_size_t parameter_size; + char conversion_type; + char buffer[80]; + int buffer_mode; + char *output_buffer; + int output_len; + char *prefix; + int result = EOF; + int len = 0; + int c; + + #if defined(FLOATING_POINT_SUPPORT) + char trail_string[8]; + int trail_string_len; + int num_trailing_zeroes; + #endif /* FLOATING_POINT_SUPPORT */ + + ENTER(); + + SHOWSTRING(format); + + assert( stream != NULL && format != NULL && arg != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL || format == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + /* If no buffering is specified but a buffer was allocated, switch to + line buffering. This is intended to help 'stderr' and others. */ + buffer_mode = (iob->iob_Flags & IOBF_BUFFER_MODE); + if(buffer_mode == IOBF_BUFFER_MODE_NONE) + buffer_mode = IOBF_BUFFER_MODE_LINE; + + assert( FLAG_IS_SET(iob->iob_Flags,IOBF_IN_USE) ); + assert( iob->iob_BufferSize > 0 ); + + if(__fputc_check(stream) != OK) + goto out; + + while((c = (*format++)) != '\0') + { + /* I this isn't a % charater, copy the input to the output. */ + if(c != '%') + { + if(__putc(c,stream,buffer_mode) == EOF) + goto out; + + len++; + + continue; + } + + format_flags = 0; + fill_character = ' '; + + /* Collect the flags: left justification, sign, space, + * alternate format, fill character. + */ + while(TRUE) + { + c = (*format); + + if(c == '-') + { + SHOWMSG("minus"); + + SET_FLAG(format_flags,FORMATF_LeftJustified); + format++; + } + else if (c == '+') + { + SHOWMSG("plus"); + + SET_FLAG(format_flags,FORMATF_ProduceSign); + format++; + } + else if (c == ' ') + { + SHOWMSG("space"); + + SET_FLAG(format_flags,FORMATF_ProduceSpace); + format++; + } + else if (c == '#') + { + SHOWMSG("alternate"); + + SET_FLAG(format_flags,FORMATF_AlternateConversion); + format++; + } + else if (c == '0') + { + SHOWMSG("leading zeroes"); + + fill_character = '0'; + format++; + } + else + { + break; + } + } + + if(c == '\0') + break; + + /* Now for the field width. */ + minimum_field_width = 0; + + while(TRUE) + { + c = (*format); + + if(c == '*') + { + SHOWMSG("use field width (stack)"); + + /* The field width is stored on the stack. */ + + assert(arg != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + result = EOF; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + minimum_field_width = va_arg(arg,int); + if(minimum_field_width < 0) + minimum_field_width = 0; + + format++; + } + else if ('0' <= c && c <= '9') + { + int next_sum; + int sum = 0; + + SHOWMSG("use field width (string)"); + + /* Process the field width. */ + while(TRUE) + { + c = (*format); + + if('0' <= c && c <= '9') + { + D(("digit = %lc",c)); + + next_sum = (10 * sum) + c - '0'; + if(next_sum < sum) /* overflow? */ + { + SHOWMSG("overflow"); + break; + } + + SHOWVALUE(sum); + + sum = next_sum; + format++; + } + else + { + break; + } + } + + minimum_field_width = sum; + + SHOWVALUE(minimum_field_width); + } + else + { + break; + } + } + + /* End of the format string? */ + if(c == '\0') + break; + + precision = -1; + + /* Was a precision specified? */ + if((*format) == '.') + { + SHOWMSG("precision required"); + + format++; + + c = (*format); + if(c == '*') + { + SHOWMSG("use stack"); + + /* The precision is stored on the stack. */ + assert(arg != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + result = EOF; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + precision = va_arg(arg,int); + if(precision < 0) + precision = 0; + + format++; + } + else if ('0' <= c && c <= '9') + { + int next_sum; + int sum = 0; + + SHOWMSG("use string"); + + /* Process the precision. */ + while(TRUE) + { + c = (*format); + + if('0' <= c && c <= '9') + { + D(("digit = %lc",c)); + + next_sum = (10 * sum) + c - '0'; + if(next_sum < sum) /* overflow? */ + { + SHOWMSG("overflow"); + break; + } + + SHOWVALUE(sum); + + sum = next_sum; + format++; + } + else + { + break; + } + } + + precision = sum; + } + else + { + /* Anything else results in the precision + * value to be set to 0. + */ + precision = 0; + } + + SHOWVALUE(precision); + } + + /* Now for the size modifier, if any. */ + c = (*format); + + /* End of the format string? */ + if(c == '\0') + break; + + if(c == 'l') + { + SHOWMSG("format size = long"); + + parameter_size = parameter_size_long; + format++; + } + else if (c == 'L') + { + SHOWMSG("format size = long double"); + + parameter_size = parameter_size_long_double; + format++; + } + else if (c == 'h') + { + SHOWMSG("format size = short"); + + parameter_size = parameter_size_short; + format++; + } + else + { + SHOWMSG("format size = default"); + + /* The default is to assume 32 bit parameters. */ + parameter_size = parameter_size_default; + } + + /* Finally, the conversion_type type. */ + c = (*format); + + /* End of the format string? */ + if(c == '\0') + break; + + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + { + /* Check for long long parameters. */ + if(c == 'l') + { + if(parameter_size == parameter_size_long) + parameter_size = parameter_size_long_long; + + format++; + + /* The conversion_type type follows. */ + c = (*format); + + /* End of the format string? */ + if(c == '\0') + break; + } + } + #endif /* __GNUC__ */ + + #if defined(FLOATING_POINT_SUPPORT) + { + trail_string[0] = '\0'; + num_trailing_zeroes = 0; + } + #endif /* FLOATING_POINT_SUPPORT */ + + D(("conversion_type (preliminary) = %lc",c)); + + switch(c) + { + /* signed integer */ + case 'i': + + conversion_type = 'd'; + + format++; + break; + + /* unsigned integer (hexadecimal notation) */ + case 'X': + + SET_FLAG(format_flags,FORMATF_CapitalLetters); + + conversion_type = 'x'; + + format++; + break; + + /* floating point number (exponential notation) */ + case 'E': + + SET_FLAG(format_flags,FORMATF_CapitalLetters); + + conversion_type = 'e'; + + format++; + break; + + /* floating point number (plain or exponential notation) */ + case 'G': + + SET_FLAG(format_flags,FORMATF_CapitalLetters); + + conversion_type = 'g'; + + format++; + break; + + /* pointer (hexadecimal notation, eight digits, '0x' prefix) */ + case 'p': + + conversion_type = 'x'; + + SET_FLAG(format_flags,FORMATF_AlternateConversion); + + fill_character = '0'; + minimum_field_width = 8; + + format++; + break; + + case 'c': /* character */ + case 'd': /* signed integer */ + case 'f': /* floating point number */ + case 'e': /* floating point number (exponential notation) */ + case 'g': /* floating point number (plain or exponential notation) */ + case 's': /* string */ + case '%': /* % character */ + case 'o': /* unsigned integer (octal notation) */ + case 'x': /* unsigned integer (hexadecimal notation) */ + case 'u': /* unsigned integer */ + case 'n': /* number of characters written */ + default: /* anything else (% works as escape character) */ + + conversion_type = c; + format++; + break; + } + + D(("conversion_type (final) = %lc",conversion_type)); + + output_buffer = &buffer[sizeof(buffer)-1]; + (*output_buffer) = '\0'; + + output_len = 0; + + if(conversion_type == 'c') + { + int ch; + + SHOWMSG("character"); + + assert(arg != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + result = EOF; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(parameter_size == parameter_size_short) + { + /* Parameter is a short integer which + * must be cast to a long integer before + * it can be used. + */ + short short_integer; + + short_integer = (short)va_arg(arg, int); + + ch = short_integer; + } + else + { + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + { + if(parameter_size == parameter_size_long_long) + ch = va_arg(arg, long long); + else + ch = va_arg(arg, int); + } + #else + { + ch = va_arg(arg, int); + } + #endif /* __GNUC__ */ + } + + D(("output = %lc",ch)); + + output_buffer--; + output_len++; + + (*output_buffer) = ch; + + CLEAR_FLAG(format_flags,FORMATF_ProduceSign); + CLEAR_FLAG(format_flags,FORMATF_ProduceSpace); + } + else if (conversion_type == 'e' || + conversion_type == 'f' || + conversion_type == 'g') + { + SHOWMSG("floating point format"); + + assert(arg != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + result = EOF; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + #if defined(FLOATING_POINT_SUPPORT) + { + const char * buffer_stop = &buffer[sizeof(buffer)-1]; + char * buffer_start = buffer; + + long double v; + + output_buffer = buffer_start; + + D(("sizeof(long double) == %ld",sizeof(v))); + + if(parameter_size == parameter_size_long_double) + v = va_arg(arg, long double); + else + v = va_arg(arg, double); + + if(__is_infinity(fabs(v))) + { + SHOWMSG("infinity"); + + strcpy(output_buffer,"Inf"); + output_len = 3; + + if(v < 0.0) + SET_FLAG(format_flags,FORMATF_IsNegative); + + fill_character = ' '; + } + else if (__is_not_a_number(v)) + { + SHOWMSG("not a number"); + + strcpy(output_buffer,"NaN"); + output_len = 3; + + if(FLAG_IS_SET(format_flags,FORMATF_ProduceSign)) + { + SET_FLAG(format_flags,FORMATF_ProduceSpace); + + CLEAR_FLAG(format_flags,FORMATF_ProduceSign); + } + + fill_character = ' '; + } + else + { + BOOL strip_trailing_zeroes = FALSE; + long double roundoff_fudge = 0.0; + int max_digits = -1; + int exponent = 0; + int digit; + int i; + + /* This takes care of the sign. */ + if(v < 0.0) + { + SHOWMSG("negative number"); + + SET_FLAG(format_flags,FORMATF_IsNegative); + v = (-v); + } + + D(("sizeof(v) == %ld",sizeof(v))); + + #if DEBUG + { + unsigned long n[2]; + + memcpy(n,&v,sizeof(n)); + + D(("v = 0x%08lx%08lx",n[0],n[1])); + } + #endif /* DEBUG */ + + /* Default precision is 6 digits. */ + if(precision < 0) + { + SHOWMSG("no precision specified, using six digits"); + precision = 6; + } + + /* Figure out whether 'e' or 'f' format should be used. */ + if(conversion_type == 'g' || conversion_type == 'e') + { + long double local_v = v; + int local_exponent = 0; + + /* Put one single digit in front of the decimal point. */ + while(local_v != 0.0 && local_v < 1.0) + { + local_v *= 10.0; + local_exponent--; + } + + while(local_v >= 10.0) + { + local_v /= 10.0; + local_exponent++; + } + + if(conversion_type == 'g') + { + /* If the precision is < 1, then it defaults to 1. */ + if(precision < 1) + precision = 1; + + SHOWVALUE(local_exponent); + SHOWVALUE(local_precision); + + /* If the exponent is < -4 or greater than or equal to + * the precision, we switch to 'e' or 'f' format, + * respectively. + */ + if((local_exponent < -4) || local_exponent >= precision) + conversion_type = 'e'; + else + conversion_type = 'f'; + + max_digits = precision; + + strip_trailing_zeroes = TRUE; + } + + if(conversion_type == 'e') + { + v = local_v; + exponent = local_exponent; + } + } + + D(("conversion_type is now %lc",conversion_type)); + + /* If necessary, perform rounding after the + last digit to be displayed. */ + if(max_digits > 0) + { + int roundoff_position; + + if(v >= 1.0) + roundoff_position = max_digits - get_num_leading_digits(v); + else + roundoff_position = max_digits; + + if(roundoff_position >= 0) + roundoff_fudge = pow(10.0,(double)(roundoff_position + 1)); + } + else + { + roundoff_fudge = pow(10.0,(double)(precision + 1)); + } + + if(roundoff_fudge > 0.0) + v += 5.0 / roundoff_fudge; + + /* The rounding may have caused an overflow, putting + two digits in front of the decimal point. This + needs to be corrected. */ + if(conversion_type == 'e') + { + while(v >= 10.0) + { + v /= 10.0; + exponent++; + } + } + + SHOWMSG("integral part"); + + if(v >= 1.0) + { + int num_leading_digits; + + /* 'Normalize' the number so that we have a zero in + front of the mantissa. We can't lose here: we + simply scale the value without any loss of + precision (we just change the floating point + exponent). */ + num_leading_digits = get_num_leading_digits(v); + + v /= pow(10.0,(double)num_leading_digits); + + for(i = 0 ; (max_digits != 0) && (i < num_leading_digits) && (output_buffer < buffer_stop) ; i++) + { + v *= 10.0; + + digit = floor(v); + + D(("next digit = %lc (digit = %ld)",'0' + digit,digit)); + + assert( 0 <= digit && digit <= 9 ); + + (*output_buffer++) = '0' + digit; + + v -= digit; + + if(max_digits > 0) + max_digits--; + } + } + else + { + /* NOTE: any 'significant' digits (for %g conversion) + will follow the decimal point. */ + (*output_buffer++) = '0'; + } + + /* Now for the fractional part. */ + if(precision > 0) + { + SHOWMSG("mantissa"); + + if((max_digits != 0) && (output_buffer < buffer_stop)) + { + (*output_buffer++) = '.'; + + for(i = 0 ; (max_digits != 0) && (i < precision) && (output_buffer < buffer_stop) ; i++) + { + v *= 10.0; + + digit = floor(v); + + D(("next digit = %lc",'0' + digit)); + + assert( 0 <= digit && digit <= 9 ); + + (*output_buffer++) = '0' + digit; + + v -= digit; + + if(max_digits > 0) + max_digits--; + } + + if(i < precision && max_digits != 0 && NOT strip_trailing_zeroes) + { + num_trailing_zeroes = precision - i; + + if(max_digits > 0 && max_digits < num_trailing_zeroes) + num_trailing_zeroes = max_digits; + } + } + + /* Strip trailing digits and decimal point + * unless we shouldn't. + */ + if(strip_trailing_zeroes && FLAG_IS_CLEAR(format_flags,FORMATF_AlternateConversion)) + { + SHOWMSG("strip trailing zeroes and comma"); + + while(output_buffer > buffer_start+1 && output_buffer[-1] == '0') + output_buffer--; + + if(output_buffer > buffer_start && output_buffer[-1] == '.') + output_buffer--; + } + } + else + { + /* Precision is zero; if the alternative conversion flag + * is specified, add the lonely decimal point. + */ + if(FLAG_IS_SET(format_flags,FORMATF_AlternateConversion)) + { + if(output_buffer < buffer_stop) + (*output_buffer++) = '.'; + } + } + + #if DEBUG + { + (*output_buffer) = '\0'; + + output_len = output_buffer - buffer_start; + + assert(output_len < (int)sizeof(buffer)); + + D(("length = %ld, output_buffer = '%s'",output_len,buffer_start)); + } + #endif /* DEBUG */ + + if(conversion_type == 'e') + { + /* For 'long double' the exponent is 15 bits in size, which + allows for a minimum of -16384 to be used. Eight digits + for the exponent should be plenty. */ + char exponent_string[8]; + size_t exponent_string_len,j; + int exponent_sign; + + /* Build the exponent string in reverse order. */ + exponent_string_len = 0; + + if(exponent < 0) + { + exponent_sign = -1; + + exponent = (-exponent); + } + else + { + exponent_sign = 1; + } + + while(exponent > 0 && exponent_string_len < sizeof(exponent_string)) + { + exponent_string[exponent_string_len++] = '0' + (exponent % 10); + + exponent /= 10; + } + + /* Minimum length of the exponent is two digits. */ + while(exponent_string_len < 2) + exponent_string[exponent_string_len++] = '0'; + + if(exponent_string_len < sizeof(exponent_string)-1) + { + if(exponent_sign < 0) + exponent_string[exponent_string_len++] = '-'; + else + exponent_string[exponent_string_len++] = '+'; + + if(FLAG_IS_SET(format_flags,FORMATF_CapitalLetters)) + exponent_string[exponent_string_len++] = 'E'; + else + exponent_string[exponent_string_len++] = 'e'; + } + + /* Add the exponent string in reverse order. */ + for(j = 0 ; exponent_string_len > 0 ; j++) + trail_string[j] = exponent_string[--exponent_string_len]; + + trail_string[j] = '\0'; + } + + (*output_buffer) = '\0'; + + output_len = output_buffer - buffer_start; + output_buffer = buffer_start; + + assert(output_len < (int)sizeof(buffer)); + + D(("length = %ld, output_buffer = '%s'",output_len,output_buffer)); + } + } + #else + { + /* Remove the parameter from the argument vector and + don't produce any output. */ + if(parameter_size == parameter_size_long_double) + (void)va_arg(arg, long double); + else + (void)va_arg(arg, double); + + #ifndef NDEBUG + { + output_buffer = "*FLOATING POINT NUMBER*"; + output_len = strlen(output_buffer); + } + #endif /* NDEBUG */ + + CLEAR_FLAG(format_flags,FORMATF_ProduceSign); + CLEAR_FLAG(format_flags,FORMATF_ProduceSpace); + } + #endif /* FLOATING_POINT_SUPPORT */ + } + else if (conversion_type == 'd' || + conversion_type == 'o' || + conversion_type == 'u' || + conversion_type == 'x') + { + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + unsigned long long v; + #else + unsigned int v; + #endif /* __GNUC__ */ + + assert(arg != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + result = EOF; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(conversion_type == 'd') + { + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + long long sv; + #else + int sv; + #endif /* __GNUC__ */ + + SHOWMSG("signed integer"); + + if(parameter_size == parameter_size_short) + { + /* Parameter is a short integer which + * must be cast to a long integer before + * it can be used. + */ + short short_integer; + + short_integer = (short)va_arg(arg, int); + + sv = short_integer; + } + else + { + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + { + if(parameter_size == parameter_size_long_long) + sv = va_arg(arg, long long); + else + sv = va_arg(arg, int); + } + #else + { + sv = va_arg(arg, int); + } + #endif /* __GNUC__ */ + } + + if(sv < 0) + { + SHOWMSG("negative number"); + + SET_FLAG(format_flags,FORMATF_IsNegative); + + v = (-sv); + } + else + { + v = sv; + } + } + else + { + if(conversion_type == 'o') + SHOWMSG("unsigned integer (octal notation)"); + else if (conversion_type == 'x') + SHOWMSG("unsigned integer (hexadecimal notation)"); + else + SHOWMSG("unsigned integer"); + + if(parameter_size == parameter_size_short) + { + /* Parameter is a short integer which + * must be cast to a long integer before + * it can be used. + */ + unsigned short short_integer; + + short_integer = (unsigned short)va_arg(arg, unsigned int); + + v = short_integer; + } + else + { + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + { + if(parameter_size == parameter_size_long_long) + v = va_arg(arg, unsigned long long); + else + v = va_arg(arg, unsigned int); + } + #else + { + v = va_arg(arg, unsigned int); + } + #endif /* __GNUC__ */ + } + + CLEAR_FLAG(format_flags,FORMATF_ProduceSign); + CLEAR_FLAG(format_flags,FORMATF_ProduceSpace); + } + + /* Don't print anything if the precision is 0 and the number + itself is 0. */ + if(v != 0 || precision != 0) + { + const char * digit_encoding; + int base; + + if(conversion_type == 'o') + base = 8; + else if (conversion_type == 'x') + base = 16; + else + base = 10; + + if(FLAG_IS_SET(format_flags,FORMATF_CapitalLetters)) + digit_encoding = "0123456789ABCDEF"; + else + digit_encoding = "0123456789abcdef"; + + do + { + output_buffer--; + output_len++; + + (*output_buffer) = digit_encoding[v % base]; + v /= base; + } + while(v > 0 && buffer < output_buffer); + + if(FLAG_IS_SET(format_flags,FORMATF_AlternateConversion)) + { + if(conversion_type == 'o') + SET_FLAG(format_flags,FORMATF_ZeroPrefix); + else if (conversion_type == 'x') + SET_FLAG(format_flags,FORMATF_HexPrefix); + } + + while(output_len < precision && output_buffer > buffer) + { + output_buffer--; + output_len++; + + (*output_buffer) = '0'; + } + } + } + else if (conversion_type == 's') + { + SHOWMSG("string"); + + assert(arg != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + result = EOF; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + output_buffer = va_arg(arg, char *); + + #if defined(NDEBUG) + { + if(output_buffer == NULL) + output_buffer = ""; + } + #else + { + if(output_buffer == NULL) + output_buffer = "*NULL POINTER*"; + } + #endif /* NDEBUG */ + + if(precision < 0) + { + output_len = strlen(output_buffer); + } + else + { + int i; + + output_len = precision; + + for(i = 0 ; i < precision ; i++) + { + if(output_buffer[i] == '\0') + { + output_len = i; + break; + } + } + } + + D(("string = '%s', length = %ld",output_buffer,output_len)); + + CLEAR_FLAG(format_flags,FORMATF_ProduceSign); + CLEAR_FLAG(format_flags,FORMATF_ProduceSpace); + } + else if (conversion_type == 'n') + { + SHOWMSG("number of characters"); + + assert(arg != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + result = EOF; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(parameter_size == parameter_size_short) + { + short * short_ptr; + + short_ptr = va_arg(arg, short *); + + assert( short_ptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(short_ptr == NULL) + { + errno = EFAULT; + result = EOF; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + (*short_ptr) = len; + } + else + { + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + { + if(parameter_size == parameter_size_long_long) + { + long long * int_ptr; + + int_ptr = va_arg(arg, long long *); + + assert( int_ptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(int_ptr == NULL) + { + errno = EFAULT; + result = EOF; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + (*int_ptr) = len; + } + else + { + int * int_ptr; + + int_ptr = va_arg(arg, int *); + + assert( int_ptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(int_ptr == NULL) + { + errno = EFAULT; + result = EOF; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + (*int_ptr) = len; + } + } + #else + { + int * int_ptr; + + int_ptr = va_arg(arg, int *); + + assert( int_ptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(int_ptr == NULL) + { + errno = EFAULT; + result = EOF; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + (*int_ptr) = len; + } + #endif /* __GNUC__ */ + } + + continue; + } + else + { + SHOWMSG("anything else"); + + /* Just store the conversion_type character. */ + if(__putc(conversion_type,stream,buffer_mode) == EOF) + goto out; + + len++; + + continue; + } + + /* Get ready to prefix a sign character, if required. */ + if(FLAG_IS_SET(format_flags,FORMATF_IsNegative)) + { + prefix = "-"; + } + else if (FLAG_IS_SET(format_flags,FORMATF_ProduceSign)) + { + prefix = "+"; + } + else if (FLAG_IS_SET(format_flags,FORMATF_ProduceSpace)) + { + prefix = " "; + } + else if (FLAG_IS_SET(format_flags,FORMATF_ZeroPrefix)) + { + prefix = "0"; + } + else if (FLAG_IS_SET(format_flags,FORMATF_HexPrefix)) + { + if(FLAG_IS_SET(format_flags,FORMATF_CapitalLetters)) + prefix = "0X"; + else + prefix = "0x"; + } + else + { + prefix = NULL; + } + + if(FLAG_IS_SET(format_flags,FORMATF_LeftJustified)) + { + int i; + + if(prefix != NULL) + { + for(i = 0 ; prefix[i] != '\0' ; i++) + { + /* One less character to fill the output with. */ + minimum_field_width--; + + if(__putc(prefix[i],stream,buffer_mode) == EOF) + goto out; + + len++; + } + } + + for(i = 0 ; i < output_len ; i++) + { + if(__putc(output_buffer[i],stream,buffer_mode) == EOF) + goto out; + + len++; + } + + #if defined(FLOATING_POINT_SUPPORT) + { + for(i = 0 ; i < num_trailing_zeroes ; i++) + { + if(__putc('0',stream,buffer_mode) == EOF) + goto out; + + output_len++; + len++; + } + + for(i = 0 ; trail_string[i] != '\0' ; i++) + { + if(__putc(trail_string[i],stream,buffer_mode) == EOF) + goto out; + + output_len++; + len++; + } + } + #endif /* FLOATING_POINT_SUPPORT */ + + for(i = output_len ; i < minimum_field_width ; i++) + { + /* Left justified output defaults to use the blank + space as the fill character. */ + if(__putc(' ',stream,buffer_mode) == EOF) + goto out; + + len++; + } + } + else + { + int i; + + /* If we have to add the prefix later, make sure that + we don't add too many fill characters in front of + it now. */ + if(prefix != NULL) + { + for(i = 0 ; prefix[i] != '\0' ; i++) + { + /* One less character to fill the output with. */ + minimum_field_width--; + + if(fill_character == '0') + { + if(__putc(prefix[i],stream,buffer_mode) == EOF) + goto out; + + len++; + } + } + + /* That takes care of the sign. */ + if(fill_character == '0') + prefix = NULL; + } + + #if defined(FLOATING_POINT_SUPPORT) + { + trail_string_len = strlen(trail_string); + + minimum_field_width -= num_trailing_zeroes + trail_string_len; + } + #endif /* FLOATING_POINT_SUPPORT */ + + for(i = output_len ; i < minimum_field_width ; i++) + { + if(__putc(fill_character,stream,buffer_mode) == EOF) + goto out; + + len++; + } + + /* If we still have a sign character to add, do it here. */ + if(prefix != NULL) + { + for(i = 0 ; prefix[i] != '\0' ; i++) + { + if(__putc(prefix[i],stream,buffer_mode) == EOF) + goto out; + + len++; + } + } + + for(i = 0 ; i < output_len ; i++) + { + if(__putc(output_buffer[i],stream,buffer_mode) == EOF) + goto out; + + len++; + } + + #if defined(FLOATING_POINT_SUPPORT) + { + for(i = 0 ; i < num_trailing_zeroes ; i++) + { + if(__putc('0',stream,buffer_mode) == EOF) + goto out; + + len++; + } + + for(i = 0 ; i < trail_string_len ; i++) + { + if(__putc(trail_string[i],stream,buffer_mode) == EOF) + goto out; + + len++; + } + } + #endif /* FLOATING_POINT_SUPPORT */ + } + } + + if(FLAG_IS_CLEAR(iob->iob_Flags,IOBF_NO_NUL)) + { + if(__putc('\0',stream,buffer_mode) == EOF) + goto out; + } + + result = len; + + out: + + /* Note: if buffering is disabled for this stream, then we still + may have buffered data around, queued to be printed right now. + This is intended to improve performance as it takes more effort + to write a single character to a file than to write a bunch. */ + if(result > 0 && (iob->iob_Flags & IOBF_BUFFER_MODE) == IOBF_BUFFER_MODE_NONE) + { + if(__iob_write_buffer_is_valid(iob) && __flush_iob_write_buffer(iob) < 0) + result = EOF; + } + + RETURN(result); + return(result); +} diff --git a/library/stdio_vfscanf.c b/library/stdio_vfscanf.c new file mode 100644 index 0000000..69914c8 --- /dev/null +++ b/library/stdio_vfscanf.c @@ -0,0 +1,1579 @@ +/* + * $Id: stdio_vfscanf.c,v 1.1.1.1 2004-07-26 16:31:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +/* + * Uncomment this to activate '%lld' support and the like. Better still, + * define this is in the Makefile! + */ +/*#define USE_64_BIT_INTS*/ + +/****************************************************************************/ + +int +__vfscanf(FILE *stream, const char *format, va_list arg) +{ + enum format_size_t + { + format_size_default, + format_size_long, + format_size_long_long, + format_size_short, + format_size_long_double + }; + + enum format_size_t format_size; + int total_num_chars_read = 0; + int num_chars_processed; + BOOL assignment_suppressed; + int maximum_field_width; + int result = EOF; + int num_conversions = 0; + int num_assignments = 0; + int conversion_type; + int c; + + ENTER(); + + assert( stream != NULL && format != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(stream == NULL || format == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__fgetc_check(stream) != OK) + goto out; + + /* Just so we can detect errors and tell them apart from + an 'end of file' condition. */ + clearerr(stream); + + while((c = (*(unsigned char *)format)) != '\0') + { + D(("next format character is '%lc'",c)); + + if(isspace(c)) + { + BOOL finished = FALSE; + + /* Skip all blank spaces in the stream. */ + format++; + + while(TRUE) + { + c = __getc(stream); + if(c == EOF) + { + /* Hit the end of the stream. Due to an error? */ + if(num_conversions == 0 || ferror(stream)) + goto out; + + finished = TRUE; + break; + } + else if (isspace(c)) + { + total_num_chars_read++; + } + else + { + /* End of the white space; we push the last + * character read back into the stream. + */ + if(ungetc(c,stream) == EOF) + goto out; + + /* Resume scanning. */ + break; + } + } + + if(finished) + break; + + /* Resume scanning. */ + continue; + } + else if (c != '%') + { + int d; + + SHOWMSG("next character must match exactly"); + + /* Match the next character in the stream. */ + format++; + + d = __getc(stream); + if(d == EOF) + { + SHOWMSG("end of file"); + + /* Hit the end of the stream. Due to an error? */ + if(num_conversions == 0 || ferror(stream)) + goto out; + + break; + } + else if (c == d) + { + SHOWMSG("it matches"); + + total_num_chars_read++; + } + else + { + SHOWMSG("it does not match"); + + if(ungetc(d,stream) == EOF) + goto out; + + break; + } + + /* Resume scanning. */ + continue; + } + + format++; + + c = (*format); + + if(c == '*') + { + /* If the first letter of the format specification + * is an asterisk, no output will be produced for + * this parameter. + */ + assignment_suppressed = TRUE; + + format++; + + c = (*format); + } + else + { + assignment_suppressed = FALSE; + } + + maximum_field_width = -1; + + if('0' <= c && c <= '9') + { + int next_sum; + int sum = 0; + + /* This could be the field width specification. */ + while(TRUE) + { + c = (*format); + + if('0' <= c && c <= '9') + { + next_sum = (10 * sum) + c - '0'; + if(next_sum < sum) /* overflow? */ + break; + + sum = next_sum; + format++; + } + else + { + break; + } + } + + maximum_field_width = sum; + } + else if (c == '\0') + { + /* And that's the end of the string. */ + break; + } + + c = (*format); + + if(c == 'h') + { + /* Parameter is a short integer. */ + format_size = format_size_short; + format++; + } + else if (c == 'l') + { + /* Parameter is a long integer or a double precision floating point value. */ + format_size = format_size_long; + format++; + } + else if (c == 'L') + { + /* Parameter is a long double floating point value. */ + format_size = format_size_long_double; + format++; + } + else if (c == '\0') + { + /* And that's the end of the string. */ + break; + } + else + { + /* Parameter is a long integer or a single precision floating point value. */ + format_size = format_size_default; + } + + /* Now for the conversion type. */ + c = (*format); + if(c == '\0') + break; + + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + { + /* Check for long long parameters. */ + if(c == 'l') + { + if(format_size == format_size_long) + format_size = format_size_long_long; + + format++; + + /* The conversion type follows. */ + c = (*format); + if(c == '\0') + break; + } + } + #endif /* __GNUC__ */ + + switch(c) + { + /* It's a pointer. */ + case 'p': + + conversion_type = 'x'; + format++; + break; + + /* It's a floating point number. */ + case 'f': + case 'e': + case 'g': + + conversion_type = 'f'; + format++; + break; + + case 'c': /* character(s) */ + case 'd': /* signed integer */ + case 'i': /* signed integer in decimal, octal or hexadecimal format */ + case 'n': /* number of characters processed */ + case 'o': /* integer (octal) */ + case 's': /* string */ + case 'u': /* unsigned integer */ + case 'x': /* unsigned integer in hexadecimal format */ + case '%': /* the % character */ + case '[': /* a range of characters */ + + conversion_type = c; + format++; + break; + + default: + + /* Must be something else */ + continue; + } + + /* Skip any initial whitespace characters. Exceptions are %c, %n and %[. */ + if(conversion_type != 'c' && + conversion_type != 'n' && + conversion_type != '[') + { + BOOL finished = FALSE; + + while(TRUE) + { + c = __getc(stream); + if(c == EOF) + { + /* Hit the end of the stream. Due to an error? */ + if(num_conversions == 0 || ferror(stream)) + goto out; + + finished = TRUE; + break; + } + else if (isspace(c)) + { + total_num_chars_read++; + } + else + { + /* End of the white space; we push the last + * character read back into the stream. + */ + if(ungetc(c,stream) == EOF) + goto out; + + /* Proceed with the conversion operation. */ + break; + } + } + + if(finished) + break; + } + + num_chars_processed = 0; + + D(("conversion type = '%lc'",c)); + + if(conversion_type == 'c') + { + char * c_ptr; + int i; + + /* The maximum field width is actually the number + * of characters that should be read. Default is + * 1 character. + */ + if(maximum_field_width < 0) + maximum_field_width = 1; + + if(NOT assignment_suppressed) + { + assert( arg != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + c_ptr = va_arg(arg,char *); + + assert( c_ptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(c_ptr == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + } + else + { + c_ptr = NULL; + } + + for(i = 0 ; i < maximum_field_width ; i++) + { + c = __getc(stream); + if(c == EOF) + { + /* Bail out if we hit the end of the stream or an error occured. */ + if(num_conversions == 0 || ferror(stream)) + goto out; + + break; + } + + total_num_chars_read++; + + if(NOT assignment_suppressed) + (*c_ptr++) = c; + + num_chars_processed++; + } + + /* Did we read as many characters as we wanted? */ + if(num_chars_processed != maximum_field_width) + break; + + if(NOT assignment_suppressed) + num_assignments++; + + num_conversions++; + } + else if (conversion_type == 'f') + { + #if defined(FLOATING_POINT_SUPPORT) + { + long double sum = 0.0; + long double new_sum; + BOOL is_negative = FALSE; + BOOL decimal_point_matches = FALSE; + BOOL have_exponent = FALSE; + void * next_parameter = NULL; + + /* We boldly try to initialize the parameter to a well- + defined value before we begin the conversion. */ + if(NOT assignment_suppressed) + { + assert( arg != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(format_size == format_size_default) + { + SHOWMSG("short format (float)"); + + next_parameter = va_arg(arg,float *); + } + else if (format_size == format_size_long) + { + SHOWMSG("long format (double)"); + + next_parameter = va_arg(arg,double *); + } + else + { + SHOWMSG("extended format (long double)"); + + next_parameter = va_arg(arg,long double *); + } + + assert( next_parameter != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(next_parameter == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(format_size == format_size_default) + { + *((float *)next_parameter) = 0; + } + else if (format_size == format_size_long) + { + *((double *)next_parameter) = 0; + } + else + { + *((long double *)next_parameter) = 0; + } + } + + if(maximum_field_width != 0) + { + c = __getc(stream); + if(c != EOF) + { + /* Skip the sign. */ + if(c == '-') + { + SHOWMSG("negative floating point number"); + + is_negative = 1; + + total_num_chars_read++; + + if(maximum_field_width > 0) + maximum_field_width--; + } + else if (c == '+') + { + SHOWMSG("ignoring positive sign"); + + total_num_chars_read++; + + if(maximum_field_width > 0) + maximum_field_width--; + } + else + { + D(("first character '%lc' is not a sign",c)); + + /* It's not a sign; reread this later. */ + if(ungetc(c,stream) == EOF) + { + SHOWMSG("couldn't push this character back"); + goto out; + } + } + } + } + + if(maximum_field_width != 0) + { + while(maximum_field_width != 0 && (c = __getc(stream)) != EOF) + { + /* Is this a digit? */ + if('0' <= c && c <= '9') + { + D(("got another digit '%lc'",c)); + + new_sum = (10 * sum) + (c - '0'); + if(new_sum < sum) /* overflow? */ + { + /* Put this back. */ + if(ungetc(c,stream) == EOF) + { + SHOWMSG("couldn't push this character back"); + goto out; + } + + break; + } + + sum = new_sum; + } + else + { + D(("'%lc' is not a digit",c)); + + /* It's not a digit; reread this later. */ + if(ungetc(c,stream) == EOF) + { + SHOWMSG("couldn't push this character back"); + goto out; + } + + break; + } + + total_num_chars_read++; + num_chars_processed++; + + if(maximum_field_width > 0) + maximum_field_width--; + } + + if(c == EOF && ((num_chars_processed == 0 && num_conversions == 0) || ferror(stream))) + goto out; + } + + if(maximum_field_width != 0) + { + SHOWMSG("looking for decimal point"); + + c = __getc(stream); + if(c != EOF) + { + /* Did we find the decimal point? We accept both the + * locale configured decimal point and the plain old + * dot. + */ + if(__locale_table[LC_NUMERIC] != NULL) + { + unsigned char * point; + + point = (unsigned char *)__locale_table[LC_NUMERIC]->loc_DecimalPoint; + + if(c == (*point) || c == '.') + { + SHOWMSG("found a decimal point"); + + decimal_point_matches = TRUE; + } + else + { + D(("'%lc' is not a decimal point",c)); + } + } + else + { + if(c == '.') + { + SHOWMSG("found a decimal point"); + + decimal_point_matches = TRUE; + } + else + { + D(("'%lc' is not a decimal point",c)); + } + } + + if(decimal_point_matches) + { + total_num_chars_read++; + + if(maximum_field_width > 0) + maximum_field_width--; + } + else if (c == 'e' || c == 'E') + { + SHOWMSG("found an exponent specifier"); + + total_num_chars_read++; + + have_exponent = TRUE; + + if(maximum_field_width > 0) + maximum_field_width--; + } + else + { + if(ungetc(c,stream) == EOF) + { + SHOWMSG("couldn't push this character back"); + goto out; + } + } + } + + if(decimal_point_matches) + { + double multiplier = 0.1; + + SHOWMSG("found a decimal point"); + + /* Process all digits following the decimal point. */ + while(maximum_field_width != 0 && (c = __getc(stream)) != EOF) + { + if('0' <= c && c <= '9') + { + if(multiplier != 0.0) + { + new_sum = sum + (c - '0') * multiplier; + if(new_sum < sum) /* overflow? */ + { + SHOWMSG("got an overflow"); + + /* Put this back. */ + if(ungetc(c,stream) == EOF) + { + SHOWMSG("couldn't push this character back"); + goto out; + } + + break; + } + + sum = new_sum; + + multiplier = multiplier / 10.0; + } + + total_num_chars_read++; + + if(maximum_field_width > 0) + maximum_field_width--; + } + else if (c == 'e' || c == 'E') + { + SHOWMSG("found an exponent specifier"); + + total_num_chars_read++; + + if(maximum_field_width > 0) + maximum_field_width--; + + have_exponent = TRUE; + break; + } + else + { + if(ungetc(c,stream) == EOF) + { + SHOWMSG("couldn't push this character back"); + goto out; + } + + break; + } + } + } + + if(have_exponent) + { + BOOL exponent_is_negative = FALSE; + int new_exponent; + int exponent = 0; + + SHOWMSG("processing exponent"); + + if(maximum_field_width != 0) + { + c = __getc(stream); + if(c != EOF) + { + /* Skip the sign. */ + if(c == '-') + { + exponent_is_negative = TRUE; + + total_num_chars_read++; + + if(maximum_field_width > 0) + maximum_field_width--; + } + else if (c == '+') + { + total_num_chars_read++; + + if(maximum_field_width > 0) + maximum_field_width--; + } + else + { + /* It's not a sign; reread this later. */ + if(ungetc(c,stream) == EOF) + { + SHOWMSG("couldn't push this character back"); + goto out; + } + } + + while(maximum_field_width != 0 && (c = __getc(stream)) != EOF) + { + if('0' <= c && c <= '9') + { + new_exponent = (10 * exponent) + (c - '0'); + if(new_exponent < exponent) /* overflow? */ + { + if(ungetc(c,stream) == EOF) + { + SHOWMSG("couldn't push this character back"); + goto out; + } + + break; + } + + exponent = new_exponent; + + total_num_chars_read++; + + if(maximum_field_width > 0) + maximum_field_width--; + } + else + { + if(ungetc(c,stream) == EOF) + { + SHOWMSG("couldn't push this character back"); + goto out; + } + + break; + } + } + + /* If the exponent is valid, scale the number + * accordingly. + */ + if(exponent != 0) + { + if(exponent_is_negative) + { + double divisor; + + /* A negative exponent means division. */ + divisor = pow(10.0,(double)exponent); + if(divisor != 0.0) + sum = sum / divisor; + } + else + { + /* A positive exponent means multiplication. */ + new_sum = sum * pow(10.0,(double)exponent); + if(new_sum >= sum) + sum = new_sum; + else + sum = HUGE_VAL; + } + } + } + } + } + } + + SHOWMSG("conversion finished.."); + + if(num_chars_processed > 0) + { + if(NOT assignment_suppressed) + { + if(is_negative) + sum = (-sum); + + if(format_size == format_size_default) + { + *((float *)next_parameter) = sum; + } + else if (format_size == format_size_long) + { + *((double *)next_parameter) = sum; + } + else + { + *((long double *)next_parameter) = sum; + } + + num_assignments++; + } + + num_conversions++; + } + } + #else + { + if(NOT assignment_suppressed) + { + void * next_parameter; + + assert( arg != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(format_size == format_size_default) + { + SHOWMSG("short format (float)"); + + next_parameter = va_arg(arg,float *); + } + else if (format_size == format_size_long) + { + SHOWMSG("long format (double)"); + + next_parameter = va_arg(arg,double *); + } + else + { + SHOWMSG("extended format (long double)"); + + next_parameter = va_arg(arg,long double *); + } + + assert( next_parameter != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(next_parameter == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + } + } + #endif /* FLOATING_POINT_SUPPORT */ + } + else if (conversion_type == 'd' || + conversion_type == 'i' || + conversion_type == 'o' || + conversion_type == 'u' || + conversion_type == 'x') + { + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + long long next_sum; + long long sum = 0; + #else + int next_sum; + int sum = 0; + #endif /* __GNUC__ */ + BOOL is_negative = FALSE; + int base; + void * next_parameter = NULL; + + /* We boldly try to initialize the parameter to a well- + defined value before we begin the conversion. */ + if(NOT assignment_suppressed) + { + assert( arg != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(format_size == format_size_short) + { + next_parameter = va_arg(arg,short *); + } + else + { + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + { + if(format_size == format_size_long_long) + next_parameter = va_arg(arg,long long *); + else + next_parameter = va_arg(arg,int *); + } + #else + { + next_parameter = va_arg(arg,int *); + } + #endif /* __GNUC__ */ + } + + assert( next_parameter != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(next_parameter == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(format_size == format_size_short) + { + *((short *)next_parameter) = 0; + } + else + { + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + { + if(format_size == format_size_long_long) + *((long long *)next_parameter) = 0; + else + *((int *)next_parameter) = 0; + } + #else + { + *((int *)next_parameter) = 0; + } + #endif /* __GNUC__ */ + } + } + + if(conversion_type == 'd' || conversion_type == 'u') + base = 10; + else if (conversion_type == 'o') + base = 8; + else + base = 0; + + if(maximum_field_width != 0) + { + c = __getc(stream); + if(c != EOF) + { + /* Skip the sign. */ + if(c == '-') + { + is_negative = TRUE; + + total_num_chars_read++; + + if(maximum_field_width > 0) + maximum_field_width--; + } + else if (c == '+') + { + total_num_chars_read++; + + if(maximum_field_width > 0) + maximum_field_width--; + } + else if (c == '0') + { + /* Keep the leading zero. */ + total_num_chars_read++; + num_chars_processed++; + + if(maximum_field_width > 0) + maximum_field_width--; + + if(base == 0 && maximum_field_width != 0) + { + /* This could be an octal number, the + * '0x' prefix or just a zero. + */ + c = __getc(stream); + if (c == 'x' || c == 'X') + { + /* It's the hex prefix. */ + base = 16; + + /* The preceding '0' was part of the + hex prefix. So we don't really know + the number yet. */ + num_chars_processed--; + + total_num_chars_read++; + + if(maximum_field_width > 0) + maximum_field_width--; + } + else if (isdigit(c)) + { + /* The preceding '0' was part of the + octal prefix. So we don't really know + the number yet. */ + num_chars_processed--; + + /* It's an octal number. */ + base = 8; + + /* Process the rest later. */ + if(ungetc(c,stream) == EOF) + goto out; + } + else if (c != EOF) + { + /* It's something else; put it back. */ + if(ungetc(c,stream) == EOF) + goto out; + } + } + } + else + { + if(ungetc(c,stream) == EOF) + goto out; + } + } + } + + /* Pick a base if none has been chosen yet. */ + if(base == 0) + { + if(conversion_type == 'x') + base = 16; + else + base = 10; + } + + if(maximum_field_width != 0) + { + while(maximum_field_width != 0 && (c = __getc(stream)) != EOF) + { + /* Is this a digit or hexadecimal value? */ + if(isxdigit(c)) + { + int digit; + + /* Perform the necessary conversion. */ + if('0' <= c && c <= '9') + digit = c - '0'; + else if ('a' <= c && c <= 'f') + digit = c - 'a' + 10; + else + digit = c - 'A' + 10; + + /* Is this a valid digit? */ + if(digit > base) + { + if(ungetc(c,stream) == EOF) + goto out; + + break; + } + + next_sum = (base * sum) + digit; + + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + { + if(format_size == format_size_long_long && (unsigned long long)next_sum < (unsigned long long)sum) /* overflow? */ + { + /* Put this back. */ + if(ungetc(c,stream) == EOF) + goto out; + + break; + } + else if ((unsigned int)next_sum < (unsigned int)sum) /* overflow? */ + { + /* Put this back. */ + if(ungetc(c,stream) == EOF) + goto out; + + break; + } + } + #else + { + if((unsigned int)next_sum < (unsigned int)sum) /* overflow? */ + { + /* Put this back. */ + if(ungetc(c,stream) == EOF) + goto out; + + break; + } + } + #endif /* __GNUC__ */ + + total_num_chars_read++; + num_chars_processed++; + + sum = next_sum; + + if(maximum_field_width > 0) + maximum_field_width--; + } + else + { + /* It's something else; reread this later. */ + if(ungetc(c,stream) == EOF) + goto out; + + break; + } + } + + if(c == EOF && ((num_chars_processed == 0 && num_conversions == 0) || ferror(stream))) + goto out; + } + + if(num_chars_processed > 0) + { + if(NOT assignment_suppressed) + { + if(is_negative) + sum = (-sum); + + if(format_size == format_size_short) + { + *((short *)next_parameter) = sum; + } + else + { + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + { + if(format_size == format_size_long_long) + *((long long *)next_parameter) = sum; + else + *((int *)next_parameter) = sum; + } + #else + { + *((int *)next_parameter) = sum; + } + #endif /* __GNUC__ */ + } + + num_assignments++; + } + + num_conversions++; + } + } + else if (conversion_type == 's') + { + char * s_ptr; + + if(NOT assignment_suppressed) + { + assert( arg != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + s_ptr = va_arg(arg,char *); + + assert( s_ptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s_ptr == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + } + else + { + s_ptr = NULL; + } + + /* Try to NUL terminate this even in case of failure. */ + if(NOT assignment_suppressed) + (*s_ptr) = '\0'; + + if(maximum_field_width != 0) + { + while(maximum_field_width != 0 && (c = __getc(stream)) != EOF) + { + /* Blank spaces stop the conversion process. */ + if(isspace(c)) + { + if(ungetc(c,stream) == EOF) + goto out; + + break; + } + + total_num_chars_read++; + num_chars_processed++; + + if(NOT assignment_suppressed) + { + (*s_ptr++) = c; + (*s_ptr) = '\0'; /* Try to NUL terminate this even in case of failure. */ + } + + if(maximum_field_width > 0) + maximum_field_width--; + } + + /* The conversion is considered to have failed if an EOF was + encountered before any non-whitespace characters could be + converted. We also bail out if we hit an error. */ + if(c == EOF && (num_chars_processed == 0 || ferror(stream))) + goto out; + } + + if(NOT assignment_suppressed) + num_assignments++; + + num_conversions++; + } + else if (conversion_type == 'n') + { + if(NOT assignment_suppressed) + { + assert( arg != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(format_size == format_size_short) + { + short * short_ptr; + + short_ptr = va_arg(arg,short *); + + assert( short_ptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(short_ptr == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + (*short_ptr) = total_num_chars_read; + } + else + { + #if defined(USE_64_BIT_INTS) && defined(__GNUC__) + { + if(format_size == format_size_long_long) + { + long long * int_ptr; + + int_ptr = va_arg(arg,long long *); + + assert( int_ptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(int_ptr == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + (*int_ptr) = total_num_chars_read; + } + else + { + int * int_ptr; + + int_ptr = va_arg(arg,int *); + + assert( int_ptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(int_ptr == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + (*int_ptr) = total_num_chars_read; + } + } + #else + { + int * int_ptr; + + int_ptr = va_arg(arg,int *); + + assert( int_ptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(int_ptr == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + (*int_ptr) = total_num_chars_read; + } + #endif /* __GNUC__ */ + } + } + } + else if (c == '%') + { + int d; + + d = __getc(stream); + if(d == EOF) + { + SHOWMSG("end of file"); + + /* Hit the end of the stream. Due to an error? */ + if(num_conversions == 0 || ferror(stream)) + goto out; + + break; + } + else if (c == d) + { + total_num_chars_read++; + } + else + { + /* This is not what we expected. We're finished. */ + if(ungetc(d,stream) == EOF) + goto out; + + break; + } + } + else if (c == '[') + { + char * s_ptr; + char set[256]; + int pick; + + if(NOT assignment_suppressed) + { + assert( arg != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(arg == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + s_ptr = va_arg(arg,char *); + + assert( s_ptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s_ptr == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + } + else + { + s_ptr = NULL; + } + + c = (*format); + if(c == '^') + { + /* Accept only characters which are not found in the range. */ + pick = 0; + + format++; + } + else + { + /* Accept only characters which are found in the range. */ + pick = 1; + } + + memset(set,1 - pick,sizeof(set)); + + /* If the ']' character introduces the range, then + * it is not considered the range termination character. + */ + c = (*format); + if(c == ']') + { + set[c] = pick; + + format++; + } + + /* Collect the other characters to form the range. */ + while((c = (*(unsigned char *)format)) != '\0') + { + format++; + + /* This would end the range. */ + if(c == ']') + break; + + assert( 0 <= c && c <= 255 ); + + set[c] = pick; + } + + /* Try to NUL terminate this even in case of failure. */ + if(NOT assignment_suppressed) + (*s_ptr) = '\0'; + + if(maximum_field_width != 0) + { + while(maximum_field_width != 0 && (c = __getc(stream)) != EOF) + { + assert( 0 <= c && c <= 255 ); + + /* If the character is not part of the + * range we stop further processing. + */ + if(set[c] == 0) + { + if(ungetc(c,stream) == EOF) + goto out; + + break; + } + + if(NOT assignment_suppressed) + { + (*s_ptr++) = c; + (*s_ptr) = '\0'; /* Try to NUL terminate this even in case of failure. */ + } + + total_num_chars_read++; + num_chars_processed++; + + if(maximum_field_width > 0) + maximum_field_width--; + } + + if(c == EOF && ((num_chars_processed == 0 && num_conversions == 0) || ferror(stream))) + goto out; + } + + if(num_chars_processed > 0) + { + if(NOT assignment_suppressed) + num_assignments++; + + num_conversions++; + } + } + } + + if(num_conversions > 0) + result = num_assignments; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_vprintf.c b/library/stdio_vprintf.c new file mode 100644 index 0000000..81d14c9 --- /dev/null +++ b/library/stdio_vprintf.c @@ -0,0 +1,77 @@ +/* + * $Id: stdio_vprintf.c,v 1.1.1.1 2004-07-26 16:31:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +vprintf(const char *format,va_list arg) +{ + int result = -1; + + ENTER(); + + SHOWSTRING(format); + SHOWPOINTER(arg); + + assert( format != NULL && arg != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(format == NULL || arg == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + result = vfprintf(stdout,format,arg); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_vsnprintf.c b/library/stdio_vsnprintf.c new file mode 100644 index 0000000..c106ba5 --- /dev/null +++ b/library/stdio_vsnprintf.c @@ -0,0 +1,120 @@ +/* + * $Id: stdio_vsnprintf.c,v 1.1.1.1 2004-07-26 16:31:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +vsnprintf(char *buffer,size_t size,const char *format,va_list arg) +{ + struct iob string_iob; + int result = EOF; + char local_buffer[32]; + + ENTER(); + + SHOWPOINTER(buffer); + SHOWVALUE(size); + SHOWSTRING(format); + SHOWPOINTER(arg); + + assert( format != NULL && arg != NULL && (int)size >= 0 ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(format == NULL || (buffer == NULL && size > 0)) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + __initialize_iob(&string_iob,(HOOKFUNC)__vsnprintf_hook_entry, + NULL, + local_buffer,sizeof(local_buffer), + -1, + -1, + IOBF_IN_USE | IOBF_WRITE | IOBF_NO_NUL | IOBF_BUFFER_MODE_NONE | IOBF_INTERNAL); + + /* Store up to 'size-1' characters in the output buffer. This + does not include the terminating NUL character, which we + will add later. */ + string_iob.iob_String = (STRPTR)buffer; + string_iob.iob_StringSize = (size > 0) ? (size - 1) : 0; + + /* We will return the number of characters that would have been + stored if there had been enough room. */ + result = vfprintf((FILE *)&string_iob,format,arg); + + /* Figure out how many characters were stored. Fewer than + the output buffer size allows for may have been written + to the buffer. The string needs to be terminated with a + NUL byte behind the last character stored. */ + if(size > 0) + { + assert( string_iob.iob_StringPosition >= 0 ); + assert( string_iob.iob_StringPosition+1 <= size ); + + buffer[string_iob.iob_StringPosition] = '\0'; + + SHOWSTRING(buffer); + } + else + { + SHOWMSG("output buffer is empty"); + } + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdio_vsnprintf_hook_entry.c b/library/stdio_vsnprintf_hook_entry.c new file mode 100644 index 0000000..4dad893 --- /dev/null +++ b/library/stdio_vsnprintf_hook_entry.c @@ -0,0 +1,93 @@ +/* + * $Id: stdio_vsnprintf_hook_entry.c,v 1.1.1.1 2004-07-26 16:31:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +void +__vsnprintf_hook_entry( + struct Hook * UNUSED unused_hook, + struct iob * string_iob, + struct file_hook_message * message) +{ + int result = -1; + int error = OK; + + assert( message != NULL && string_iob != NULL ); + + if(message->action != file_hook_action_write) + { + error = EBADF; + goto out; + } + + if(message->size > 0 && string_iob->iob_StringSize > 0 && string_iob->iob_StringPosition < string_iob->iob_StringSize) + { + int num_bytes_left; + int num_bytes; + + num_bytes_left = string_iob->iob_StringSize - string_iob->iob_StringPosition; + + num_bytes = message->size; + if(num_bytes > num_bytes_left) + num_bytes = num_bytes_left; + + assert( num_bytes >= 0 ); + + assert( message->data != NULL ); + assert( string_iob->iob_String != NULL ); + + memmove(&string_iob->iob_String[string_iob->iob_StringPosition],message->data,(size_t)num_bytes); + string_iob->iob_StringPosition += num_bytes; + } + + result = message->size; + + out: + + message->result = result; + message->error = error; +} diff --git a/library/stdio_vsprintf.c b/library/stdio_vsprintf.c new file mode 100644 index 0000000..58d73e2 --- /dev/null +++ b/library/stdio_vsprintf.c @@ -0,0 +1,82 @@ +/* + * $Id: stdio_vsprintf.c,v 1.1.1.1 2004-07-26 16:31:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +int +vsprintf(char *s,const char *format,va_list arg) +{ + struct iob string_iob; + int result = EOF; + char buffer[32]; + + assert( s != NULL && format != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s == NULL || format == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + __initialize_iob(&string_iob,(HOOKFUNC)__vsprintf_hook_entry, + NULL, + buffer,sizeof(buffer), + -1, + -1, + IOBF_IN_USE | IOBF_WRITE | IOBF_BUFFER_MODE_NONE | IOBF_INTERNAL); + + string_iob.iob_String = (STRPTR)s; + + result = vfprintf((FILE *)&string_iob,format,arg); + + out: + + return(result); +} diff --git a/library/stdio_vsprintf_hook_entry.c b/library/stdio_vsprintf_hook_entry.c new file mode 100644 index 0000000..232ab1c --- /dev/null +++ b/library/stdio_vsprintf_hook_entry.c @@ -0,0 +1,77 @@ +/* + * $Id: stdio_vsprintf_hook_entry.c,v 1.1.1.1 2004-07-26 16:31:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +void +__vsprintf_hook_entry( + struct Hook * UNUSED unused_hook, + struct iob * string_iob, + struct file_hook_message * message) +{ + int result = -1; + int error = OK; + + assert( message != NULL && string_iob != NULL ); + + if(message->action != file_hook_action_write) + { + error = EBADF; + goto out; + } + + assert( message->size >= 0 ); + + assert( message->data != NULL ); + assert( string_iob->iob_StringPosition >= 0 ); + + memmove(&string_iob->iob_String[string_iob->iob_StringPosition],message->data,(size_t)message->size); + string_iob->iob_StringPosition += message->size; + + result = message->size; + + out: + + message->result = result; + message->error = error; +} diff --git a/library/stdlib_abort.c b/library/stdlib_abort.c new file mode 100644 index 0000000..5194e2c --- /dev/null +++ b/library/stdlib_abort.c @@ -0,0 +1,61 @@ +/* + * $Id: stdlib_abort.c,v 1.1.1.1 2004-07-26 16:31:50 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +void +abort(void) +{ + raise(SIGABRT); + + __check_abort_enabled = FALSE; + + __print_termination_message(__abnormal_program_termination); + + /* Note that we drop into the exit() function which + * does not trigger the exit trap. + */ + _exit(EXIT_FAILURE); +} diff --git a/library/stdlib_abs.c b/library/stdlib_abs.c new file mode 100644 index 0000000..9a39496 --- /dev/null +++ b/library/stdlib_abs.c @@ -0,0 +1,48 @@ +/* + * $Id: stdlib_abs.c,v 1.1.1.1 2004-07-26 16:31:50 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +int +abs(int x) +{ + int result; + + result = (x < 0) ? (-x) : x; + + return(result); +} diff --git a/library/stdlib_alloca.c b/library/stdlib_alloca.c new file mode 100644 index 0000000..9228c3b --- /dev/null +++ b/library/stdlib_alloca.c @@ -0,0 +1,160 @@ +/* + * $Id: stdlib_alloca.c,v 1.1.1.1 2004-07-26 16:31:50 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#undef alloca + +extern void * alloca(size_t size); + +/****************************************************************************/ + +struct MemoryContextNode +{ + struct MinNode mcn_MinNode; + ULONG mcn_StackPointer; + char * mcn_Memory; +}; + +/****************************************************************************/ + +extern unsigned long __get_sp(void); + +/****************************************************************************/ + +void +__alloca_cleanup(const char * file,int line) +{ + ULONG stack_pointer = __get_sp(); + struct MemoryContextNode * mcn_next; + struct MemoryContextNode * mcn; + + /* ZZZ this could be done in a much smarter fashion by paying attention + * to the fact that the 'mcn_StackPointer' members are sorted... + */ + for(mcn = (struct MemoryContextNode *)__alloca_memory_list.mlh_Head ; + mcn->mcn_MinNode.mln_Succ != NULL ; + mcn = mcn_next) + { + mcn_next = (struct MemoryContextNode *)mcn->mcn_MinNode.mln_Succ; + + if(mcn->mcn_StackPointer < stack_pointer) + { + Remove((struct Node *)mcn); + + __force_free(mcn->mcn_Memory,file,line); + __force_free(mcn,file,line); + } + } +} + +/****************************************************************************/ + +void * +__alloca(size_t size,const char * file,int line) +{ + ULONG stack_pointer = __get_sp(); + struct MemoryContextNode * mcn; + void * result = NULL; + + __alloca_cleanup(file,line); + + assert( (int)size >= 0 ); + + if(size == 0) + { + #ifdef __MEM_DEBUG + { + kprintf("[%s] ",__program_name); + + if(file != NULL) + kprintf("%s:%ld:",file,line); + + kprintf("alloca(0) called.\n"); + } + #endif /* __MEM_DEBUG */ + + goto out; + } + + mcn = __allocate_memory(sizeof(*mcn),FALSE,file,line); + if(mcn == NULL) + { + SHOWMSG("not enough memory"); + goto out; + } + + /* Allocate memory which cannot be run through realloc() + * or free(). + */ + mcn->mcn_Memory = __allocate_memory(size,TRUE,file,line); + if(mcn->mcn_Memory == NULL) + { + SHOWMSG("not enough memory"); + + __force_free(mcn,file,line); + goto out; + } + + mcn->mcn_StackPointer = stack_pointer; + + AddTail((struct List *)&__alloca_memory_list,(struct Node *)mcn); + + result = mcn->mcn_Memory; + + out: + + return(result); +} + +/****************************************************************************/ + +void * +alloca(size_t size) +{ + void * result; + + result = __alloca(size,NULL,0); + + return(result); +} diff --git a/library/stdlib_assertion_failure.c b/library/stdlib_assertion_failure.c new file mode 100644 index 0000000..4fbf94f --- /dev/null +++ b/library/stdlib_assertion_failure.c @@ -0,0 +1,166 @@ +/* + * $Id: stdlib_assertion_failure.c,v 1.1.1.1 2004-07-26 16:31:50 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#include + +#define __NOLIBBASE__ +#define __NOGLOBALIFACE__ +#include +#include + +/****************************************************************************/ + +void +__assertion_failure( + const char * file_name, + int line_number, + const char * expression) +{ + static int been_here_before; + + /* Don't drop into a recursion. */ + if(been_here_before++ == 0) + { + BOOL use_stderr = FALSE; + + /* Figure out if the assertion failure message can be printed + * on the stderr stream. + */ + if(__iob != NULL && NOT __no_standard_io) + { + struct iob * iob; + + iob = (struct iob *)stderr; + if(iob != NULL && + FLAG_IS_SET(iob->iob_Flags,IOBF_IN_USE) && + FLAG_IS_SET(iob->iob_Flags,IOBF_WRITE)) + { + struct fd * fd; + + fd = __get_file_descriptor(iob->iob_Descriptor); + if(fd != NULL && + FLAG_IS_SET(fd->fd_Flags,FDF_IN_USE) && + FLAG_IS_SET(fd->fd_Flags,FDF_WRITE) && + FLAG_IS_CLEAR(fd->fd_Flags,FDF_IS_SOCKET)) + { + BPTR file_handle; + + file_handle = fd->fd_DefaultFile; + if(file_handle != ZERO && + ((struct FileHandle *)BADDR(file_handle))->fh_Type != NULL && + IsInteractive(file_handle)) + { + use_stderr = TRUE; + } + } + } + } + + if(use_stderr) + { + if(__program_name != NULL) + fprintf(stderr,"[%s] ",__program_name); + + fprintf(stderr, + "%s:%d: failed assertion '%s'\n", + file_name, + line_number, + expression); + } + else + { + #if defined(__amigaos4__) + struct IntuitionIFace * IIntuition = NULL; + #endif /* __amigaos4__ */ + + struct Library * IntuitionBase; + + IntuitionBase = OpenLibrary("intuition.library",37); + + #if defined(__amigaos4__) + { + if(IntuitionBase != NULL) + { + IIntuition = (struct IntuitionIFace *)GetInterface((struct Library *)IntuitionBase, "main", 1, 0); + if(IIntuition == NULL) + { + CloseLibrary(IntuitionBase); + IntuitionBase = NULL; + } + } + } + #endif /* __amigaos4__ */ + + if(IntuitionBase != NULL) + { + struct EasyStruct es; + ULONG args[3]; + + memset(&es,0,sizeof(es)); + + es.es_StructSize = sizeof(es); + es.es_Title = (STRPTR)__program_name; + es.es_TextFormat = (STRPTR)"Assertion of expression\n'%s'\nfailed in file '%s', line %ld"; + es.es_GadgetFormat = (STRPTR)"Sorry"; + + args[0] = (ULONG)expression; + args[1] = (ULONG)file_name; + args[2] = (ULONG)line_number; + + EasyRequestArgs(NULL,&es,NULL,args); + + #if defined(__amigaos4__) + { + DropInterface((struct Interface *)IIntuition); + } + #endif /* __amigaos4__ */ + + CloseLibrary(IntuitionBase); + } + } + + abort(); + } + + been_here_before--; +} diff --git a/library/stdlib_atexit.c b/library/stdlib_atexit.c new file mode 100644 index 0000000..f5da7ac --- /dev/null +++ b/library/stdlib_atexit.c @@ -0,0 +1,144 @@ +/* + * $Id: stdlib_atexit.c,v 1.1.1.1 2004-07-26 16:31:51 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +struct ExitTrapNode +{ + struct MinNode etn_MinNode; + void (*etn_Function)(void); +}; + +/****************************************************************************/ + +/* 32 functions are the minimum required by ISO 'C'. */ +static struct ExitTrapNode exit_node_table[32]; +static struct MinList exit_trap_list; +static size_t num_exit_nodes_used; +static BOOL atexit_blocked; + +/****************************************************************************/ + +int +atexit(void (*function)(void)) +{ + struct ExitTrapNode * etn; + int result = -1; + + assert( function != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(function == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(atexit_blocked) + { + errno = EACCES; + goto out; + } + + /* We always have room for 32 exit trap functions. */ + if(num_exit_nodes_used < NUM_ENTRIES(exit_node_table)) + { + etn = &exit_node_table[num_exit_nodes_used++]; + } + else + { + /* More than 32 exit trap functions are called + * for. Let's make room for another one. + */ + etn = malloc(sizeof(*etn)); + if(etn == NULL) + { + errno = ENOMEM; + goto out; + } + } + + etn->etn_Function = function; + + if(exit_trap_list.mlh_Head == NULL) + NewList((struct List *)&exit_trap_list); + + AddHead((struct List *)&exit_trap_list,(struct Node *)etn); + + result = 0; + + out: + + return(result); +} + +/****************************************************************************/ + +void +__exit_trap_trigger(void) +{ + struct ExitTrapNode * etn; + + /* Disallow further additions to the atexit() list. */ + atexit_blocked = TRUE; + + /* Remove the trap entries one at a time and process them. + * Should one of the routines drop into exit(), processing + * will continue with the next entry until eventually all + * list items have been taken care of. + */ + if(exit_trap_list.mlh_Head != NULL) + { + while((etn = (struct ExitTrapNode *)RemHead((struct List *)&exit_trap_list)) != NULL) + (*etn->etn_Function)(); + } +} diff --git a/library/stdlib_atof.c b/library/stdlib_atof.c new file mode 100644 index 0000000..fcb75e0 --- /dev/null +++ b/library/stdlib_atof.c @@ -0,0 +1,76 @@ +/* + * $Id: stdlib_atof.c,v 1.1.1.1 2004-07-26 16:31:51 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +double +atof(const char *str) +{ + double result = 0.0; + + assert( str != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(str == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + result = strtod(str,NULL); + + out: + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/stdlib_atoi.c b/library/stdlib_atoi.c new file mode 100644 index 0000000..307d6f6 --- /dev/null +++ b/library/stdlib_atoi.c @@ -0,0 +1,68 @@ +/* + * $Id: stdlib_atoi.c,v 1.1.1.1 2004-07-26 16:31:51 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +int +atoi(const char *str) +{ + int result = 0; + + assert( str != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(str == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + result = (int)strtol(str, (char **)NULL, 10); + + out: + + return(result); +} diff --git a/library/stdlib_atol.c b/library/stdlib_atol.c new file mode 100644 index 0000000..8819347 --- /dev/null +++ b/library/stdlib_atol.c @@ -0,0 +1,68 @@ +/* + * $Id: stdlib_atol.c,v 1.1.1.1 2004-07-26 16:31:51 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +long +atol(const char *str) +{ + long result = 0; + + assert( str != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(str == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + result = strtol(str, (char **)NULL, 10); + + out: + + return(result); +} diff --git a/library/stdlib_bsearch.c b/library/stdlib_bsearch.c new file mode 100644 index 0000000..c50a867 --- /dev/null +++ b/library/stdlib_bsearch.c @@ -0,0 +1,105 @@ +/* + * $Id: stdlib_bsearch.c,v 1.1.1.1 2004-07-26 16:31:51 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +void * +bsearch(const void *key, const void *base, size_t count, size_t size, int (*compare)(const void * key,const void * value)) +{ + void * result = NULL; + + ENTER(); + + SHOWPOINTER(key); + SHOWPOINTER(base); + SHOWVALUE(count); + SHOWVALUE(size); + SHOWPOINTER(compare); + + if(count > 0 && size > 0) + { + void * current; + size_t lower = 0; + size_t upper = count; + size_t position; + int delta; + + assert( key != NULL && base != NULL && compare != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(key == NULL || base == NULL || compare == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + while(lower < upper) + { + position = (lower + upper) / 2; + + current = (void *)(((ULONG)base) + (position * size)); + + delta = (*compare)(key, current); + if(delta == 0) + { + result = current; + break; + } + + if(delta < 0) + upper = position; + else + lower = position + 1; + } + } + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdlib_calloc.c b/library/stdlib_calloc.c new file mode 100644 index 0000000..ab9542d --- /dev/null +++ b/library/stdlib_calloc.c @@ -0,0 +1,93 @@ +/* + * $Id: stdlib_calloc.c,v 1.1.1.1 2004-07-26 16:31:52 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#undef calloc + +/****************************************************************************/ + +void * +__calloc(size_t num_elements,size_t element_size,const char * file,int line) +{ + void * result = NULL; + + #ifdef __MEM_DEBUG + { + /*__check_memory_allocations(file,line);*/ + } + #endif /* __MEM_DEBUG */ + + assert( (int)num_elements >= 0 && (int)element_size >= 0 ); + + if(num_elements > 0 && element_size > 0) + { + size_t total_size; + + total_size = num_elements * element_size; + + result = __malloc(total_size,file,line); + if(result != NULL) + memset(result,0,total_size); + else + SHOWMSG("memory allocation failure"); + } + else + { + SHOWMSG("zero length allocation"); + } + + return(result); +} + +/****************************************************************************/ + +void * +calloc(size_t num_elements,size_t element_size) +{ + void * result; + + result = __calloc(num_elements,element_size,NULL,0); + + return(result); +} diff --git a/library/stdlib_checkdetach.c b/library/stdlib_checkdetach.c new file mode 100644 index 0000000..36cad98 --- /dev/null +++ b/library/stdlib_checkdetach.c @@ -0,0 +1,38 @@ +/* + * $Id: stdlib_checkdetach.c,v 1.1.1.1 2004-07-26 16:31:52 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +BOOL (* __check_detach)(void); diff --git a/library/stdlib_constructor.c b/library/stdlib_constructor.c new file mode 100644 index 0000000..c3591bb --- /dev/null +++ b/library/stdlib_constructor.c @@ -0,0 +1,48 @@ +/* + * $Id: stdlib_constructor.c,v 1.1.1.1 2004-07-26 16:31:52 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +typedef void (*func_ptr)(void); + +/****************************************************************************/ + +func_ptr __CTOR_LIST__[] = { (func_ptr)0 }; + +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_constructor_begin.c b/library/stdlib_constructor_begin.c new file mode 100644 index 0000000..1069a28 --- /dev/null +++ b/library/stdlib_constructor_begin.c @@ -0,0 +1,255 @@ +/* + * $Id: stdlib_constructor_begin.c,v 1.1.1.1 2004-07-26 16:31:52 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#if defined(__amigaos4__) + +/****************************************************************************/ + +/* + * Dummy constructor and destructor array. The linker script will put these at the + * very beginning of section ".ctors" and ".dtors". crtend.o contains a similar entry + * with a NULL pointer entry and is put at the end of the sections. This way, the init + * code can find the global constructor/destructor pointers + */ +static void (*__CTOR_LIST__[1]) (void) __attribute__((section(".ctors"))) = { (void *)-1 }; +static void (*__DTOR_LIST__[1]) (void) __attribute__((section(".dtors"))) = { (void *)-1 }; + +/****************************************************************************/ + +static void +_do_ctors(void) +{ + void (**pFuncPtr)(void); + + /* Skip the first entry in the list (it's -1 anyway) */ + pFuncPtr = __CTOR_LIST__ + 1; + + /* Call all constructors in forward order */ + while (*pFuncPtr != NULL) + (**pFuncPtr++)(); +} + +/****************************************************************************/ + +static void +_do_dtors(void) +{ + static ULONG i = ~0UL; + void (**pFuncPtr)(void); + + if(i == ~0UL) + { + ULONG j = (ULONG)__DTOR_LIST__[0]; + + if(j == ~0UL) + { + /* Find the end of the destructors list. */ + j = 1; + + while(__DTOR_LIST__[j] != NULL) + j++; + + /* We're at the NULL entry now. Go back by one. */ + j--; + } + + i = j; + } + + /* If one of the destructors drops into + * exit(), processing will continue with + * the next following destructor. + */ + (void)setjmp(__exit_jmp_buf); + + /* Call all destructors in reverse order. */ + pFuncPtr = &__DTOR_LIST__[i]; + while(i > 0) + { + i--; + + (**pFuncPtr--)(); + } +} + +/****************************************************************************/ + +#elif defined(__SASC) + +/****************************************************************************/ + +extern int (* __far __ctors[])(void); +extern void (* __far __dtors[])(void); + +/****************************************************************************/ + +/* With SAS/C this function is placed in front of the first constructor + * table entry. It will invoke all following constructors and + * finally all the destructors. We don't use this approach here. + */ +void +__construct(void) +{ +} + +/****************************************************************************/ + +static void +_do_ctors(void) +{ + void * volatile p = &__ctors; + + /* The address is NULL if no constructor functions are to be used. */ + if(p != NULL) + { + int i; + + for(i = 0 ; __ctors[i] != NULL ; i++) + { + if((*__ctors[i])() != 0) + exit(RETURN_FAIL); + } + } +} + +/****************************************************************************/ + +static void +_do_dtors(void) +{ + void * volatile p = &__dtors; + + /* The address is NULL if no destructor functions are to be used. */ + if(p != NULL) + { + static int i; + + /* If one of the destructors drops into + * exit(), processing will continue with + * the next following destructor. + */ + (void)setjmp(__exit_jmp_buf); + + while(__dtors[i] != NULL) + { + /* Increment this before jumping in, so that the next + * invocation will always pick up the destructor following + * the one we will invoke rigt now. + */ + i++; + + (*__dtors[i-1])(); + } + } +} + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +typedef void (*func_ptr)(void); + +/****************************************************************************/ + +static void +_do_ctors(void) +{ + extern func_ptr __CTOR_LIST__[]; + ULONG nptrs = (ULONG)__CTOR_LIST__[0]; + ULONG i; + + /* Call all constructors in forward order */ + for(i = 0 ; i < nptrs ; i++) + __CTOR_LIST__[1+i](); +} + +/****************************************************************************/ + +static void +_do_dtors(void) +{ + extern func_ptr __DTOR_LIST__[]; + extern jmp_buf __exit_jmp_buf; + ULONG nptrs = (ULONG)__DTOR_LIST__[0]; + static ULONG i; + + /* If one of the destructors drops into + * exit(), processing will continue with + * the next following destructor. + */ + (void)setjmp(__exit_jmp_buf); + + /* Call all destructors in reverse order */ + while(i++ < nptrs) + __DTOR_LIST__[1+nptrs - i](); +} + +/****************************************************************************/ + +#endif /*__amigaos4__ */ + +/****************************************************************************/ + +/* FIXME: Do we need to put these in .init/.fini sections? */ + +//void _init(void) __attribute__((section(".init"))); +//void _fini(void) __attribute__((section(".fini"))); + +/****************************************************************************/ + +void +_init(void) +{ + _do_ctors(); +} + +/****************************************************************************/ + +void +_fini(void) +{ + _do_dtors(); +} diff --git a/library/stdlib_constructor_end.c b/library/stdlib_constructor_end.c new file mode 100644 index 0000000..864c6fb --- /dev/null +++ b/library/stdlib_constructor_end.c @@ -0,0 +1,44 @@ +/* + * $Id: stdlib_constructor_end.c,v 1.1.1.1 2004-07-26 16:31:52 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(__amigaos4__) + +/****************************************************************************/ + +/* End markers for the CTOR and DTOR list. */ +static volatile void (*__CTOR_LIST__[1]) (void) __attribute__((section(".ctors"))) = { (void *)0 }; +static volatile void (*__DTOR_LIST__[1]) (void) __attribute__((section(".dtors"))) = { (void *)0 }; + +/****************************************************************************/ + +#endif /*__amigaos4__ */ diff --git a/library/stdlib_data.c b/library/stdlib_data.c new file mode 100644 index 0000000..41ddf3c --- /dev/null +++ b/library/stdlib_data.c @@ -0,0 +1,105 @@ +/* + * $Id: stdlib_data.c,v 1.1.1.1 2004-07-26 16:31:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +/* NOTE: for Knuth's algorithm below the seed must not be zero. */ +unsigned __random_seed = 1; + +/****************************************************************************/ + +#if defined(__USE_MEM_TREES) && defined(__MEM_DEBUG) + +struct MemoryTree __memory_tree; + +#endif /* __USE_MEM_TREES && __MEM_DEBUG */ + +/****************************************************************************/ + +APTR __memory_pool; +struct MinList __memory_list; + +/****************************************************************************/ + +struct MinList __alloca_memory_list; + +/****************************************************************************/ + +struct WBStartup * __WBenchMsg; + +/****************************************************************************/ + +char * __program_name; +BOOL __free_program_name; + +/****************************************************************************/ + +BOOL __stack_overflow; +UBYTE * __stk_limit; +/*UBYTE ** __stackborders;*/ +/*UBYTE * __stk_initial;*/ +ULONG __stk_maxsize; +ULONG __stk_size; +ULONG __stk_extensions; + +/****************************************************************************/ + +struct Library * __UtilityBase; +struct Library * __LocaleBase; + +/****************************************************************************/ + +#if defined(__amigaos4__) + +struct UtilityIFace * __IUtility; +struct LocaleIFace * __ILocale; + +#endif /* __amigaos4__ */ + +/****************************************************************************/ + +#if defined(__SASC) + +UBYTE * __base; + +#endif /* __SASC */ diff --git a/library/stdlib_default_pool_size.c b/library/stdlib_default_pool_size.c new file mode 100644 index 0000000..7f6f10b --- /dev/null +++ b/library/stdlib_default_pool_size.c @@ -0,0 +1,40 @@ +/* + * $Id: stdlib_default_pool_size.c,v 1.1.1.1 2004-07-26 16:31:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +int __default_pool_size = 4096; diff --git a/library/stdlib_default_puddle_size.c b/library/stdlib_default_puddle_size.c new file mode 100644 index 0000000..bf56729 --- /dev/null +++ b/library/stdlib_default_puddle_size.c @@ -0,0 +1,40 @@ +/* + * $Id: stdlib_default_puddle_size.c,v 1.1.1.1 2004-07-26 16:31:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +int __default_puddle_size = 4096; diff --git a/library/stdlib_destructor.c b/library/stdlib_destructor.c new file mode 100644 index 0000000..31aaaaf --- /dev/null +++ b/library/stdlib_destructor.c @@ -0,0 +1,48 @@ +/* + * $Id: stdlib_destructor.c,v 1.1.1.1 2004-07-26 16:31:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +typedef void (*func_ptr)(void); + +/****************************************************************************/ + +func_ptr __DTOR_LIST__[] = { (func_ptr)0 }; + +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_detach.c b/library/stdlib_detach.c new file mode 100644 index 0000000..72709e6 --- /dev/null +++ b/library/stdlib_detach.c @@ -0,0 +1,38 @@ +/* + * $Id: stdlib_detach.c,v 1.1.1.1 2004-07-26 16:31:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +BOOL __detach; diff --git a/library/stdlib_disablerequesters.c b/library/stdlib_disablerequesters.c new file mode 100644 index 0000000..33384ed --- /dev/null +++ b/library/stdlib_disablerequesters.c @@ -0,0 +1,38 @@ +/* + * $Id: stdlib_disablerequesters.c,v 1.1.1.1 2004-07-26 16:31:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +BOOL __disable_dos_requesters; diff --git a/library/stdlib_div.c b/library/stdlib_div.c new file mode 100644 index 0000000..d58bf5d --- /dev/null +++ b/library/stdlib_div.c @@ -0,0 +1,51 @@ +/* + * $Id: stdlib_div.c,v 1.1.1.1 2004-07-26 16:31:53 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +div_t +div(int n,int d) +{ + div_t result; + + assert( d != 0 ); + + result.quot = n / d; + result.rem = n % d; + + return(result); +} diff --git a/library/stdlib_divmodsi3.c b/library/stdlib_divmodsi3.c new file mode 100644 index 0000000..1e2e956 --- /dev/null +++ b/library/stdlib_divmodsi3.c @@ -0,0 +1,79 @@ +/* + * $Id: stdlib_divmodsi3.c,v 1.1.1.1 2004-07-26 16:31:54 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl ___modsi3 + +| D1.L = D0.L % D1.L signed + +___modsi3: + + moveml sp@(4:W),d0/d1 + jbsr ___divsi4 + movel d1,d0 + rts + + .globl ___divsi3 + .globl ___UtilityBase + +| D0.L = D0.L / D1.L signed + +___divsi3: + moveml sp@(4:W),d0/d1 +___divsi4: + movel "A4(___UtilityBase)",a0 + jmp a0@(-150:W) + +"); + +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_divsi3.c b/library/stdlib_divsi3.c new file mode 100644 index 0000000..48eb37c --- /dev/null +++ b/library/stdlib_divsi3.c @@ -0,0 +1,69 @@ +/* + * $Id: stdlib_divsi3.c,v 1.1.1.1 2004-07-26 16:31:54 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(__GNUC__) + +/****************************************************************************/ +#ifndef __PPC__ +asm(" \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl ___divsi3 \n\ + .globl ___udivsi4 \n\ + \n\ +| D0.L = D0.L / D1.L signed \n\ + \n\ +___divsi3: \n\ + \n\ + moveml sp@(4:W),d0/d1 \n\ + jbra ___divsi4 \n\ + \n\ +"); +#else +__asm (" \n\ + .text \n\ + .align 2 \n\ + \n\ + .globl __divsi3 \n\ + \n\ +__divsi3: \n\ + divw r3, r3, r4 \n\ + blr \n\ +"); +#endif + +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_divsi4.c b/library/stdlib_divsi4.c new file mode 100644 index 0000000..2fcf9be --- /dev/null +++ b/library/stdlib_divsi4.c @@ -0,0 +1,77 @@ +/* + * $Id: stdlib_divsi4.c,v 1.1.1.1 2004-07-26 16:31:54 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ +#ifndef __PPC__ +asm(" \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl ___divsi4 \n\ + .globl ___UtilityBase \n\ + \n\ +___divsi4: \n\ + \n\ + movel "A4(___UtilityBase)",a0 \n\ + jmp a0@(-150:W) \n\ + \n\ +"); +#else +__asm(" \n\ + .text \n\ + .align 2 \n\ + \n\ + .globl __divsi4 \n\ + \n\ +__divis4: \n\ + divw r3, r3, r4 \n\ + blr \n\ +"); + +#endif +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_dosbase.c b/library/stdlib_dosbase.c new file mode 100644 index 0000000..2cbe20c --- /dev/null +++ b/library/stdlib_dosbase.c @@ -0,0 +1,47 @@ +/* + * $Id: stdlib_dosbase.c,v 1.1.1.1 2004-07-26 16:31:54 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#define __NOLIBBASE__ +#include + +/****************************************************************************/ + +struct Library * DOSBase; + +/****************************************************************************/ + +#if defined(__amigaos4__) + +struct DOSIFace * IDOS; + +#endif /* __amigaos4__ */ diff --git a/library/stdlib_exit.c b/library/stdlib_exit.c new file mode 100644 index 0000000..024c666 --- /dev/null +++ b/library/stdlib_exit.c @@ -0,0 +1,66 @@ +/* + * $Id: stdlib_exit.c,v 1.1.1.1 2004-07-26 16:31:54 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +jmp_buf __exit_jmp_buf; +int __exit_value = RETURN_FAIL; + +/****************************************************************************/ + +extern void __exit_trap_trigger(void); + +/****************************************************************************/ + +void +_exit(int return_code) +{ + __exit_value = return_code; + + longjmp(__exit_jmp_buf,1); +} + +/****************************************************************************/ + +void +exit(int return_code) +{ + /* ZZZ what about inifinite recursion in __exit_trap_trigger()? */ + __exit_trap_trigger(); + + _exit(return_code); +} diff --git a/library/stdlib_free.c b/library/stdlib_free.c new file mode 100644 index 0000000..6791646 --- /dev/null +++ b/library/stdlib_free.c @@ -0,0 +1,512 @@ +/* + * $Id: stdlib_free.c,v 1.1.1.1 2004-07-26 16:31:55 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#undef free + +/****************************************************************************/ + +#ifdef __MEM_DEBUG + +/****************************************************************************/ + +static char +get_hex_char(int n) +{ + char result; + + if(0 <= n && n <= 9) + result = n + '0'; + else + result = n + 'A' - 10; + + return(result); +} + +static void +int_to_hex(unsigned long v,char * buffer,int min_digits) +{ + int i,j,c; + + i = 0; + + do + { + c = (v % 16); + v = v / 16; + + buffer[i++] = get_hex_char(c); + } + while(v > 0); + + while(i < min_digits) + buffer[i++] = '0'; + + for(j = 0 ; j < i / 2 ; j++) + { + c = buffer[i - 1 - j]; + buffer[i - 1 - j] = buffer[j]; + buffer[j] = c; + } + + buffer[i] = '\0'; +} + +static void +dump_memory(unsigned char * m,int size,int ignore) +{ + const int mod = 20; + int position,i,c; + char buffer[120]; + char hex[10]; + + buffer[0] = '\0'; + + for(i = 0 ; i < size ; i++) + { + position = i % mod; + if(position == 0) + { + if(buffer[0] != '\0') + { + int len = sizeof(buffer)-1; + + while(len > 0 && buffer[len-1] == ' ') + len--; + + buffer[len] = '\0'; + + kprintf("[%s] %s\n",__program_name,buffer); + } + + memset(buffer,' ',sizeof(buffer)-1); + + int_to_hex((unsigned long)&m[i],hex,8); + + memmove(buffer,hex,8); + hex[9] = ':'; + } + + if(m[i] != ignore) + { + buffer[10 + 2 * position + 0] = get_hex_char(m[i] >> 4); + buffer[10 + 2 * position + 1] = get_hex_char(m[i] & 15); + + c = m[i]; + if(c < ' ' || (c >= 127 && c <= 160)) + c = '.'; + + buffer[10 + 2 * mod + 1 + position] = c; + } + else + { + buffer[10 + 2 * position + 0] = '_'; + buffer[10 + 2 * position + 1] = '_'; + } + } + + if(buffer[0] != '\0') + { + int len = sizeof(buffer)-1; + + while(len > 0 && buffer[len-1] == ' ') + len--; + + buffer[len] = '\0'; + + kprintf("[%s] %s\n",__program_name,buffer); + } +} + +/****************************************************************************/ + +static void +check_memory_node(struct MemoryNode * mn,const char * file,int line) +{ + size_t size = mn->mn_Size; + unsigned char * head = (unsigned char *)(mn + 1); + unsigned char * body = head + MALLOC_HEAD_SIZE; + unsigned char * tail = body + size; + int max_head_damage = 0; + int max_tail_damage = 0; + int max_body_damage = 0; + int i; + + for(i = 1 ; i <= MALLOC_HEAD_SIZE ; i++) + { + if(head[MALLOC_HEAD_SIZE - i] != MALLOC_HEAD_FILL) + max_head_damage = i; + } + + if(max_head_damage > 0) + { + kprintf("[%s] ",__program_name); + + if(file != NULL) + kprintf("%s:%ld:",file,line); + + kprintf("At least %ld bytes were damaged in front of allocation 0x%08lx..0x%08lx, size = %ld", + max_head_damage, + body,body + size - 1,size); + + if(mn->mn_File != NULL) + kprintf(", allocated at %s:%ld",mn->mn_File,mn->mn_Line); + + kprintf("\n"); + + dump_memory(head,MALLOC_HEAD_SIZE,MALLOC_HEAD_FILL); + } + + for(i = 0 ; i < MALLOC_TAIL_SIZE ; i++) + { + if(tail[i] != MALLOC_TAIL_FILL) + max_tail_damage = i+1; + } + + if(max_tail_damage > 0) + { + kprintf("[%s] ",__program_name); + + if(file != NULL) + kprintf("%s:%ld:",file,line); + + kprintf("At least %ld bytes were damaged behind allocation 0x%08lx..0x%08lx, size = %ld (with damage = %ld)", + max_tail_damage, + body,body + size - 1, + size,size+max_tail_damage); + + if(mn->mn_File != NULL) + kprintf(", allocated at %s:%ld",mn->mn_File,mn->mn_Line); + + kprintf("\n"); + + dump_memory(tail,MALLOC_TAIL_SIZE,MALLOC_TAIL_FILL); + } + + if(mn->mn_AlreadyFree) + { + for(i = 0 ; i < size ; i++) + { + if(body[i] != MALLOC_FREE_FILL) + max_body_damage = i+1; + } + + if(max_body_damage > 0) + { + kprintf("[%s] ",__program_name); + + if(file != NULL) + kprintf("%s:%ld:",file,line); + + kprintf("At least %ld bytes were damaged in freed allocation 0x%08lx..0x%08lx, size = %ld", + max_body_damage, + body,body + size - 1,size); + + if(mn->mn_File != NULL) + kprintf(", allocated at %s:%ld",mn->mn_File,mn->mn_Line); + + kprintf("\n"); + + dump_memory(body,size,MALLOC_FREE_FILL); + } + } +} + +/****************************************************************************/ + +void +__check_memory_allocations(const char * file,int line) +{ + struct MemoryNode * mn; + + for(mn = (struct MemoryNode *)__memory_list.mlh_Head ; + mn->mn_MinNode.mln_Succ != NULL ; + mn = (struct MemoryNode *)mn->mn_MinNode.mln_Succ) + { + check_memory_node(mn,file,line); + } +} + +/****************************************************************************/ + +struct MemoryNode * +__find_memory_node(void * address) +{ + struct MemoryNode * result; + + assert( address != NULL ); + + #if defined(__USE_MEM_TREES) + { + result = __red_black_tree_find(&__memory_tree,address); + } + #else + { + struct MemoryNode * mn; + + result = NULL; + + for(mn = (struct MemoryNode *)__memory_list.mlh_Head ; + mn->mn_MinNode.mln_Succ != NULL ; + mn = (struct MemoryNode *)mn->mn_MinNode.mln_Succ) + { + if(address == mn->mn_Allocation) + { + result = mn; + break; + } + } + } + #endif /* __USE_MEM_TREES */ + + return(result); +} + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +struct MemoryNode * +__find_memory_node(void * address) +{ + struct MemoryNode * result; + + assert( address != NULL ); + + result = &((struct MemoryNode *)address)[-1]; + + return(result); +} + +/****************************************************************************/ + +#endif /* __MEM_DEBUG */ + +/****************************************************************************/ + +static void +remove_and_free_memory_node(struct MemoryNode * mn) +{ + size_t allocation_size; + + assert( mn != NULL ); + + Remove((struct Node *)mn); + + #if defined(__USE_MEM_TREES) && defined(__MEM_DEBUG) + { + __red_black_tree_remove(&__memory_tree,mn); + } + #endif /* __USE_MEM_TREES && __MEM_DEBUG */ + + #ifdef __MEM_DEBUG + { + allocation_size = sizeof(*mn) + MALLOC_HEAD_SIZE + mn->mn_Size + MALLOC_TAIL_SIZE; + + assert( allocation_size == mn->mn_AllocationSize ); + + memset(mn,MALLOC_FREE_FILL,allocation_size); + } + #else + { + allocation_size = sizeof(*mn) + mn->mn_Size; + } + #endif /* __MEM_DEBUG */ + + if(__memory_pool != NULL) + FreePooled(__memory_pool,mn,allocation_size); + else + FreeMem(mn,allocation_size); +} + +/****************************************************************************/ + +void +__free_memory_node(struct MemoryNode * mn,const char * UNUSED file,int UNUSED line) +{ + assert(mn != NULL); + + #ifdef __MEM_DEBUG + { + size_t size = mn->mn_Size; + + check_memory_node(mn,file,line); + + if(NOT mn->mn_AlreadyFree) + { + #ifdef __MEM_DEBUG_LOG + { + kprintf("[%s] - %10ld 0x%08lx [",__program_name,mn->mn_Size,mn->mn_Allocation); + + if(mn->mn_File != NULL) + kprintf("allocated at %s:%ld, ",mn->mn_File,mn->mn_Line); + + kprintf("freed at %s:%ld]\n",file,line); + } + #endif /* __MEM_DEBUG_LOG */ + + if(__never_free) + { + mn->mn_AlreadyFree = TRUE; + + mn->mn_FreeFile = (char *)file; + mn->mn_FreeLine = line; + + memset(mn->mn_Allocation,MALLOC_FREE_FILL,size); + } + else + { + __current_memory_allocated -= size; + __current_num_memory_chunks_allocated--; + + remove_and_free_memory_node(mn); + } + } + else + { + #ifdef __MEM_DEBUG_LOG + { + kprintf("[%s] - %10ld 0x%08lx [",__program_name,mn->mn_Size,mn->mn_Allocation); + + kprintf("FAILED]\n"); + } + #endif /* __MEM_DEBUG_LOG */ + + kprintf("[%s] %s:%ld:Allocation at address 0x%08lx, size %ld", + __program_name,file,line,mn->mn_Allocation,mn->mn_Size); + + if(mn->mn_File != NULL) + kprintf(", allocated at %s:%ld",mn->mn_File,mn->mn_Line); + + kprintf(", has already been freed at %s:%ld.\n",mn->mn_FreeFile,mn->mn_FreeLine); + } + } + #else + { + remove_and_free_memory_node(mn); + } + #endif /* __MEM_DEBUG */ +} + +/****************************************************************************/ + +static void +free_memory(void * ptr,BOOL force,const char * file,int line) +{ + struct MemoryNode * mn; + + assert(ptr != NULL); + + /* Try to get rid of now unused memory. */ + /*if(NOT IsListEmpty((struct List *)&__alloca_memory_list)) + __alloca_cleanup(file,line);*/ + + #ifdef __MEM_DEBUG + { + /*if((rand() % 16) == 0) + __check_memory_allocations(file,line);*/ + } + #endif /* __MEM_DEBUG */ + + mn = __find_memory_node(ptr); + + #ifdef __MEM_DEBUG + { + if(mn != NULL) + { + if(force || (NOT mn->mn_NeverFree)) + __free_memory_node(mn,file,line); + } + else + { + #ifdef __MEM_DEBUG_LOG + { + kprintf("[%s] - %10ld 0x%08lx [",__program_name,0,ptr); + + kprintf("FAILED]\n"); + } + #endif /* __MEM_DEBUG_LOG */ + + kprintf("[%s] %s:%ld:Address for free(0x%08lx) not known.\n",__program_name,file,line,ptr); + + D(("memory allocation at 0x%08lx could not be freed",ptr)); + } + } + #else + { + assert( mn != NULL ); + + if(mn != NULL && (force || (NOT mn->mn_NeverFree))) + __free_memory_node(mn,file,line); + } + #endif /* __MEM_DEBUG */ +} + +/****************************************************************************/ + +void +__force_free(void * ptr,const char * file,int line) +{ + if(ptr != NULL) + free_memory(ptr,TRUE,file,line); +} + +/****************************************************************************/ + +void +__free(void * ptr,const char * file,int line) +{ + if(ptr != NULL) + free_memory(ptr,FALSE,file,line); +} + +/****************************************************************************/ + +void +free(void * ptr) +{ + __free(ptr,NULL,0); +} diff --git a/library/stdlib_gcc_help.h b/library/stdlib_gcc_help.h new file mode 100644 index 0000000..0e52faf --- /dev/null +++ b/library/stdlib_gcc_help.h @@ -0,0 +1,50 @@ +/* + * $Id: stdlib_gcc_help.h,v 1.1.1.1 2004-07-26 16:31:55 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_GCC_HELP_H +#define _STDLIB_GCC_HELP_H + +/****************************************************************************/ + +/* + * Uncomment this to build a library which contains code that helps + * GCC to build itself. This has two effects: the shell escape character + * "\" is enabled and the default stack size is raised to 200000 bytes + * with an additional helper function included which can be used to override + * the default stack size. + */ +/*#define GCC_HELP_SUPPORT*/ + +/****************************************************************************/ + +#endif /* _STDLIB_GCC_HELP_H */ diff --git a/library/stdlib_getdefstacksize.c b/library/stdlib_getdefstacksize.c new file mode 100644 index 0000000..77d62e3 --- /dev/null +++ b/library/stdlib_getdefstacksize.c @@ -0,0 +1,40 @@ +/* + * $Id: stdlib_getdefstacksize.c,v 1.1.1.1 2004-07-26 16:31:55 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +unsigned int (* __get_default_stack_size)(void); diff --git a/library/stdlib_getenv.c b/library/stdlib_getenv.c new file mode 100644 index 0000000..4961a43 --- /dev/null +++ b/library/stdlib_getenv.c @@ -0,0 +1,89 @@ +/* + * $Id: stdlib_getenv.c,v 1.1.1.1 2004-07-26 16:31:56 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +char * +getenv(const char * name) +{ + static char env_var_buffer[FILENAME_MAX]; + char * result = NULL; + + ENTER(); + + SHOWSTRING(name); + + assert( name != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name == NULL) + { + SHOWMSG("invalid name parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + if(GetVar((STRPTR)name,env_var_buffer,sizeof(env_var_buffer),0) < 0) + { + SHOWMSG("couldn't get the variable"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + result = env_var_buffer; + + SHOWSTRING(result); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdlib_getsp.asm b/library/stdlib_getsp.asm new file mode 100644 index 0000000..1bc7836 --- /dev/null +++ b/library/stdlib_getsp.asm @@ -0,0 +1,45 @@ +* +* $Id: stdlib_getsp.asm,v 1.1.1.1 2004-07-26 16:31:56 obarthel Exp $ +* +* :ts=8 +* +* Portable ISO 'C' (1994) runtime library for the Amiga computer +* Copyright (c) 2002-2004 by Olaf Barthel +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* - Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* - Neither the name of Olaf Barthel nor the names of contributors +* may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* + + section text,code + + xdef ___get_sp + +___get_sp: + + move.l sp,d0 + addq.l #4,d0 + + rts + + end diff --git a/library/stdlib_getsp.c b/library/stdlib_getsp.c new file mode 100644 index 0000000..fa7774b --- /dev/null +++ b/library/stdlib_getsp.c @@ -0,0 +1,88 @@ +/* + * $Id: stdlib_getsp.c,v 1.1.1.1 2004-07-26 16:31:56 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#ifndef __PPC__ + +/****************************************************************************/ + +asm(" \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl ___get_sp \n\ + \n\ +___get_sp: \n\ + movel sp,d0 \n\ + addql #4,d0 \n\ + rts \n\ + \n\ +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +__asm(" \n\ + \n\ + .text \n\ + .align 2 \n\ + \n\ + .globl __get_sp \n\ + \n\ +__get_sp: \n\ + \n\ + mr r3, r1 \n\ + blr \n\ + \n\ +"); + +/****************************************************************************/ + +#endif /* __PPC__ */ + +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_headers.h b/library/stdlib_headers.h new file mode 100644 index 0000000..44beca0 --- /dev/null +++ b/library/stdlib_headers.h @@ -0,0 +1,248 @@ +/* + * $Id: stdlib_headers.h,v 1.1.1.1 2004-07-26 16:31:56 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#define _STDLIB_HEADERS_H + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +/* This enables the legacy compatible 'struct AnchorPathOld'. */ +#define USE_OLD_ANCHORPATH + +#if (INCLUDE_VERSION >= 50) +#include +#endif /* (INCLUDE_VERSION >= 50) */ + +#include +#include +#include + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/****************************************************************************/ + +#ifndef _STDLIB_LOCALE_UTILITY_H +#include "stdlib_locale_utility.h" +#endif /* _STDLIB_LOCALE_UTILITY_H */ + +/****************************************************************************/ + +#ifndef _MATH_FP_SUPPORT_H +#include "math_fp_support.h" +#endif /* _MATH_FP_SUPPORT_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) +#include +#endif /* FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#include "macros.h" +#include "debug.h" + +/****************************************************************************/ + +struct MemoryNode +{ + struct MinNode mn_MinNode; + size_t mn_Size; + + UBYTE mn_NeverFree; + +#ifdef __MEM_DEBUG + UBYTE mn_AlreadyFree; + UBYTE mn_Pad0[2]; + + void * mn_Allocation; + size_t mn_AllocationSize; + + char * mn_FreeFile; + int mn_FreeLine; + + char * mn_File; + int mn_Line; + +#ifdef __USE_MEM_TREES + struct MemoryNode * mn_Left; + struct MemoryNode * mn_Right; + struct MemoryNode * mn_Parent; + UBYTE mn_IsRed; + UBYTE mn_Pad1[3]; +#endif /* __USE_MEM_TREES */ + +#else + UBYTE mn_Pad0[3]; +#endif /* __MEM_DEBUG */ +}; + +#ifdef __USE_MEM_TREES + +struct MemoryTree +{ + struct MemoryNode * mt_Root; + struct MemoryNode mt_RootNode; + struct MemoryNode mt_NullNode; +}; + +#endif /* __USE_MEM_TREES */ + +/****************************************************************************/ + +struct LocalVariable +{ + struct LocalVariable * lv_Next; + char * lv_Name; +}; + +/****************************************************************************/ + +extern struct LocalVariable * __lv_root; + +/****************************************************************************/ + +extern unsigned __random_seed; + +/****************************************************************************/ + +extern struct MemoryTree __memory_tree; +extern struct MinList __memory_list; +extern APTR __memory_pool; + +/****************************************************************************/ + +extern struct MinList __alloca_memory_list; + +/****************************************************************************/ + +extern unsigned long __maximum_memory_allocated; +extern unsigned long __current_memory_allocated; +extern unsigned long __maximum_num_memory_chunks_allocated; +extern unsigned long __current_num_memory_chunks_allocated; + +/****************************************************************************/ + +extern jmp_buf __exit_jmp_buf; +extern int __exit_value; + +/****************************************************************************/ + +extern unsigned int (* __get_default_stack_size)(void); + +/****************************************************************************/ + +extern unsigned int __stack_size; +extern BOOL __stack_overflow; +extern UBYTE * __stk_limit; +/*extern UBYTE ** __stackborders;*/ +/*extern UBYTE * __SaveSP;*/ +extern UBYTE * __base; + +/****************************************************************************/ + +extern ULONG __stk_argbytes; +extern ULONG __stk_safezone; +extern ULONG __stk_maxsize; +extern ULONG __stk_size; +extern ULONG __stk_extensions; +extern ULONG __stk_minframe; + +/****************************************************************************/ + +extern BOOL __is_resident; + +/****************************************************************************/ + +extern BOOL __free_program_name; + +/****************************************************************************/ + +extern UBYTE __shell_escape_character; + +/****************************************************************************/ + +extern char ** __argv; +extern int __argc; + +/****************************************************************************/ + +extern UBYTE * __quote_vector; + +/****************************************************************************/ + +extern int __default_pool_size; +extern int __default_puddle_size; + +/****************************************************************************/ + +#ifndef _STDLIB_PROTOS_H +#include "stdlib_protos.h" +#endif /* _STDLIB_PROTOS_H */ + +/****************************************************************************/ + +extern void kprintf(const char * format,...); + +/****************************************************************************/ + +#endif /* _STDLIB_HEADERS_H */ diff --git a/library/stdlib_init_exit.c b/library/stdlib_init_exit.c new file mode 100644 index 0000000..bdf4803 --- /dev/null +++ b/library/stdlib_init_exit.c @@ -0,0 +1,157 @@ +/* + * $Id: stdlib_init_exit.c,v 1.1.1.1 2004-07-26 16:31:57 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +void +__stdlib_exit(void) +{ + ENTER(); + + #ifdef __MEM_DEBUG + { + kprintf("[%s] %ld bytes still allocated upon exit, maximum of %ld bytes allocated at a time.\n", + __program_name,__current_memory_allocated,__maximum_memory_allocated); + + kprintf("[%s] %ld chunks of memory still allocated upon exit, maximum of %ld chunks allocated at a time.\n", + __program_name,__current_num_memory_chunks_allocated,__maximum_num_memory_chunks_allocated); + + __check_memory_allocations(__FILE__,__LINE__); + } + #endif /* __MEM_DEBUG */ + + /* Now for the local variables that may still be set. */ + if(__lv_root != NULL) + { + /* ZZZ why is this being done here? */ + + do + { + D(("deleting variable '%s'",__lv_root->lv_Name)); + + DeleteVar(__lv_root->lv_Name,0); + } + while((__lv_root = __lv_root->lv_Next) != NULL); + } + + /* Clean this up, too, just to be safe. */ + NewList((struct List *)&__alloca_memory_list); + + #if defined(__MEM_DEBUG) + { + __never_free = FALSE; + + if(__memory_list.mlh_Head != NULL) + { + while(NOT IsListEmpty((struct List *)&__memory_list)) + { + ((struct MemoryNode *)__memory_list.mlh_Head)->mn_AlreadyFree = FALSE; + + __free_memory_node((struct MemoryNode *)__memory_list.mlh_Head,__FILE__,__LINE__); + } + } + } + #endif /* __MEM_DEBUG */ + + #if defined(__USE_MEM_TREES) && defined(__MEM_DEBUG) + { + __initialize_red_black_tree(&__memory_tree); + } + #endif /* __USE_MEM_TREES && __MEM_DEBUG */ + + if(__memory_pool != NULL) + { + NewList((struct List *)&__memory_list); + + DeletePool(__memory_pool); + __memory_pool = NULL; + } + else + { + if(__memory_list.mlh_Head != NULL) + { + #ifdef __MEM_DEBUG + { + while(NOT IsListEmpty((struct List *)&__memory_list)) + __free_memory_node((struct MemoryNode *)__memory_list.mlh_Head,__FILE__,__LINE__); + } + #else + { + while(NOT IsListEmpty((struct List *)&__memory_list)) + __free_memory_node((struct MemoryNode *)__memory_list.mlh_Head,NULL,0); + } + #endif /* __MEM_DEBUG */ + } + } + + if(__free_program_name && __program_name != NULL) + { + FreeVec(__program_name); + __program_name = NULL; + } + + LEAVE(); +} + +/****************************************************************************/ + +int +__stdlib_init(void) +{ + ENTER(); + + #if defined(__USE_MEM_TREES) && defined(__MEM_DEBUG) + { + __initialize_red_black_tree(&__memory_tree); + } + #endif /* __USE_MEM_TREES && __MEM_DEBUG */ + + NewList((struct List *)&__memory_list); + NewList((struct List *)&__alloca_memory_list); + + if(((struct Library *)SysBase)->lib_Version >= 39) + __memory_pool = CreatePool(MEMF_ANY,(ULONG)__default_pool_size,(ULONG)__default_puddle_size); + + RETURN(OK); + return(OK); +} diff --git a/library/stdlib_isresident.c b/library/stdlib_isresident.c new file mode 100644 index 0000000..9ac5feb --- /dev/null +++ b/library/stdlib_isresident.c @@ -0,0 +1,38 @@ +/* + * $Id: stdlib_isresident.c,v 1.1.1.1 2004-07-26 16:31:57 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +BOOL __is_resident; diff --git a/library/stdlib_labs.c b/library/stdlib_labs.c new file mode 100644 index 0000000..169b04a --- /dev/null +++ b/library/stdlib_labs.c @@ -0,0 +1,48 @@ +/* + * $Id: stdlib_labs.c,v 1.1.1.1 2004-07-26 16:31:57 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +long +labs(long x) +{ + long result; + + result = (x < 0) ? (-x) : x; + + return(result); +} diff --git a/library/stdlib_ldiv.c b/library/stdlib_ldiv.c new file mode 100644 index 0000000..8cf3c26 --- /dev/null +++ b/library/stdlib_ldiv.c @@ -0,0 +1,51 @@ +/* + * $Id: stdlib_ldiv.c,v 1.1.1.1 2004-07-26 16:31:57 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +ldiv_t +ldiv(long n,long d) +{ + ldiv_t result; + + assert( d != 0 ); + + result.quot = n / d; + result.rem = n % d; + + return(result); +} diff --git a/library/stdlib_locale_utility.h b/library/stdlib_locale_utility.h new file mode 100644 index 0000000..7c4092a --- /dev/null +++ b/library/stdlib_locale_utility.h @@ -0,0 +1,92 @@ +/* + * $Id: stdlib_locale_utility.h,v 1.1.1.1 2004-07-26 16:31:57 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_LOCALE_UTILITY_H +#define _STDLIB_LOCALE_UTILITY_H + +/****************************************************************************/ + +#ifndef __NOLIBBASE__ +#define __NOLIBBASE__ +#endif /* __NOLIBBASE__ */ + +#ifndef __NOGLOBALIFACE__ +#define __NOGLOBALIFACE__ +#endif /* __NOGLOBALIFACE__ */ + +#include +#include + +/****************************************************************************/ + +extern struct Library * __UtilityBase; +extern struct Library * __LocaleBase; + +/****************************************************************************/ + +#if defined(__amigaos4__) + +/****************************************************************************/ + +extern struct UtilityIFace * __IUtility; +extern struct LocaleIFace * __ILocale; + +/****************************************************************************/ + +#define DECLARE_UTILITYBASE() \ + struct Library * UNUSED UtilityBase = __UtilityBase; \ + struct UtilityIFace * IUtility = __IUtility + +#define DECLARE_LOCALEBASE() \ + struct Library * UNUSED LocaleBase = __LocaleBase; \ + struct LocaleIFace * ILocale = __ILocale + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +#define DECLARE_UTILITYBASE() \ + struct Library * UtilityBase = __UtilityBase + +#define DECLARE_LOCALEBASE() \ + struct Library * LocaleBase = __LocaleBase + +/****************************************************************************/ + +#endif /* __amigaos4__ */ + +/****************************************************************************/ + +#endif /* _STDLIB_LOCALE_UTILITY_H */ diff --git a/library/stdlib_machine_test.c b/library/stdlib_machine_test.c new file mode 100644 index 0000000..5fe2dfd --- /dev/null +++ b/library/stdlib_machine_test.c @@ -0,0 +1,89 @@ +/* + * $Id: stdlib_machine_test.c,v 1.1.1.1 2004-07-26 16:31:57 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +int +__machine_test(void) +{ + int result = ERROR; + + #if defined(M68020) + { + const struct ExecBase * UNUSED ex = (const struct ExecBase *)SysBase; + + #if defined(M68881_FLOATING_POINT_SUPPORT) + { + if(FLAG_IS_CLEAR(ex->AttnFlags,AFF_68881) || FLAG_IS_CLEAR(ex->AttnFlags,AFF_68020)) + { + __show_error("This program requires a floating point processor and an MC68020 CPU, or better."); + + goto out; + } + } + #endif /* M68881_FLOATING_POINT_SUPPORT */ + + if(FLAG_IS_CLEAR(ex->AttnFlags,AFF_68020)) + { + __show_error("This program requires an MC68020 CPU, or better."); + + goto out; + } + } + #elif defined(M68881_FLOATING_POINT_SUPPORT) + { + const struct ExecBase * UNUSED ex = (const struct ExecBase *)SysBase; + + if(FLAG_IS_CLEAR(ex->AttnFlags,AFF_68881)) + { + __show_error("This program requires a floating point processor."); + + goto out; + } + } + #endif /* M68881_FLOATING_POINT_SUPPORT */ + + result = OK; + + out: + + return(result); +} diff --git a/library/stdlib_main.c b/library/stdlib_main.c new file mode 100644 index 0000000..72b1077 --- /dev/null +++ b/library/stdlib_main.c @@ -0,0 +1,579 @@ +/* + * $Id: stdlib_main.c,v 1.1.1.1 2004-07-26 16:31:58 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*#define DEBUG*/ + +#include "stdlib_headers.h" +#include "stdio_headers.h" +#include "time_headers.h" + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#include +#include +#include +#include +#include + +/****************************************************************************/ + +#include "macros.h" + +/****************************************************************************/ + +typedef int (*init_func_ptr)(void); +typedef void (*exit_func_ptr)(void); + +/****************************************************************************/ + +extern int main(int arg_c,char ** arg_v); + +/****************************************************************************/ + +#if 0 + +/****************************************************************************/ + +static BOOL show_profile_names = FALSE; +static int nest_level; + +void ASM +_PROLOG(REG(a0,char * id)) +{ + nest_level++; + + if(id != NULL && __program_name != NULL) + { + int i; + + kprintf("[%s]",__program_name); + + for(i = 0 ; i < nest_level ; i++) + kputc(' '); + + kprintf("%s\n",id); + } +} + +/****************************************************************************/ + +void ASM +_EPILOG(REG(a0,char * id)) +{ + if(nest_level > 0) + nest_level--; +} + +/****************************************************************************/ + +#endif + +/****************************************************************************/ + +static int +call_main(void) +{ + /* Initialization functions; must be called exactly in this + * order because there are dependencies between the + * individual functions. + */ + static init_func_ptr init_functions[] = + { + __stdlib_init, + __stk_init, + __startup_init, + __stdio_init, + __machine_test, + __math_init, + __locale_init, + __unistd_init, + __socket_init, + __usergroup_init, + __wildcard_expand_init, + + NULL + }; + + /* Finalization functions; these may be called + * essentially in any order. But this one makes the + * most sense (roll-back of the corresponding + * initialization functions). + */ + static exit_func_ptr exit_functions[] = + { + __wildcard_expand_exit, + __usergroup_exit, + __socket_exit, + __unistd_exit, + __locale_exit, + __math_exit, + __stdio_exit, + __startup_exit, + __stk_exit, + __stdlib_exit, + + NULL + }; + + static size_t i; + + /* This plants the return buffer for _exit(). */ + if(setjmp(__exit_jmp_buf) != 0) + goto out; + + for(i = 0 ; init_functions[i] != NULL ; i++) + { + if((*init_functions[i])() != OK) + goto out; + } + + /* Go through the constructor list */ + _init(); + + //show_profile_names = TRUE; + + /* After all these preparations, get this show on the road... */ + exit(main((int)__argc,(char **)__argv)); + + out: + + //show_profile_names = FALSE; + + /* If we end up here with the __stack_overflow variable + * set then the stack overflow handler dropped into + * longjmp() and _exit() did not get called. This + * means that we will have to show the error message + * and invoke _exit() all on our own. + */ + if(__stack_overflow) + { + /* Dump whatever is waiting to be written to the + * standard I/O streams, and make sure that no + * break signal is about to make things any more + * complicated than they already are. + */ + __check_abort_enabled = FALSE; + + if(stdout != NULL) + fflush(stdout); + + if(stderr != NULL) + fflush(stderr); + + __show_error("Stack overflow detected"); + + if(setjmp(__exit_jmp_buf) == 0) + _exit(RETURN_FAIL); + } + + /* If necessary, print stack size usage information. */ + __stack_usage_exit(); + + /* Go through the destructor list */ + _fini(); + + /* Any of the following cleanup routines may call + * _exit() by way of abort() or through a hook + * function. Which is why we redirect the exit + * return procedure. + */ + for(i = 0 ; exit_functions[i] != NULL ; i++) + { + if(setjmp(__exit_jmp_buf) == 0) + (*exit_functions[i])(); + } + + return(__exit_value); +} + +/****************************************************************************/ + +static void ASM +detach_cleanup(REG(d0, LONG UNUSED unused_return_code),REG(d1, BPTR segment_list)) +{ + #if defined(__amigaos4__) + { + if(__IUtility != NULL) + DropInterface((struct Interface *)__IUtility); + } + #endif /* __amigaos4__ */ + + if(__UtilityBase != NULL) + CloseLibrary(__UtilityBase); + + /* The following trick is necessary only under dos.library V40 and below. */ + if(((struct Library *)DOSBase)->lib_Version < 50) + { + /* Now for the slightly shady part. We need to unload the segment + * list this program was originally loaded with. We have to close + * dos.library, though, which means that either we can close the + * library or unload the code, but not both. But there's a loophole + * in that we can enter Forbid(), unload the code, close the library + * and exit and nobody will be able to allocate this program's + * memory until after the process has been terminated. + */ + Forbid(); + + UnLoadSeg(segment_list); + } + + #if defined(__amigaos4__) + { + if(IDOS != NULL) + DropInterface((struct Interface *)IDOS); + } + #endif /* __amigaos4__ */ + + if(DOSBase != NULL) + CloseLibrary(DOSBase); +} + +/****************************************************************************/ + +static ULONG +get_stack_size(struct Task * tc) +{ + ULONG upper,lower; + ULONG result; + + /* How much stack size was provided? */ + upper = (ULONG)tc->tc_SPUpper; + lower = (ULONG)tc->tc_SPLower; + + result = upper - lower; + + return(result); +} + +/****************************************************************************/ + +int +_main(void) +{ + struct Process * child_process = NULL; + struct WBStartup * startup_message; + struct Process * this_process; + int return_code = RETURN_FAIL; + ULONG current_stack_size; + APTR old_window_pointer; + + SysBase = *(struct Library **)4; + + #if defined(__amigaos4__) + { + /* Get exec interface */ + IExec = (struct ExecIFace *)((struct ExecBase *)SysBase)->MainInterface; + } + #endif /* __amigaos4__ */ + + /* Pick up the Workbench startup message, if available. */ + this_process = (struct Process *)FindTask(NULL); + + if(this_process->pr_CLI == ZERO) + { + struct MsgPort * mp = &this_process->pr_MsgPort; + + WaitPort(mp); + + startup_message = (struct WBStartup *)GetMsg(mp); + } + else + { + startup_message = NULL; + } + + old_window_pointer = this_process->pr_WindowPtr; + + if(__disable_dos_requesters) + this_process->pr_WindowPtr = (APTR)-1; + + __WBenchMsg = startup_message; + + /* We will need dos.library V37 and utility.library V37. */ + DOSBase = (struct Library *)OpenLibrary("dos.library",37); + __UtilityBase = OpenLibrary("utility.library",37); + + if(DOSBase == NULL || __UtilityBase == NULL) + { + __show_error("This program requires AmigaOS 2.04 or higher."); + goto out; + } + + #if defined(__amigaos4__) + { + /* Get interfaces for DOS and Utility */ + IDOS = (struct DOSIFace *)GetInterface(DOSBase, "main", 1, 0); + __IUtility = (struct UtilityIFace *)GetInterface(__UtilityBase, "main", 1, 0); + + if (IDOS == NULL || __IUtility == NULL) + { + __show_error("This program requires AmigaOS 4.0 or higher."); + goto out; + } + } + #endif /* __amigaos4__ */ + + /* Remember when this program was started. */ + DateStamp(&__start_time); + + /* If a callback was provided which can fill us in on which + * minimum stack size should be used, invoke it now and + * store its result in the global __stack_size variable. + */ + if(__get_default_stack_size != NULL) + { + unsigned int size; + + size = (*__get_default_stack_size)(); + if(size > 0) + __stack_size = size; + } + + /* How much stack size was provided? */ + current_stack_size = get_stack_size(&this_process->pr_Task); + + /* If this is a resident program, don't allow for the detach + * code to run. Same goes for launching the program from + * Workbench. + */ + if(__is_resident || startup_message != NULL) + { + __detach = FALSE; + } + else if (__check_detach != NULL) + { + /* Check if we may need to detach from the shell. */ + __detach = (*__check_detach)(); + } + + /* The following code will be executed if the program is to keep + * running in the shell or was launched from Workbench. + */ + if(DO_NOT __detach) + { + /* Was a minimum stack size requested and do we + * need more stack space than was provided for? + */ + if(__stack_size > 0 && current_stack_size < (ULONG)__stack_size) + { + struct StackSwapStruct * stk; + unsigned int stack_size; + ULONG lower,upper; + + /* Make the stack size a multiple of 16 bytes. */ + stack_size = (__stack_size + 15UL) & ~15UL; + + /* We allocate a little more memory so that we can align + the stack to a 128 bit boundary. */ + stk = AllocVec(sizeof(*stk) + 15 + stack_size,MEMF_PUBLIC|MEMF_ANY); + if(stk == NULL) + goto out; + + /* Align the lower stack bound to a 128 bit boundary, then + fix up the upper bound, which is guaranteed to be on + a 128 bit boundary, too, on account of the stack size + having being rounded to that boundary. */ + lower = (((ULONG)(stk+1)) + 15UL) & ~15UL; + upper = lower + stack_size; + + stk->stk_Lower = (APTR)lower; + stk->stk_Upper = upper; + stk->stk_Pointer = (APTR)upper; + + /* If necessary, set up for stack size usage measurement. */ + __stack_usage_init(stk); + + return_code = __swap_stack_and_call(stk,(APTR)call_main); + + FreeVec(stk); + } + else + { + /* We have enough room to make the call or just don't care. */ + return_code = call_main(); + } + } + else + { + struct CommandLineInterface * cli = Cli(); + struct TagItem tags[11]; + UBYTE program_name[256]; + unsigned int stack_size; + int i; + + /* Now for the interesting part: detach from the shell we're + * currently executing in. This works only if the program is + * not reentrant and has not been launched from Workbench. + */ + + stack_size = __stack_size; + + if(stack_size < current_stack_size) + stack_size = current_stack_size; + + if(stack_size < cli->cli_DefaultStack * sizeof(LONG)) + stack_size = cli->cli_DefaultStack * sizeof(LONG); + + GetProgramName(program_name,sizeof(program_name)); + + i = 0; + + tags[i]. ti_Tag = NP_Entry; + tags[i++]. ti_Data = (ULONG)call_main; + tags[i]. ti_Tag = NP_StackSize; + tags[i++]. ti_Data = stack_size; + tags[i]. ti_Tag = NP_Name; + tags[i++]. ti_Data = (ULONG)program_name; + tags[i]. ti_Tag = NP_CommandName; + tags[i++]. ti_Data = (ULONG)program_name; + tags[i]. ti_Tag = NP_Cli; + tags[i++]. ti_Data = TRUE; + tags[i]. ti_Tag = NP_Arguments; + tags[i++]. ti_Data = (ULONG)GetArgStr(); + tags[i]. ti_Tag = NP_ExitCode; + tags[i++]. ti_Data = (ULONG)detach_cleanup; + tags[i]. ti_Tag = NP_ExitData; + tags[i++]. ti_Data = (ULONG)cli->cli_Module; + + /* dos.library V50 will free the segment list upon exit. */ + if(((struct Library *)DOSBase)->lib_Version >= 50) + { + tags[i]. ti_Tag = NP_Seglist; + tags[i++]. ti_Data = (ULONG)cli->cli_Module;; + tags[i]. ti_Tag = NP_FreeSeglist; + tags[i++]. ti_Data = TRUE; + } + + tags[i].ti_Tag = TAG_END; + + Forbid(); + + child_process = CreateNewProc(tags); + if(child_process == NULL) + { + Permit(); + + PrintFault(IoErr(),program_name); + + return_code = RETURN_FAIL; + goto out; + } + + /* The standard I/O streams are no longer attached to a console. */ + __no_standard_io = TRUE; + + cli->cli_Module = ZERO; + + return_code = RETURN_OK; + + Permit(); + } + + out: + + this_process->pr_WindowPtr = old_window_pointer; + + if(child_process == NULL) + { + #if defined(__amigaos4__) + { + if(__IUtility != NULL) + { + DropInterface((struct Interface *)__IUtility); + __IUtility = NULL; + } + } + #endif /* __amigaos4__ */ + + if(__UtilityBase != NULL) + { + CloseLibrary(__UtilityBase); + __UtilityBase = NULL; + } + + #if defined(__amigaos4__) + { + if(IDOS != NULL) + { + DropInterface((struct Interface *)IDOS); + IDOS = NULL; + } + } + #endif /* __amigaos4__ */ + + if(DOSBase != NULL) + { + CloseLibrary(DOSBase); + DOSBase = NULL; + } + } + + if(startup_message != NULL) + { + Forbid(); + + ReplyMsg((struct Message *)startup_message); + } + + return(return_code); +} + +/****************************************************************************/ + +/* The following is automatically called by the main() function through code + * inserted by GCC. In theory, this could be removed by updating the machine + * definition, but for now we'll just keep this stub around. It is intended + * to call the constructor functions, but we do this in our own _main() + * anyway. + */ + +#if defined(__GNUC__) + +/****************************************************************************/ + +void __main(void); + +/****************************************************************************/ + +void +__main(void) +{ +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_malloc.c b/library/stdlib_malloc.c new file mode 100644 index 0000000..5162fd1 --- /dev/null +++ b/library/stdlib_malloc.c @@ -0,0 +1,252 @@ +/* + * $Id: stdlib_malloc.c,v 1.1.1.1 2004-07-26 16:31:59 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#undef malloc + +/****************************************************************************/ + +#ifdef __MEM_DEBUG + +unsigned long __maximum_memory_allocated; +unsigned long __current_memory_allocated; +unsigned long __maximum_num_memory_chunks_allocated; +unsigned long __current_num_memory_chunks_allocated; + +#endif /* __MEM_DEBUG */ + +/****************************************************************************/ + +size_t +__get_allocation_size(size_t size) +{ + #ifndef __MEM_DEBUG + { + size_t total_allocation_size; + + total_allocation_size = sizeof(struct MemoryNode) + size; + + /* Round up the allocation size to the physical allocation granularity. */ + size += ((total_allocation_size + MEM_BLOCKMASK) & ~((ULONG)MEM_BLOCKMASK)) - total_allocation_size; + } + #endif /* __MEM_DEBUG */ + + return(size); +} + +/****************************************************************************/ + +void * +__allocate_memory(size_t size,BOOL never_free,const char * UNUSED file,int UNUSED line) +{ + struct MemoryNode * mn; + size_t allocation_size; + void * result = NULL; + + assert( size > 0 ); + + if(__free_memory_threshold > 0 && AvailMem(MEMF_ANY|MEMF_LARGEST) < __free_memory_threshold) + { + SHOWMSG("not enough free memory available to safely proceed with allocation"); + + errno = ENOMEM; + goto out; + } + + #ifdef __MEM_DEBUG + { + assert( MALLOC_HEAD_SIZE > 0 && (MALLOC_HEAD_SIZE % 4) == 0 ); + assert( MALLOC_TAIL_SIZE > 0 && (MALLOC_TAIL_SIZE % 4) == 0 ); + assert( (sizeof(*mn) % 4) == 0 ); + + allocation_size = sizeof(*mn) + MALLOC_HEAD_SIZE + size + MALLOC_TAIL_SIZE; + } + #else + { + /* Round up the allocation size to the physical allocation granularity. */ + size = __get_allocation_size(size); + + allocation_size = sizeof(*mn) + size; + } + #endif /* __MEM_DEBUG */ + + if(__memory_pool != NULL) + mn = AllocPooled(__memory_pool,allocation_size); + else + mn = AllocMem(allocation_size,MEMF_ANY); + + if(mn == NULL) + { + SHOWMSG("not enough memory"); + + errno = ENOMEM; + goto out; + } + + mn->mn_Size = size; + mn->mn_NeverFree = never_free; + + AddTail((struct List *)&__memory_list,(struct Node *)mn); + + #ifdef __MEM_DEBUG + { + char * head = (char *)(mn + 1); + char * body = head + MALLOC_HEAD_SIZE; + char * tail = body + size; + + mn->mn_AlreadyFree = FALSE; + mn->mn_Allocation = body; + mn->mn_AllocationSize = allocation_size; + mn->mn_File = (char *)file; + mn->mn_Line = line; + mn->mn_FreeFile = NULL; + mn->mn_FreeLine = 0; + + memset(head,MALLOC_HEAD_FILL,MALLOC_HEAD_SIZE); + memset(body,MALLOC_NEW_FILL,size); + memset(tail,MALLOC_TAIL_FILL,MALLOC_TAIL_SIZE); + + __current_memory_allocated += size; + if(__maximum_memory_allocated < __current_memory_allocated) + __maximum_memory_allocated = __current_memory_allocated; + + __current_num_memory_chunks_allocated++; + if(__maximum_num_memory_chunks_allocated < __current_num_memory_chunks_allocated) + __maximum_num_memory_chunks_allocated = __current_num_memory_chunks_allocated; + + #ifdef __MEM_DEBUG_LOG + { + kprintf("[%s] + %10ld 0x%08lx [",__program_name,size,body); + + kprintf("allocated at %s:%ld]\n",file,line); + } + #endif /* __MEM_DEBUG_LOG */ + + #ifdef __USE_MEM_TREES + { + __red_black_tree_insert(&__memory_tree,mn); + } + #endif /* __USE_MEM_TREES */ + + result = mn->mn_Allocation; + } + #else + { + result = &mn[1]; + } + #endif /* __MEM_DEBUG */ + + assert( (((ULONG)result) & 3) == 0 ); + + out: + + #ifdef __MEM_DEBUG_LOG + { + if(result == NULL) + { + kprintf("[%s] + %10ld 0x%08lx [",__program_name,size,NULL); + + kprintf("FAILED: allocated at %s:%ld]\n",file,line); + } + } + #endif /* __MEM_DEBUG_LOG */ + + return(result); +} + +/****************************************************************************/ + +void * +__malloc(size_t size,const char * file,int line) +{ + void * result = NULL; + + /* Try to get rid of now unused memory. */ + /*if(NOT IsListEmpty((struct List *)&__alloca_memory_list)) + __alloca_cleanup(file,line);*/ + + #ifdef __MEM_DEBUG + { + /*if((rand() % 16) == 0) + __check_memory_allocations(file,line);*/ + } + #endif /* __MEM_DEBUG */ + + if(size == 0) + { + #ifdef __MEM_DEBUG + { + kprintf("[%s] ",__program_name); + + if(file != NULL) + kprintf("%s:%ld:",file,line); + + kprintf("malloc(0) called.\n"); + } + #endif /* __MEM_DEBUG */ + + goto out; + } + + assert( (int)size > 0 ); + + /* Allocate memory which can be put through realloc() and free(). */ + result = __allocate_memory(size,FALSE,file,line); + + out: + + return(result); +} + +/****************************************************************************/ + +void * +malloc(size_t size) +{ + void * result; + + result = __malloc(size,NULL,0); + + return(result); +} diff --git a/library/stdlib_math.c b/library/stdlib_math.c new file mode 100644 index 0000000..699e696 --- /dev/null +++ b/library/stdlib_math.c @@ -0,0 +1,55 @@ +/* + * $Id: stdlib_math.c,v 1.1.1.1 2004-07-26 16:31:59 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#include "macros.h" + +/****************************************************************************/ + +void +__math_exit(void) +{ +} + +/****************************************************************************/ + +int +__math_init(void) +{ + return(OK); +} diff --git a/library/stdlib_mblen.c b/library/stdlib_mblen.c new file mode 100644 index 0000000..1c8d240 --- /dev/null +++ b/library/stdlib_mblen.c @@ -0,0 +1,45 @@ +/* + * $Id: stdlib_mblen.c,v 1.1.1.1 2004-07-26 16:31:59 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +int +mblen(const char *s, size_t n) +{ + /* ZZZ unimplemented */ + return(-1); +} diff --git a/library/stdlib_mbstowcs.c b/library/stdlib_mbstowcs.c new file mode 100644 index 0000000..9748f50 --- /dev/null +++ b/library/stdlib_mbstowcs.c @@ -0,0 +1,45 @@ +/* + * $Id: stdlib_mbstowcs.c,v 1.1.1.1 2004-07-26 16:31:59 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +size_t +mbstowcs(wchar_t *pwcs, const char *s, size_t n) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/stdlib_mbtowc.c b/library/stdlib_mbtowc.c new file mode 100644 index 0000000..1f6a17f --- /dev/null +++ b/library/stdlib_mbtowc.c @@ -0,0 +1,45 @@ +/* + * $Id: stdlib_mbtowc.c,v 1.1.1.1 2004-07-26 16:31:59 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +int +mbtowc(wchar_t *pwc, const char *s, size_t n) +{ + /* ZZZ unimplemented */ + return(-1); +} diff --git a/library/stdlib_mem_debug.h b/library/stdlib_mem_debug.h new file mode 100644 index 0000000..3723e2b --- /dev/null +++ b/library/stdlib_mem_debug.h @@ -0,0 +1,90 @@ +/* + * $Id: stdlib_mem_debug.h,v 1.1.1.1 2004-07-26 16:32:00 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#define _STDLIB_MEM_DEBUG_H + +/****************************************************************************/ + +/* + * Uncomment this to build a library which has the memory debugging features + * enabled. + */ +/*#define __MEM_DEBUG */ + +/****************************************************************************/ + +/* + * Uncomment this to see reports of where and how much memory is allocated + * or released. + */ +/*#define __MEM_DEBUG_LOG*/ + +/****************************************************************************/ + +/* + * Uncomment this to speed up memory data maintenance operations when + * the memory debugging mode is enabled. + */ +/*#define __USE_MEM_TREES*/ + +/****************************************************************************/ + +/* + * Memory debugging parameters; note that the head/tail size must be + * multiples of four, or you will break code that depends upon malloc() + * and friends to return long word aligned data structures! Better + * still, there are assert()s in the library which will blow your code + * out of the water if the data returned by malloc() and realloc() is + * not long word aligned... + */ + +#define MALLOC_HEAD_SIZE 512 /* How many bytes to allocate in front of + each memory chunk */ +#define MALLOC_TAIL_SIZE 512 /* How many bytes to allocate behind each + memory chunk */ + +/****************************************************************************/ + +#define MALLOC_NEW_FILL 0xA3 /* The byte value to fill newly created + memory allocations with */ +#define MALLOC_FREE_FILL 0xA5 /* The byte value to fill freed memory + allocations with */ +#define MALLOC_HEAD_FILL 0xA7 /* The byte value to fill the memory in + front of each allocation with */ +#define MALLOC_TAIL_FILL 0xA9 /* The byte value to fill the memory behind + each allocation with */ + +/****************************************************************************/ + +#endif /* _STDLIB_MEM_DEBUG_H */ diff --git a/library/stdlib_mkdtemp.c b/library/stdlib_mkdtemp.c new file mode 100644 index 0000000..1359e0f --- /dev/null +++ b/library/stdlib_mkdtemp.c @@ -0,0 +1,95 @@ +/* + * $Id: stdlib_mkdtemp.c,v 1.1.1.1 2004-07-26 16:32:00 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +char * +mkdtemp(char *name_template) +{ + char * result = NULL; + + ENTER(); + + SHOWSTRING(name_template); + + assert( name_template != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name_template == NULL) + { + SHOWMSG("invalid name template"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(mktemp(name_template) == NULL) + { + SHOWMSG("could not pick a temp name"); + goto out; + } + + if(mkdir(name_template,0700) == -1) + { + SHOWMSG("could not create directory"); + goto out; + } + + result = name_template; + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdlib_mkstemp.c b/library/stdlib_mkstemp.c new file mode 100644 index 0000000..b91507e --- /dev/null +++ b/library/stdlib_mkstemp.c @@ -0,0 +1,91 @@ +/* + * $Id: stdlib_mkstemp.c,v 1.1.1.1 2004-07-26 16:32:00 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +mkstemp(char *name_template) +{ + int result = -1; + + ENTER(); + + SHOWSTRING(name_template); + + assert( name_template != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name_template == NULL) + { + SHOWMSG("invalid name template"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(mktemp(name_template) == NULL) + { + SHOWMSG("could not pick temp name"); + goto out; + } + + SHOWSTRING(name_template); + + result = open(name_template,O_RDWR|O_CREAT|O_TRUNC,0600); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdlib_mktemp.c b/library/stdlib_mktemp.c new file mode 100644 index 0000000..ebe996e --- /dev/null +++ b/library/stdlib_mktemp.c @@ -0,0 +1,226 @@ +/* + * $Id: stdlib_mktemp.c,v 1.1.1.1 2004-07-26 16:32:00 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +char * +mktemp(char * name_template) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info name_template_nti; + char * original_name_template = NULL; + #endif /* UNIX_PATH_SEMANTICS */ + struct Process * this_process; + APTR old_window_pointer; + char * result = NULL; + int template_offset; + int template_len; + time_t now; + BPTR lock; + int i; + + ENTER(); + + SHOWSTRING(name_template); + + assert(name_template != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name_template == NULL) + { + SHOWMSG("invalid name template"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + original_name_template = name_template; + + if(__translate_unix_to_amiga_path_name((char const **)&name_template,&name_template_nti) != 0) + goto out; + + if(name_template_nti.is_root) + { + errno = EACCES; + goto out; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + SHOWSTRING(name_template); + + template_offset = -1; + template_len = 0; + + for(i = strlen(name_template)-1 ; i >= 0 ; i--) + { + if(name_template[i] == 'X') + { + template_offset = i; + template_len++; + } + else + { + break; + } + } + + if(template_offset == -1) + { + SHOWMSG("invalid name template"); + + errno = EINVAL; + goto out; + } + + this_process = (struct Process *)FindTask(NULL); + + time(&now); + + now += (time_t)this_process; + + for(i = 0 ; i < template_len ; i++) + { + name_template[template_offset + i] = 'A' + (now % 26); + + now = (now / 26); + if(now == 0) + time(&now); + } + + old_window_pointer = this_process->pr_WindowPtr; + + while(TRUE) + { + if(__check_abort_enabled) + __check_abort(); + + D(("checking '%s'",name_template)); + + /* Turn off DOS error requesters. */ + this_process->pr_WindowPtr = (APTR)-1; + + /* Does this object exist already? */ + PROFILE_OFF(); + lock = Lock(name_template,SHARED_LOCK); + PROFILE_ON(); + + /* Restore DOS requesters. */ + this_process->pr_WindowPtr = old_window_pointer; + + if(lock == ZERO) + { + /* If the object does not exist yet then we + * are finished. + */ + if(IoErr() == ERROR_OBJECT_NOT_FOUND) + { + result = name_template; + break; + } + + /* Looks like a serious error. */ + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + /* OK, so it exists already. Start over... */ + + PROFILE_OFF(); + UnLock(lock); + PROFILE_ON(); + + /* Change one letter; if that 'overflows', start + * over with 'A' and move on to the next position. + */ + for(i = 0 ; i < template_len ; i++) + { + name_template[template_offset + i]++; + if(name_template[template_offset + i] <= 'Z') + break; + + name_template[template_offset + i] = 'A'; + } + } + + SHOWSTRING(name_template); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_amiga_to_unix_path_name((char const **)&name_template,&name_template_nti) != 0) + goto out; + + strcpy(original_name_template,name_template); + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + SHOWSTRING(name_template); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdlib_modsi3.c b/library/stdlib_modsi3.c new file mode 100644 index 0000000..602881e --- /dev/null +++ b/library/stdlib_modsi3.c @@ -0,0 +1,76 @@ +/* + * $Id: stdlib_modsi3.c,v 1.1.1.1 2004-07-26 16:32:01 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#ifndef __PPC__ +asm(" \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl ___modsi3 \n\ + .globl ___divsi4 \n\ + \n\ +| D1.L = D0.L % D1.L signed \n\ + \n\ +___modsi3: \n\ + \n\ + moveml sp@(4:W),d0/d1 \n\ + jbsr ___divsi4 \n\ + movel d1,d0 \n\ + rts \n\ + \n\ +"); +#else +__asm(" \n\ + .text \n\ + .align 2 \n\ + \n\ + .globl __modsi3 \n\ + .globl __divsi4 \n\ + \n\ +__modsi3: \n\ + stw r0, 20(r1) \n\ + divw r0, r3, r4 \n\ + mullw r0, r0, r4 \n\ + subf r3, r0, r3 \n\ + blr \n\ +"); +#endif + +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_mulsi3.c b/library/stdlib_mulsi3.c new file mode 100644 index 0000000..6ef0ec8 --- /dev/null +++ b/library/stdlib_mulsi3.c @@ -0,0 +1,79 @@ +/* + * $Id: stdlib_mulsi3.c,v 1.1.1.1 2004-07-26 16:32:01 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ +#ifndef __PPC__ +asm(" \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl ___mulsi3 \n\ + .globl ___UtilityBase \n\ + \n\ +| D0 = D0 * D1 \n\ + \n\ +___mulsi3: \n\ + \n\ + moveml sp@(4),d0/d1 \n\ + movel "A4(___UtilityBase)",a0 \n\ + jmp a0@(-138:W) \n\ + \n\ +"); +#else +__asm(" \n\ + .text \n\ + .align 2 \n\ + \n\ + .globl __mulsi3 \n\ + \n\ +__mulsi3: \n\ + mullw r3, r3, r4 \n\ + blr \n\ +"); +#endif +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_never_free.c b/library/stdlib_never_free.c new file mode 100644 index 0000000..516aabb --- /dev/null +++ b/library/stdlib_never_free.c @@ -0,0 +1,40 @@ +/* + * $Id: stdlib_never_free.c,v 1.1.1.1 2004-07-26 16:32:01 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +BOOL __never_free = FALSE; diff --git a/library/stdlib_null_pointer_check.h b/library/stdlib_null_pointer_check.h new file mode 100644 index 0000000..02a0c40 --- /dev/null +++ b/library/stdlib_null_pointer_check.h @@ -0,0 +1,47 @@ +/* + * $Id: stdlib_null_pointer_check.h,v 1.1.1.1 2004-07-26 16:32:01 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#define _STDLIB_NULL_POINTER_CHECK_H + +/****************************************************************************/ + +/* + * Uncomment this to build a library which checks pointer parameters against + * NULL upon entry. + */ +/*#define CHECK_FOR_NULL_POINTERS*/ + +/****************************************************************************/ + +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ diff --git a/library/stdlib_protos.h b/library/stdlib_protos.h new file mode 100644 index 0000000..c44bad7 --- /dev/null +++ b/library/stdlib_protos.h @@ -0,0 +1,224 @@ +/* + * $Id: stdlib_protos.h,v 1.1.1.1 2004-07-26 16:32:02 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_PROTOS_H +#define _STDLIB_PROTOS_H + +/****************************************************************************/ + +#ifndef EXEC_TASKS_H +#include +#endif /* EXEC_TASKS_H */ + +/****************************************************************************/ + +#ifndef _STDDEF_H +#include +#endif /* _STDDEF_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H + +/* Forward declarations */ +struct MemoryNode; +struct MemoryTree; + +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +/* math_init_exit.c */ +extern int __math_init(void); +extern void __math_exit(void); + +/****************************************************************************/ + +/* stdlib_machine_test.c */ +extern int __machine_test(void); + +/****************************************************************************/ + +/* locale_init_exit.c */ +extern int __locale_init(void); +extern void __locale_exit(void); + +/****************************************************************************/ + +/* stdio_init_exit.c */ +extern int __stdio_init(void); +extern void __stdio_exit(void); + +/****************************************************************************/ + +/* stdlib_init_exit.c */ +extern int __stdlib_init(void); +extern void __stdlib_exit(void); + +/****************************************************************************/ + +/* unistd_init_exit.c */ +extern int __unistd_init(void); +extern void __unistd_exit(void); + +/****************************************************************************/ + +/* dirent_init_exit.c */ +extern int __dirent_init(void); +extern void __dirent_exit(void); + +/****************************************************************************/ + +/* stdlib_atexit.c */ +extern void __exit_trap_trigger(void); + +/****************************************************************************/ + +/* socket_init_exit.c */ +extern int __socket_init(void); +extern void __socket_exit(void); + +/****************************************************************************/ + +/* usergroup_init_exit.c */ +extern int __usergroup_init(void); +extern void __usergroup_exit(void); + +/****************************************************************************/ + +/* stdlib_showerror.c */ +extern void __show_error(const char * message); + +/****************************************************************************/ + +/* stdlib_swap_stack.c/stdlib_swap_stack.s/stdlib_swap_stack.asm */ +extern int __swap_stack_and_call(struct StackSwapStruct * stk,APTR function); + +/****************************************************************************/ + +/* stdlib_get_sp.c/stdlib_get_sp.s/stdlib_get_sp.asm */ +extern unsigned long __get_sp(void); + +/****************************************************************************/ + +/* stdlib_wildcard_expand.c */ +extern UBYTE * __allocate_quote_vector(int num_parameters); +extern int __wildcard_expand_init(void); +extern void __wildcard_expand_exit(void); + +/****************************************************************************/ + +/* stdlib_stackextension.c */ +extern int __stk_init(void); +extern void __stk_exit(void); + +/****************************************************************************/ + +/* stdlib_stack_usage.c */ +extern void __stack_usage_init(struct StackSwapStruct * stk); +extern void __stack_usage_exit(void); + +/****************************************************************************/ + +/* stdlib_exit.c */ +extern void _exit(int return_code); + +/****************************************************************************/ + +/* stdlib_constructor_begin.c */ +void _init(void); +void _fini(void); + +/****************************************************************************/ + +/* stdlib_startup.c */ +extern int __startup_init(void); +extern void __startup_exit(void); + +/****************************************************************************/ + +/* stdlib_malloc.c */ +extern size_t __get_allocation_size(size_t size); +extern void * __allocate_memory(size_t size,BOOL never_free,const char * file,int line); +extern void * __malloc(size_t size,const char * file,int line); + +/* stdlib_free.c */ +extern struct MemoryNode * __find_memory_node(void * address); +extern void __force_free(void * ptr,const char * file,int line); +extern void __check_memory_allocations(const char * file,int line); +extern void __free_memory_node(struct MemoryNode * mn,const char * file,int line); +extern void __free(void * ptr,const char * file,int line); + +/* stdlib_alloca.c */ +extern void __alloca_cleanup(const char * file,int line); +extern void * __alloca(size_t size,const char * file,int line); + +/* stdlib_realloc.c */ +extern void * __realloc(void *ptr,size_t size,const char * file,int line); + +/****************************************************************************/ + +/* signal_checkabort.c */ +extern void __check_abort(void); + +/****************************************************************************/ + +/* stdlib_red_black.c */ +extern void __initialize_red_black_tree(struct MemoryTree *new_tree); +extern void __red_black_tree_insert(struct MemoryTree * tree, struct MemoryNode *x); +extern struct MemoryNode * __red_black_tree_find(struct MemoryTree * tree,void * allocation); +extern void __red_black_tree_remove(struct MemoryTree * tree, struct MemoryNode * z); + +/****************************************************************************/ + +/* stdlib_main.c */ +extern int _main(void); + +/****************************************************************************/ + +/* stdlib_assertion_failure.c */ +extern void __assertion_failure(const char *file_name,int line_number,const char *expression); + +/****************************************************************************/ + +/* stdlib_stackoverflow.c */ +extern void __stkovf(void); + +/****************************************************************************/ + +/* stdlib_termination_message.c */ +extern void __print_termination_message(const char * termination_message); + +/****************************************************************************/ + +#endif /* _STDLIB_PROTOS_H */ diff --git a/library/stdlib_putenv.c b/library/stdlib_putenv.c new file mode 100644 index 0000000..12e1ce7 --- /dev/null +++ b/library/stdlib_putenv.c @@ -0,0 +1,82 @@ +/* + * $Id: stdlib_putenv.c,v 1.1.1.1 2004-07-26 16:32:02 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +putenv(const char *string) +{ + int result = -1; + + ENTER(); + + SHOWSTRING(string); + + assert( string != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(string == NULL) + { + SHOWMSG("invalid string"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + result = setenv(string,"",1); + + out: + + RETURN(result); + return(result); +} diff --git a/library/stdlib_qsort.c b/library/stdlib_qsort.c new file mode 100644 index 0000000..e88403a --- /dev/null +++ b/library/stdlib_qsort.c @@ -0,0 +1,291 @@ +/* + * $Id: stdlib_qsort.c,v 1.1.1.1 2004-07-26 16:32:02 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +/****************************************************************** + * qsort.c -- Non-Recursive ANSI Quicksort function * + * * + * Public domain by Raymond Gardner, Englewood CO February 1991 * + * * + * Usage: * + * qsort(base, nbr_elements, width_bytes, compare_function); * + * void *base; * + * size_t nbr_elements, width_bytes; * + * int (*compare_function)(const void *, const void *); * + * * + * Sorts an array starting at base, of length nbr_elements, each * + * element of size width_bytes, ordered via compare_function, * + * which is called as (*compare_function)(ptr_to_element1, * + * ptr_to_element2) and returns < 0 if element1 < element2, * + * 0 if element1 = element2, > 0 if element1 > element2. * + * Most refinements are due to R. Sedgewick. See "Implementing * + * Quicksort Programs", Comm. ACM, Oct. 1978, and Corrigendum, * + * Comm. ACM, June 1979. * + ******************************************************************/ + +/******************************************************************/ + +#define SWAP(a, b, size) (swap((char *)(a), (char *)(b), size)) +#define COMPARE(a, b) ((*comp)((const void *)(a), (const void *)(b))) + +/******************************************************************/ + +/* subfiles of THRESHOLD or fewer elements will + be sorted by a simple insertion sort + Note! THRESHOLD must be at least 3 */ +#define THRESHOLD 7 + +/******************************************************************/ + +/* For an 68030 and beyond the alignment does not matter and you can skip the + second half of the test (everything beyond the 'nbytes >= sizeof(long)'). */ +#if defined(M68020) +#define IS_WORD_ALIGNED(a,b) 1 +#else +#define IS_WORD_ALIGNED(a,b) (((((unsigned long)(a)) | ((unsigned long)(b))) & 1) == 0) +#endif /* M68020 */ + +/******************************************************************/ + +/* swap nbytes between a and b */ +INLINE static void +swap(char * a, char * b, size_t nbytes) +{ + char temp; + + assert( a != NULL && b != NULL && nbytes > 0 ); + + /* This is an attempt to use 'long' sized swapping, if possible. */ + if(nbytes >= sizeof(long) && IS_WORD_ALIGNED(a,b)) + { + long *_a = (long *)a; + long *_b = (long *)b; + long _temp; + + do + { + _temp = (*_a); + (*_a++) = (*_b); + (*_b++) = _temp; + + nbytes -= sizeof(long); + } + while(nbytes >= sizeof(long)); + + if(nbytes > 0) + { + a = (char *)_a; + b = (char *)_b; + + do + { + temp = (*a); + (*a++) = (*b); + (*b++) = temp; + } + while(--nbytes > 0); + } + } + else + { + do + { + temp = (*a); + (*a++) = (*b); + (*b++) = temp; + } + while(--nbytes > 0); + } +} + +/******************************************************************/ + +void +qsort(void * base, size_t count, size_t size, int (*comp)(const void * element1, const void * element2)) +{ + ENTER(); + + SHOWPOINTER(base); + SHOWVALUE(count); + SHOWVALUE(size); + SHOWPOINTER(comp); + + assert( (int)count >= 0 && (int)size >= 0 ); + + if(count > 1 && size > 0) + { + char *stack[32 * 2], **sp; /* stack and stack pointer */ + char *i, *j, *limit; /* scan and limit pointers */ + char *base_pointer; /* base pointer as (char *) */ + size_t threshold; /* size of THRESHOLD elements in bytes */ + + assert( base != NULL && comp != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(base == NULL || comp == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + /* set up (char *) base_pointer pointer */ + base_pointer = (char *)base; + + /* init threshold */ + threshold = THRESHOLD * size; /* ZZZ problematic if (THRESHOLD * size) > 0xffffffff */ + + /* init stack pointer */ + sp = stack; + + /* pointer past end of array */ + limit = base_pointer + count * size; /* ZZZ problematic if (count * size) > 0xffffffff or (base_pointer + count * size) > 0xffffffff */ + + /* repeat until break... */ + while(TRUE) + { + /* if more than THRESHOLD elements */ + if((size_t)(limit - base_pointer) > threshold) + { + /* swap base_pointer with middle */ + SWAP((((limit - base_pointer) / size) / 2) * size + base_pointer, base_pointer, size); + + /* i scans left to right */ + i = base_pointer + size; + + /* j scans right to left */ + j = limit - size; + + /* Sedgewick's three-element sort sets things up so that + (*i) <= (*base_pointer) <= (*j); (*base_pointer) is + pivot element */ + if(COMPARE(i, j) > 0) + SWAP(i, j, size); + + if(COMPARE(base_pointer, j) > 0) + SWAP(base_pointer, j, size); + + if(COMPARE(i, base_pointer) > 0) + SWAP(i, base_pointer, size); + + /* loop until break */ + while(TRUE) + { + /* move i right until (*i) >= pivot */ + do + i += size; + while(COMPARE(i, base_pointer) < 0); + + /* move j left until (*j) <= pivot */ + do + j -= size; + while(COMPARE(j, base_pointer) > 0); + + /* break loop if pointers crossed */ + if(i > j) + break; + + /* else swap elements, keep scanning */ + SWAP(i, j, size); + } + + /* move pivot into correct place */ + SWAP(base_pointer, j, size); + + /* if left subfile larger */ + if(j - base_pointer > limit - i) + { + /* stack left subfile base_pointer and limit */ + sp[0] = base_pointer; + sp[1] = j; + + /* sort the right subfile */ + base_pointer = i; + } + else /* else right subfile larger */ + { + /* stack right subfile base_pointer and limit */ + sp[0] = i; + sp[1] = limit; + + /* sort the left subfile */ + limit = j; + } + + /* increment stack pointer */ + sp += 2; + } + else /* else subfile is small, use insertion sort */ + { + for(j = base_pointer, i = j + size; i < limit; j = i, i += size) + { + for( ; COMPARE(j, j + size) > 0; j -= size ) + { + SWAP(j, j + size, size); + if(j == base_pointer) + break; + } + } + + /* if any entries on stack pop the base_pointer and limit, + else the stack is empty and we're done */ + if(sp == stack) + break; + + sp -= 2; + + base_pointer = sp[0]; + limit = sp[1]; + } + } + } + + out: + + LEAVE(); +} diff --git a/library/stdlib_rand.c b/library/stdlib_rand.c new file mode 100644 index 0000000..07f102a --- /dev/null +++ b/library/stdlib_rand.c @@ -0,0 +1,65 @@ +/* + * $Id: stdlib_rand.c,v 1.1.1.1 2004-07-26 16:32:02 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +/* Parameters of a pseudo-random-number generator from Knuth's + * "The Art of Computer Programming, Volume 2: Seminumerical + * Algorithms" (3rd edition), pp. 185-186. + */ +#define MM 2147483647 /* a Mersenne prime */ +#define AA 48271 /* this does well in the spectral test */ +#define QQ 44488 /* (long)(MM/AA) */ +#define RR 3399 /* MM % AA; it is important that RR < QQ */ + +/****************************************************************************/ + +int +rand(void) +{ + int X; + + X = (int)__random_seed; + + X = AA * (X % QQ) - RR * (long)(X / QQ); + if(X < 0) + X += MM; + + __random_seed = (unsigned)X; + + return(X); +} diff --git a/library/stdlib_realloc.c b/library/stdlib_realloc.c new file mode 100644 index 0000000..da77610 --- /dev/null +++ b/library/stdlib_realloc.c @@ -0,0 +1,210 @@ +/* + * $Id: stdlib_realloc.c,v 1.1.1.1 2004-07-26 16:32:03 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#undef realloc + +/****************************************************************************/ + +void * +__realloc(void *ptr,size_t size,const char * file,int line) +{ + void * result = NULL; + + ENTER(); + + SHOWPOINTER(ptr); + SHOWVALUE(size); + + assert( (int)size >= 0 ); + + if(ptr == NULL) + { + D(("calling malloc(%ld)",size)); + + result = __malloc(size,file,line); + } + else if (size == 0) + { + D(("calling free(0x%08lx)",ptr)); + + __free(ptr,file,line); + } + else + { + struct MemoryNode * mn; + BOOL reallocate; + + assert( ptr != NULL && size > 0 ); + + /* Try to find the allocation in the list. */ + mn = __find_memory_node(ptr); + + #ifdef __MEM_DEBUG + { + /* If we managed to find the memory allocation, + * reallocate it. + */ + if(mn == NULL) + { + SHOWMSG("allocation not found"); + + kprintf("[%s] %s:%ld:Address for realloc(0x%08lx,%ld) not known.\n",__program_name,file,line,ptr,size); + + /* Apparently, the address did not qualify for + * reallocation. + */ + errno = ENOMEM; + goto out; + } + } + #else + { + assert( mn != NULL ); + } + #endif /* __MEM_DEBUG */ + + if(mn == NULL || mn->mn_NeverFree) + { + SHOWMSG("cannot free this chunk"); + + errno = ENOMEM; + goto out; + } + + /* Don't do anything unless the size of the allocation has really + * changed. + */ + #if defined(__MEM_DEBUG) + { + reallocate = (mn->mn_Size != size); + } + #else + { + if(size > mn->mn_Size) + { + /* Allocation size should grow. */ + reallocate = TRUE; + } + else + { + size_t rounded_allocation_size; + + /* Round the total allocation size to the operating system + * granularity. + */ + rounded_allocation_size = __get_allocation_size(size); + + assert( rounded_allocation_size >= size ); + + /* Optimization: If the block size shrinks by less than half the + * original allocation size, do not reallocate the + * block and do not copy over the contents of the old + * allocation. We also take into account that the + * actual size of the allocation is affected by a + * certain operating system imposed granularity. + */ + reallocate = (rounded_allocation_size < mn->mn_Size && rounded_allocation_size <= mn->mn_Size / 2); + } + } + #endif /* __MEM_DEBUG */ + + if(reallocate) + { + void * new_ptr; + + D(("realloc() size has changed; old=%ld, new=%ld",mn->mn_Size,size)); + + /* We allocate the new memory chunk before we + attempt to replace the old. */ + new_ptr = __malloc(size,file,line); + if(new_ptr == NULL) + { + SHOWMSG("could not reallocate memory"); + + errno = ENOMEM; + goto out; + } + + /* Copy the contents of the old allocation to the new buffer. */ + if(size > mn->mn_Size) + size = mn->mn_Size; + + memmove(new_ptr,ptr,size); + + /* Free the old allocation. Since we already know which memory + node is associated with it, we don't call __free() here. */ + __free_memory_node(mn,file,line); + + result = new_ptr; + } + else + { + D(("size didn't actually change that much (%ld -> %ld); returning memory block as is.",mn->mn_Size,size)); + + /* No change in size. */ + result = ptr; + } + } + + out: + + if(result == NULL) + SHOWMSG("ouch! realloc failed"); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +void * +realloc(void *ptr,size_t size) +{ + void * result; + + result = __realloc(ptr,size,NULL,0); + + return(result); +} diff --git a/library/stdlib_red_black.c b/library/stdlib_red_black.c new file mode 100644 index 0000000..544d7fc --- /dev/null +++ b/library/stdlib_red_black.c @@ -0,0 +1,424 @@ +/* + * $Id: stdlib_red_black.c,v 1.1.1.1 2004-07-26 16:32:03 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#if defined(__USE_MEM_TREES) && defined(__MEM_DEBUG) + +/****************************************************************************/ + +/* Red-Black Tree 'C' code adapted from Emin Martinian's implementation + (see ) */ + +/****************************************************************************/ + +static void +help_insertion (struct MemoryTree * tree, struct MemoryNode * z) +{ + struct MemoryNode *nil = &tree->mt_NullNode; + struct MemoryNode *x; + struct MemoryNode *y; + + z->mn_Left = z->mn_Right = nil; + + y = tree->mt_Root; + x = tree->mt_Root->mn_Left; + + while (x != nil) + { + y = x; + + if (x->mn_Allocation > z->mn_Allocation) + x = x->mn_Left; + else + x = x->mn_Right; + } + + z->mn_Parent = y; + + if (y == tree->mt_Root || y->mn_Allocation > z->mn_Allocation) + y->mn_Left = z; + else + y->mn_Right = z; +} + +static void +rotate_left (struct MemoryTree * tree, struct MemoryNode * x) +{ + struct MemoryNode *nil = &tree->mt_NullNode; + struct MemoryNode *y; + + y = x->mn_Right; + x->mn_Right = y->mn_Left; + + if (y->mn_Left != nil) + y->mn_Left->mn_Parent = x; + + y->mn_Parent = x->mn_Parent; + + if (x == x->mn_Parent->mn_Left) + x->mn_Parent->mn_Left = y; + else + x->mn_Parent->mn_Right = y; + + y->mn_Left = x; + x->mn_Parent = y; +} + +static void +rotate_right (struct MemoryTree * tree, struct MemoryNode * y) +{ + struct MemoryNode *nil = &tree->mt_NullNode; + struct MemoryNode *x; + + x = y->mn_Left; + y->mn_Left = x->mn_Right; + + if (nil != x->mn_Right) + x->mn_Right->mn_Parent = y; + + x->mn_Parent = y->mn_Parent; + + if (y == y->mn_Parent->mn_Left) + y->mn_Parent->mn_Left = x; + else + y->mn_Parent->mn_Right = x; + + x->mn_Right = y; + y->mn_Parent = x; +} + +/****************************************************************************/ + +static struct MemoryNode * +get_successor (struct MemoryTree * tree, struct MemoryNode * x) +{ + struct MemoryNode *nil = &tree->mt_NullNode; + struct MemoryNode *root = tree->mt_Root; + struct MemoryNode *result; + struct MemoryNode *y; + + if (nil != (y = x->mn_Right)) + { + while (y->mn_Left != nil) + y = y->mn_Left; + + result = y; + } + else + { + y = x->mn_Parent; + + while (x == y->mn_Right) + { + x = y; + y = y->mn_Parent; + } + + if (y == root) + result = nil; + else + result = y; + } + + return (result); +} + +static void +remove_fixup (struct MemoryTree * tree, struct MemoryNode * x) +{ + struct MemoryNode *root = tree->mt_Root->mn_Left; + struct MemoryNode *w; + + while (NOT x->mn_IsRed && root != x) + { + if (x == x->mn_Parent->mn_Left) + { + w = x->mn_Parent->mn_Right; + + if (w->mn_IsRed) + { + w->mn_IsRed = FALSE; + x->mn_Parent->mn_IsRed = TRUE; + + rotate_left (tree, x->mn_Parent); + + w = x->mn_Parent->mn_Right; + } + + if (NOT w->mn_Right->mn_IsRed && NOT w->mn_Left->mn_IsRed) + { + w->mn_IsRed = TRUE; + + x = x->mn_Parent; + } + else + { + if (NOT w->mn_Right->mn_IsRed) + { + w->mn_Left->mn_IsRed = FALSE; + w->mn_IsRed = TRUE; + + rotate_right (tree, w); + + w = x->mn_Parent->mn_Right; + } + + w->mn_IsRed = x->mn_Parent->mn_IsRed; + x->mn_Parent->mn_IsRed = FALSE; + w->mn_Right->mn_IsRed = FALSE; + + rotate_left (tree, x->mn_Parent); + + x = root; + } + } + else + { + w = x->mn_Parent->mn_Left; + + if (w->mn_IsRed) + { + w->mn_IsRed = FALSE; + x->mn_Parent->mn_IsRed = TRUE; + + rotate_right (tree, x->mn_Parent); + + w = x->mn_Parent->mn_Left; + } + + if (NOT w->mn_Right->mn_IsRed && NOT w->mn_Left->mn_IsRed) + { + w->mn_IsRed = TRUE; + + x = x->mn_Parent; + } + else + { + if (NOT w->mn_Left->mn_IsRed) + { + w->mn_Right->mn_IsRed = FALSE; + w->mn_IsRed = TRUE; + + rotate_left (tree, w); + + w = x->mn_Parent->mn_Left; + } + + w->mn_IsRed = x->mn_Parent->mn_IsRed; + x->mn_Parent->mn_IsRed = FALSE; + w->mn_Left->mn_IsRed = FALSE; + + rotate_right (tree, x->mn_Parent); + + x = root; + } + } + } + + x->mn_IsRed = FALSE; +} + +/****************************************************************************/ + +void +__initialize_red_black_tree (struct MemoryTree *new_tree) +{ + struct MemoryNode *temp; + + temp = &new_tree->mt_NullNode; + temp->mn_Parent = temp->mn_Left = temp->mn_Right = temp; + temp->mn_IsRed = FALSE; + temp->mn_Allocation = NULL; + + temp = new_tree->mt_Root = &new_tree->mt_RootNode; + temp->mn_Parent = temp->mn_Left = temp->mn_Right = &new_tree->mt_NullNode; + temp->mn_IsRed = FALSE; + temp->mn_Allocation = NULL; +} + +/****************************************************************************/ + +void +__red_black_tree_insert (struct MemoryTree * tree, struct MemoryNode *x) +{ + struct MemoryNode *y; + + help_insertion (tree, x); + + x->mn_IsRed = TRUE; + + while (x->mn_Parent->mn_IsRed) + { + if (x->mn_Parent == x->mn_Parent->mn_Parent->mn_Left) + { + y = x->mn_Parent->mn_Parent->mn_Right; + + if (y->mn_IsRed) + { + x->mn_Parent->mn_IsRed = FALSE; + y->mn_IsRed = FALSE; + x->mn_Parent->mn_Parent->mn_IsRed = TRUE; + x = x->mn_Parent->mn_Parent; + } + else + { + if (x == x->mn_Parent->mn_Right) + { + x = x->mn_Parent; + + rotate_left (tree, x); + } + + x->mn_Parent->mn_IsRed = FALSE; + x->mn_Parent->mn_Parent->mn_IsRed = TRUE; + + rotate_right (tree, x->mn_Parent->mn_Parent); + } + } + else + { + y = x->mn_Parent->mn_Parent->mn_Left; + + if (y->mn_IsRed) + { + x->mn_Parent->mn_IsRed = FALSE; + y->mn_IsRed = FALSE; + x->mn_Parent->mn_Parent->mn_IsRed = TRUE; + x = x->mn_Parent->mn_Parent; + } + else + { + if (x == x->mn_Parent->mn_Left) + { + x = x->mn_Parent; + + rotate_right (tree, x); + } + + x->mn_Parent->mn_IsRed = FALSE; + x->mn_Parent->mn_Parent->mn_IsRed = TRUE; + + rotate_left (tree, x->mn_Parent->mn_Parent); + } + } + } + + tree->mt_Root->mn_Left->mn_IsRed = FALSE; +} + +/****************************************************************************/ + +struct MemoryNode * +__red_black_tree_find(struct MemoryTree * tree,void * allocation) +{ + struct MemoryNode * x = tree->mt_Root->mn_Left; + struct MemoryNode * nil = &tree->mt_NullNode; + struct MemoryNode * result = NULL; + + while(x != nil) + { + if(x->mn_Allocation > allocation) + { + x = x->mn_Left; + } + else if (x->mn_Allocation < allocation) + { + x = x->mn_Right; + } + else + { + result = x; + break; + } + } + + return(result); +} + +/****************************************************************************/ + +void +__red_black_tree_remove (struct MemoryTree * tree, struct MemoryNode * z) +{ + struct MemoryNode *nil = &tree->mt_NullNode; + struct MemoryNode *root = tree->mt_Root; + struct MemoryNode *y; + struct MemoryNode *x; + + y = (z->mn_Left == nil || z->mn_Right == nil) ? z : get_successor (tree, z); + x = (y->mn_Left == nil) ? y->mn_Right : y->mn_Left; + + if (root == (x->mn_Parent = y->mn_Parent)) + { + root->mn_Left = x; + } + else + { + if (y == y->mn_Parent->mn_Left) + y->mn_Parent->mn_Left = x; + else + y->mn_Parent->mn_Right = x; + } + + if (NOT y->mn_IsRed) + remove_fixup (tree, x); + + if (y != z) + { + y->mn_Left = z->mn_Left; + y->mn_Right = z->mn_Right; + y->mn_Parent = z->mn_Parent; + y->mn_IsRed = z->mn_IsRed; + z->mn_Left->mn_Parent = z->mn_Right->mn_Parent = y; + + if (z == z->mn_Parent->mn_Left) + z->mn_Parent->mn_Left = y; + else + z->mn_Parent->mn_Right = y; + } +} + +/****************************************************************************/ + +#endif /* __USE_MEM_TREES && __MEM_DEBUG */ diff --git a/library/stdlib_setenv.c b/library/stdlib_setenv.c new file mode 100644 index 0000000..9c94835 --- /dev/null +++ b/library/stdlib_setenv.c @@ -0,0 +1,220 @@ +/* + * $Id: stdlib_setenv.c,v 1.1.1.1 2004-07-26 16:32:04 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +struct LocalVariable * __lv_root; + +/****************************************************************************/ + +int +setenv(const char *original_name, const char *original_value, int overwrite) +{ + char * name = (char *)original_name; + char * value = (char *)original_value; + char * name_copy = NULL; + struct LocalVariable * lv = NULL; + struct LocalVar * found; + int status; + int result = -1; + size_t i; + + ENTER(); + + SHOWSTRING(original_name); + SHOWSTRING(original_value); + SHOWVALUE(overwrite); + + assert(original_name != NULL || original_value != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(original_name == NULL && original_value == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + if(name != NULL) + { + for(i = 0 ; i < strlen(name) ; i++) + { + if(name[i] == '=') + { + name_copy = malloc(i+1); + if(name_copy == NULL) + { + SHOWMSG("could not create copy of name"); + goto out; + } + + memmove(name_copy,name,i); + name_copy[i] = '\0'; + + value = &name[i+1]; + name = name_copy; + break; + } + } + } + else if (value != NULL) /* && name == NULL */ + { + for(i = 0 ; i < strlen(value) ; i++) + { + if(value[i] == '=') + { + name_copy = malloc(i+1); + if(name_copy == NULL) + { + SHOWMSG("could not create copy of name"); + goto out; + } + + memmove(name_copy,value,i); + name_copy[i] = '\0'; + + name = name_copy; + value = &value[i+1]; + break; + } + } + } + + if(name == NULL || name[0] == '\0' || value == NULL) + { + SHOWMSG("invalid name"); + + errno = EINVAL; + goto out; + } + + if(NOT overwrite) + { + char buffer[10]; + + PROFILE_OFF(); + status = GetVar(name,buffer,sizeof(buffer),0); + PROFILE_ON(); + + if(status != -1) + { + SHOWMSG("variable already exists; leaving..."); + + result = 0; + goto out; + } + } + + PROFILE_OFF(); + found = FindVar(name,0); + PROFILE_ON(); + + if(found == NULL) + { + SHOWMSG("the local variable is not yet set; remembering that"); + + lv = malloc(sizeof(*lv) + strlen(name)+1); + if(lv == NULL) + { + SHOWMSG("not enough memory to remember local variable to be deleted"); + goto out; + } + + lv->lv_Next = __lv_root; + __lv_root = lv; + + lv->lv_Name = (char *)(lv+1); + strcpy(lv->lv_Name,name); + } + + if(value == NULL) + value = ""; + + SHOWSTRING(name); + SHOWSTRING(value); + + PROFILE_OFF(); + status = SetVar(name,value,(LONG)strlen(value),0); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("could not set variable"); + + if(lv != NULL) + { + __lv_root = lv->lv_Next; + free(lv); + } + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + result = 0; + + out: + + if(name_copy != NULL) + free(name_copy); + + RETURN(result); + return(result); +} diff --git a/library/stdlib_setjmp.asm b/library/stdlib_setjmp.asm new file mode 100644 index 0000000..49821e6 --- /dev/null +++ b/library/stdlib_setjmp.asm @@ -0,0 +1,98 @@ +* +* $Id: stdlib_setjmp.asm,v 1.1.1.1 2004-07-26 16:32:04 obarthel Exp $ +* +* :ts=8 +* +* Portable ISO 'C' (1994) runtime library for the Amiga computer +* Copyright (c) 2002-2004 by Olaf Barthel +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* - Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* - Neither the name of Olaf Barthel nor the names of contributors +* may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* + + include "stdlib_setjmp.i" + +****************************************************************************** + + section text,code + +****************************************************************************** + + xref _SysBase + +****************************************************************************** + + xdef @setjmp + xdef _setjmp + +@setjmp: + move.l a0,-(sp) ; "save" A0 + bra.b l1 ; we don't need to load A0 from the stack + +_setjmp: + move.l a0,-(sp) ; save A0 + move.l 8(sp),a0 ; (struct __jmp_buf *) env + +l1 move.l 4(sp),JB_RETURNADDRESS(a0) ; remember the return address + movem.l d1-d7/a0-a6,JB_D1(a0) ; save all registers, except for D0 and A7 + move.l (sp)+,JB_A0(a0) ; put the old A0 where it belongs + move.l sp,JB_A7(a0) ; put the old A7 where it belongs + + move.l _SysBase,a1 + btst #AFB_68881,AttnFlags+1(a1) ; is there an FPU installed? + beq.b l2 ; skip the following if not + + fmovem.x fp0-fp7,JB_FP0(a0) ; save all floating point registers + +l2 moveq #0,d0 ; always return 0 + rts + +****************************************************************************** + + xdef _longjmp + xdef @longjmp + +_longjmp: + move.l 4(sp),a0 ; (struct __jmp_buf *) env + move.l 8(sp),d0 ; (int) status +@longjmp: + tst.l d0 + bne.b l3 + moveq #1,d0 ; make sure that the result is always non-zero + +l3 move.l _SysBase,a1 + btst #AFB_68881,AttnFlags+1(a1) ; is there an FPU installed? + beq.b l4 ; skip the following if not + + fmovem.x JB_FP0(a0),fp0-fp7 + +l4 movem.l JB_D1(a0),d1-d7 ; restore all data registers + movem.l JB_A1(a0),a1-a7 ; restore almost all address registers, except for A0 + move.l JB_RETURNADDRESS(a0),(sp) ; fix up the return address + move.l JB_A0(a0),a0 ; restore A0 + rts ; and return to the address SetJump() was called from + +****************************************************************************** + + end diff --git a/library/stdlib_setjmp.c b/library/stdlib_setjmp.c new file mode 100644 index 0000000..e25c22e --- /dev/null +++ b/library/stdlib_setjmp.c @@ -0,0 +1,370 @@ +/* + * $Id: stdlib_setjmp.c,v 1.1.1.1 2004-07-26 16:32:05 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +#if defined(__mc68020__) + +/****************************************************************************/ + +asm(" \n\ + \n\ +AFB_68881 = 4 \n\ +AttnFlags = 297 \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl _setjmp \n\ + \n\ +_setjmp: \n\ + \n\ + movel a0,sp@- | save A0 \n\ + moveal sp@(8),a0 | (struct __jmp_buf *) env \n\ + movel sp@(4),a0@ | remember the return address \n\ + moveml d1-a6,a0@(4:W) | save all registers, except for D0 and A7 \n\ + movel sp@+,a0@(32:W) | put the old A0 where it belongs \n\ + movel sp,a0@(60:W) | put the old A7 where it belongs \n\ + \n\ + moveal "A4(_SysBase)",a1 \n\ + btst #AFB_68881,a1@(AttnFlags:W) | is there an FPU installed? \n\ + beq l0 | skip the following if not \n\ + \n\ + fmovemx fp0-fp7,a0@(64:W) | save all floating point registers \n\ + \n\ +l0: moveq #0,d0 | always return 0 \n\ + rts \n\ + \n\ +"); + +/****************************************************************************/ + +#if defined(STACK_EXTENSION) + +/****************************************************************************/ + +asm(" \n\ + \n\ +AFB_68881 = 4 \n\ +AttnFlags = 297 \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl _longjmp \n\ + .globl ___stkrst \n\ + \n\ +_longjmp: \n\ + \n\ + moveal sp@(4),a0 | (struct __jmp_buf *) env \n\ + movel sp@(8),d2 | (int) status \n\ + \n\ + tstl d2 \n\ + bne l1 | skip the following if result is non-zero \n\ + \n\ + moveq #1,d2 | make sure that the result is always non-zero \n\ + \n\ +l1: movel a0@(60:W),d0 | get the stack pointer address to restore \n\ + jbsr ___stkrst | restore the stack frame \n\ + movel d2,d0 | get the return code back \n\ + \n\ + moveal "A4(_SysBase)",a1 \n\ + btst #AFB_68881,a1@(AttnFlags:W) | is there an FPU installed? \n\ + beq l2 | skip the following if not \n\ + \n\ + fmovemx a0@(64:W),fp0-fp7 | restore all floating point registers \n\ + \n\ +l2: moveml a0@(4:W),d1-d7 | restore all data registers \n\ + moveml a0@(36:W),a1-a7 | restore almost all address registers, except for A0 \n\ + movel a0@,sp@ | restore A0 \n\ + moveal a0@(32:W),a0 | and return to the address setjmp() was called from \n\ + rts \n\ + \n\ +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +asm(" \n\ + \n\ +AFB_68881 = 4 \n\ +AttnFlags = 297 \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl _longjmp \n\ + \n\ +_longjmp: \n\ + \n\ + moveal sp@(4),a0 | (struct __jmp_buf *) env \n\ + movel sp@(8),d0 | (int) status \n\ + \n\ + tstl d0 \n\ + bne l1 | skip the following if result is non-zero\n\ + \n\ + moveq #1,d0 | make sure that the result is always non-zero\n\ + \n\ +l1: moveal "A4(_SysBase)",a1 \n\ + btst #AFB_68881,a1@(AttnFlags:W) | is there an FPU installed? \n\ + beq l2 | skip the following if not \n\ + \n\ + fmovemx a0@(64:W),fp0-fp7 | restore all floating point registers \n\ + \n\ +l2: moveml a0@(4:W),d1-d7 | restore all data registers \n\ + moveml a0@(36:W),a1-a7 | restore almost all address registers, except for A0\n\ + movel a0@,sp@ | restore A0 \n\ + moveal a0@(32:W),a0 | and return to the address setjmp() was called from\n\ + rts \n\ + \n\ +"); + +/****************************************************************************/ + +#endif /* STACK_EXTENSION */ + +/****************************************************************************/ + +#elif defined(__mc68000__) + +/****************************************************************************/ + +asm(" \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl _setjmp \n\ + \n\ +_setjmp: \n\ + \n\ + movel a0,sp@- | save A0 \n\ + moveal sp@(8),a0 | (struct __jmp_buf *) env \n\ + movel sp@(4),a0@ | remember the return address \n\ + moveml d1-a6,a0@(4:W) | save all registers, except for D0 and A7\n\ + movel sp@+,a0@(32:W) | put the old A0 where it belongs \n\ + movel sp,a0@(60:W) | put the old A7 where it belongs \n\ + moveq #0,d0 | always return 0 \n\ + rts \n\ + \n\ +"); + +/****************************************************************************/ + +#if defined(STACK_EXTENSION) + +/****************************************************************************/ + +asm(" \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl _longjmp \n\ + .globl ___stkrst \n\ + \n\ +_longjmp: \n\ + \n\ + moveal sp@(4),a0 | (struct __jmp_buf *) env \n\ + movel sp@(8),d2 | (int) status \n\ + \n\ + tstl d2 \n\ + bne l1 | skip the following if result is non-zero\n\ + \n\ + moveq #1,d2 | make sure that the result is always non-zero\n\ + \n\ +l1: movel a0@(60:W),d0 | get the stack pointer address to restore\n\ + jbsr ___stkrst | restore the stack frame \n\ + movel d2,d0 | get the return code back \n\ + \n\ + moveml a0@(4:W),d1-d7 | restore all data registers \n\ + moveml a0@(36:W),a1-a7 | restore almost all address registers, except for A0\n\ + movel a0@,sp@ | restore A0 \n\ + moveal a0@(32:W),a0 | and return to the address setjmp() was called from\n\ + rts \n\ + \n\ +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +asm(" \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl _longjmp \n\ + \n\ +_longjmp: \n\ + \n\ + moveal sp@(4),a0 | (struct __jmp_buf *) env \n\ + movel sp@(8),d0 | (int) status \n\ + \n\ + tstl d0 \n\ + bne l1 | skip the following if result is non-zero\n\ + \n\ + moveq #1,d0 | make sure that the result is always non-zero\n\ + \n\ +l1: moveml a0@(4:W),d1-d7 | restore all data registers \n\ + moveml a0@(36:W),a1-a7 | restore almost all address registers, except for A0\n\ + movel a0@,sp@ | restore A0 \n\ + moveal a0@(32:W),a0 | and return to the address setjmp() was called from\n\ + rts \n\ + \n\ +"); + +/****************************************************************************/ + +#endif /* STACK_EXTENSION */ + +/****************************************************************************/ + +#elif defined(__PPC__) + +/****************************************************************************/ + +#if defined(STACK_EXTENSION) + +/****************************************************************************/ + +#error "STACK_EXTENSION is not supported on the PowerPC" + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +__asm(" \n\ + \n\ + .text \n\ + .align 2 \n\ + \n\ + .globl setjmp \n\ + \n\ +setjmp: \n\ + \n\ + mflr r10 \n\ + mfcr r11 \n\ + mr r12, r1 \n\ + stmw r10, 0(r3) \n\ + stfd f14, 88(r3) \n\ + stfd f15, 96(r3) \n\ + stfd f16, 104(r3) \n\ + stfd f17, 112(r3) \n\ + stfd f18, 120(r3) \n\ + stfd f19, 128(r3) \n\ + stfd f20, 136(r3) \n\ + stfd f21, 144(r3) \n\ + stfd f22, 152(r3) \n\ + stfd f23, 160(r3) \n\ + stfd f24, 168(r3) \n\ + stfd f25, 176(r3) \n\ + stfd f26, 184(r3) \n\ + stfd f27, 192(r3) \n\ + stfd f28, 200(r3) \n\ + stfd f29, 208(r3) \n\ + stfd f30, 216(r3) \n\ + stfd f31, 224(r3) \n\ + li r3, 0 \n\ + blr \n\ + \n\ +"); + +__asm(" \n\ + .text \n\ + .align 2 \n\ + \n\ + .globl longjmp \n\ + \n\ +longjmp: \n\ + \n\ + lmw r10,0(r3) \n\ + mtlr r10 \n\ + mtcr r11 \n\ + mr r1,r12 \n\ + lfd f14, 88(r3) \n\ + lfd f15, 96(r3) \n\ + lfd f16, 104(r3) \n\ + lfd f17, 112(r3) \n\ + lfd f18, 120(r3) \n\ + lfd f19, 128(r3) \n\ + lfd f20, 136(r3) \n\ + lfd f21, 144(r3) \n\ + lfd f22, 152(r3) \n\ + lfd f23, 160(r3) \n\ + lfd f24, 168(r3) \n\ + lfd f25, 176(r3) \n\ + lfd f26, 184(r3) \n\ + lfd f27, 192(r3) \n\ + lfd f28, 200(r3) \n\ + lfd f29, 208(r3) \n\ + lfd f30, 216(r3) \n\ + lfd f31, 224(r3) \n\ + cmpwi r4, 0 \n\ + bne 1f \n\ + li r3,1 \n\ + blr \n\ +1: \n\ + mr r3, r4 \n\ + blr \n\ + \n\ +"); + +#endif /* defined STACK_EXTENSION */ + +/****************************************************************************/ + +#endif /* PPC */ + +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_setjmp.i b/library/stdlib_setjmp.i new file mode 100644 index 0000000..4916b11 --- /dev/null +++ b/library/stdlib_setjmp.i @@ -0,0 +1,70 @@ +* +* $Id: stdlib_setjmp.i,v 1.1.1.1 2004-07-26 16:32:06 obarthel Exp $ +* +* :ts=8 +* +* Portable ISO 'C' (1994) runtime library for the Amiga computer +* Copyright (c) 2002-2004 by Olaf Barthel +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* - Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* - Neither the name of Olaf Barthel nor the names of contributors +* may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* + + include "exec/types.i" + include "exec/execbase.i" + +****************************************************************************** + + STRUCTURE FPR,0 + LONG FPR_0 + LONG FPR_1 + LONG FPR_2 + LABEL FPR_SIZE + + STRUCTURE JB,0 + APTR JB_RETURNADDRESS + LONG JB_D1 + LONG JB_D2 + LONG JB_D3 + LONG JB_D4 + LONG JB_D5 + LONG JB_D6 + LONG JB_D7 + APTR JB_A0 + APTR JB_A1 + APTR JB_A2 + APTR JB_A3 + APTR JB_A4 + APTR JB_A5 + APTR JB_A6 + APTR JB_A7 + STRUCT JB_FP0,FPR_SIZE + STRUCT JB_FP1,FPR_SIZE + STRUCT JB_FP2,FPR_SIZE + STRUCT JB_FP3,FPR_SIZE + STRUCT JB_FP4,FPR_SIZE + STRUCT JB_FP5,FPR_SIZE + STRUCT JB_FP6,FPR_SIZE + STRUCT JB_FP7,FPR_SIZE + LABEL JB_SIZE diff --git a/library/stdlib_shell_escape.c b/library/stdlib_shell_escape.c new file mode 100644 index 0000000..39481c1 --- /dev/null +++ b/library/stdlib_shell_escape.c @@ -0,0 +1,61 @@ +/* + * $Id: stdlib_shell_escape.c,v 1.1.1.1 2004-07-26 16:32:06 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_GCC_HELP_H +#include "stdlib_gcc_help.h" +#endif /* _STDLIB_GCC_HELP_H */ + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +/* Quick "hack" to help GCC compile itself */ +#if defined(GCC_HELP_SUPPORT) + +/******************************************************************************/ + +UBYTE __shell_escape_character = '\\'; + +/******************************************************************************/ + +#else + +/******************************************************************************/ + +UBYTE __shell_escape_character = '*'; + +/******************************************************************************/ + +#endif /* GCC_HELP_SUPPORT */ diff --git a/library/stdlib_showerror.c b/library/stdlib_showerror.c new file mode 100644 index 0000000..de585a2 --- /dev/null +++ b/library/stdlib_showerror.c @@ -0,0 +1,163 @@ +/* + * $Id: stdlib_showerror.c,v 1.1.1.1 2004-07-26 16:32:06 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include + +#include + +#include + +/****************************************************************************/ + +#include + +#define __NOLIBBASE__ +#define __NOGLOBALIFACE__ +#include +#include + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#include "macros.h" + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +void +__show_error(const char * message) +{ + #if defined(__amigaos4__) + struct IntuitionIFace * IIntuition = NULL; + struct DOSIFace * IDOS = NULL; + #endif /* __amigaos4__ */ + + struct Library * IntuitionBase = NULL; + struct Library * DOSBase = NULL; + + PROFILE_OFF(); + + if(__detach || __WBenchMsg != NULL || __no_standard_io) + { + IntuitionBase = OpenLibrary("intuition.library",0); + if(IntuitionBase == NULL) + goto out; + + #if defined(__amigaos4__) + { + IIntuition = (struct IntuitionIFace *)GetInterface((struct Library *)IntuitionBase, "main", 1, 0); + if (IIntuition == NULL) + goto out; + } + #endif /* __amigaos4__ */ + + if(IntuitionBase->lib_Version >= 37) + { + struct EasyStruct es; + + memset(&es,0,sizeof(es)); + + es.es_StructSize = sizeof(es); + es.es_Title = (STRPTR)__WBenchMsg->sm_ArgList[0].wa_Name; + es.es_TextFormat = (STRPTR)message; + es.es_GadgetFormat = (STRPTR)"Sorry"; + + EasyRequestArgs(NULL,&es,NULL,NULL); + } + else + { + static struct TextAttr default_font = { (STRPTR)"topaz.font",8,FS_NORMAL,FPF_ROMFONT|FPF_DESIGNED }; + static struct IntuiText sorry_text = {0,1,JAM1,6,3,&default_font,(STRPTR)"Sorry",NULL}; + static struct IntuiText body_text = {0,1,JAM1,5,3,&default_font,(STRPTR)NULL,NULL}; + + body_text.IText = (STRPTR)message; + + AutoRequest(NULL,&body_text,NULL,&sorry_text,0,0,37 + 8 * strlen(message),46); + } + } + else + { + BPTR output; + + DOSBase = OpenLibrary("dos.library",0); + if(DOSBase == NULL) + goto out; + + #if defined(__amigaos4__) + { + IDOS = (struct DOSIFace *)GetInterface((struct Library *)DOSBase, "main", 1, 0); + if (IDOS == NULL) + goto out; + } + #endif /* __amigaos4__ */ + + output = Output(); + + Write(output,(STRPTR)message,(LONG)strlen(message)); + Write(output,"\n",1); + } + + out: + + #if defined(__amigaos4__) + { + if(IIntuition != NULL) + DropInterface((struct Interface *)IIntuition); + + if(IDOS != NULL) + DropInterface((struct Interface *)IDOS); + } + #endif /* __amigaos4__ */ + + if (IntuitionBase != NULL) + CloseLibrary(IntuitionBase); + + if (DOSBase != NULL) + CloseLibrary(DOSBase); + + PROFILE_ON(); +} diff --git a/library/stdlib_socket.c b/library/stdlib_socket.c new file mode 100644 index 0000000..4fddc09 --- /dev/null +++ b/library/stdlib_socket.c @@ -0,0 +1,51 @@ +/* + * $Id: stdlib_socket.c,v 1.1.1.1 2004-07-26 16:32:06 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +void +__socket_exit(void) +{ +} + +/****************************************************************************/ + +int +__socket_init(void) +{ + return(OK); +} diff --git a/library/stdlib_srand.c b/library/stdlib_srand.c new file mode 100644 index 0000000..54239a7 --- /dev/null +++ b/library/stdlib_srand.c @@ -0,0 +1,45 @@ +/* + * $Id: stdlib_srand.c,v 1.1.1.1 2004-07-26 16:32:06 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +void +srand(unsigned seed) +{ + /* We have to make sure that the seed is never zero. */ + __random_seed = (seed & 0x7FFFFFFF) | 1; +} diff --git a/library/stdlib_stack_usage.c b/library/stdlib_stack_usage.c new file mode 100644 index 0000000..a852f23 --- /dev/null +++ b/library/stdlib_stack_usage.c @@ -0,0 +1,117 @@ +/* + * $Id: stdlib_stack_usage.c,v 1.1.1.1 2004-07-26 16:32:07 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "stdlib_headers.h" + +/****************************************************************************/ + +#include "macros.h" + +/****************************************************************************/ + +#ifndef NDEBUG + +static struct StackSwapStruct stack_swap_struct; + +#endif /* NDEBUG */ + +/****************************************************************************/ + +#define STACK_FILL_COOKIE 0xA1 + +/****************************************************************************/ + +void +__stack_usage_init(struct StackSwapStruct * UNUSED stk) +{ + #ifndef NDEBUG + { + if(stk != NULL) + { + size_t stack_size = ((ULONG)stk->stk_Upper - (ULONG)stk->stk_Lower); + + memset(stk->stk_Lower,STACK_FILL_COOKIE,stack_size); + + stack_swap_struct = (*stk); + } + } + #endif /* NDEBUG */ +} + +/****************************************************************************/ + +void +__stack_usage_exit(void) +{ + #ifndef NDEBUG + { + if(stack_swap_struct.stk_Lower != NULL && stack_swap_struct.stk_Upper != 0) + { + const UBYTE * m = (const UBYTE *)stack_swap_struct.stk_Lower; + size_t stack_size = ((ULONG)stack_swap_struct.stk_Upper - (ULONG)stack_swap_struct.stk_Lower); + size_t total,i; + + total = 0; + + /* Figure out how much of the stack was used by checking + if the fill pattern was overwritten. */ + for(i = 0 ; i < stack_size ; i++) + { + /* Strangely, the first long word is always trashed, + even if the stack doesn't grow down this far... */ + if(i > sizeof(LONG) && m[i] != STACK_FILL_COOKIE) + break; + + total++; + } + + kprintf("[%s] total amount of stack space used = %ld bytes\n", + __program_name,stack_size - total); + + stack_swap_struct.stk_Lower = NULL; + stack_swap_struct.stk_Upper = 0; + } + + if(__stk_maxsize == 0) + { + kprintf("[%s] no stack extension was performed\n", + __program_name); + } + else + { + kprintf("[%s] maximum size of extended stack = %ld bytes, stack was extended %ld times\n", + __program_name,__stk_maxsize,__stk_extensions); + } + } + #endif /* NDEBUG */ +} diff --git a/library/stdlib_stackargbytes.c b/library/stdlib_stackargbytes.c new file mode 100644 index 0000000..f1c9573 --- /dev/null +++ b/library/stdlib_stackargbytes.c @@ -0,0 +1,38 @@ +/* + * $Id: stdlib_stackargbytes.c,v 1.1.1.1 2004-07-26 16:32:07 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +ULONG __stk_argbytes = 256; diff --git a/library/stdlib_stackcheck.c b/library/stdlib_stackcheck.c new file mode 100644 index 0000000..a3b3ddf --- /dev/null +++ b/library/stdlib_stackcheck.c @@ -0,0 +1,130 @@ +/* + * $Id: stdlib_stackcheck.c,v 1.1.1.1 2004-07-26 16:32:07 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#include "macros.h" + +/****************************************************************************/ + +#if (defined(__GNUC__) && !defined(__PPC__)) + +/****************************************************************************/ + +/* The stack extension code has its own set of these routines. */ +#ifndef STACK_EXTENSION + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl ___stkovf \n\ + .globl ___stk_limit \n\ + \n\ + .globl ___stkchk_d0 \n\ + \n\ +___stkchk_d0: \n\ + \n\ + negl d0 \n\ + addl sp,d0 \n\ + cmpl "A4(___stk_limit)",d0 \n\ + jcs overflow | if (sp-d0) < __stk_limit then we have an overflow\n\ + rts \n\ + \n\ + .globl ___stkchk_0 \n\ + \n\ +___stkchk_0: \n\ + \n\ + cmpl "A4(___stk_limit)",sp \n\ + jcs overflow | if sp < __stk_limit then we have an overflow\n\ + rts \n\ + \n\ +overflow: \n\ + \n\ + movel #0,"A4(___stk_limit)" | disable stack checking \n\ + jra ___stkovf \n\ + \n\ +"); + +/****************************************************************************/ + +#endif /* STACK_EXTENSION && !__PPC__ */ + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +int +__stk_init(void) +{ + struct Task * this_task = FindTask(NULL); + ULONG lower = (ULONG)this_task->tc_SPLower; + + #if defined(__GNUC__) + { + __stk_limit = (UBYTE *)(lower + __stk_safezone + __stk_argbytes); + } + #endif /* __GNUC__ */ + + #if defined(__SASC) + { + __base = (UBYTE *)(lower + __stk_safezone + __stk_argbytes); + } + #endif /* __SASC */ + + return(OK); +} + +void +__stk_exit(void) +{ +} diff --git a/library/stdlib_stackextension.c b/library/stdlib_stackextension.c new file mode 100644 index 0000000..97c401b --- /dev/null +++ b/library/stdlib_stackextension.c @@ -0,0 +1,612 @@ +/* + * $Id: stdlib_stackextension.c,v 1.1.1.1 2004-07-26 16:32:08 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#if (defined(__GNUC__) && !defined(__PPC__)) + +/****************************************************************************/ + +#if defined(STACK_EXTENSION) + +/****************************************************************************/ + +/* internal structure used by the stackextend code */ +struct stackframe +{ + struct stackframe * next; /* NULL if there is no next one */ + void * savesp; /* stored sp for next underlying stackframe */ + void * upper; /* end of this stackframe+1 */ +}; + +/****************************************************************************/ + +/* Local stack extension variables */ +static void * __stk_sp_lower; /* original entries of task structure */ +static void * __stk_sp_upper; /* to restore them at exit */ +static void * __stk_initial_sp_lower; /* original stackborders */ +static void * __stk_initial_sp_upper; +static struct stackframe * __stk_used; /* used stackframes */ +static struct stackframe * __stk_spare; /* spare stackframes */ + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +/* Glue code */ +asm(" + +_LVOStackSwap = -0x2dc +StackSwapStruct_SIZEOF = 12 + + .globl _SysBase + .globl ___stk_limit + +|----------------------------------------------------------------------------- + + .globl ___link_a5_0_f + +___link_a5_0_f: + + movel sp@+,a0 | load the return address into A0 + cmpl "A4(___stk_limit)",sp + jcc l0 | if SP >= __stk_limit then we are well within bounds + jbsr l2 | try to extend the stack +l0: link a5,#0:W | restore frame pointer + jmp a0@ | go to the return address + +|----------------------------------------------------------------------------- + + .globl ___sub_0_sp_f + +___sub_0_sp_f: + movel sp@+,a0 | load the return address into A0 + cmpl "A4(___stk_limit)",sp + jcc l1 | if SP >= __stk_limit then we are well within bounds + jbsr l2 | try to extend the stack +l1: jmp a0@ | go to the return address + +l2: moveq #0,d0 + moveq #0,d1 + jra ___stkext_f | try stack extension + +|----------------------------------------------------------------------------- + + .globl ___link_a5_d0_f + +___link_a5_d0_f: + movel sp@+,a0 | load the return address into A0 + movel sp,d1 + subl d0,d1 | D0 holds size of stack adjustment to make + cmpl "A4(___stk_limit)",d1 + jcc l3 | if (SP-D0) >= __stk_limit then we are well within bounds + jbsr l5 | try stack extension +l3: link a5,#0:W | restore the frame pointer + subl d0,sp | adjust the stack pointer, as required + jmp a0@ | go to the return address + +|----------------------------------------------------------------------------- + + .globl ___sub_d0_sp_f + +___sub_d0_sp_f: + movel sp@+,a0 | load the return address into A0 + movel sp,d1 + subl d0,d1 | D0 holds size of stack adjustment to make + cmpl "A4(___stk_limit)",d1 + jcc l4 | if (SP-D0) >= __stk_limit then we are well within bounds + jbsr l5 | try stack extension +l4: subl d0,sp | adjust the stack pointer, as required + jmp a0@ | go to the return address + +l5: moveq #0,d1 + jra ___stkext_f | try stack extension + +|----------------------------------------------------------------------------- + + .globl ___sub_d0_sp + +___sub_d0_sp: + movel sp@+,a0 | load the return address into A0 + movel sp,d1 + subl d0,d1 | D0 holds size of stack adjustment to make + cmpl "A4(___stk_limit)",d1 + jcc l6 | if (SP-D0) >= __stk_limit then we are well within bounds + jbsr ___stkext | try stack extension +l6: subl d0,sp | adjust the stack pointer, as required + jmp a0@ | go to the return address + +|----------------------------------------------------------------------------- + + .globl ___move_d0_sp + +___move_d0_sp: + jra ___stkrst | Straight jump into ___stkrst + +|----------------------------------------------------------------------------- + + .globl ___unlk_a5_rts + +___unlk_a5_rts: + movel d0,a0 | Preserve D0 + movel a5,d0 | A5 is stack pointer to be restored + jbsr ___stkrst + movel a0,d0 | Restore D0 + movel sp@+,a5 | Restore A5, thus performing 'unlink A5' + rts + +|----------------------------------------------------------------------------- + + .globl ___stkext + +___stkext: + moveml d0/d1/a0/a1/a6,sp@- + subw #StackSwapStruct_SIZEOF,sp + jbsr _stkext + tstl d0 + jeq s_noext + movel "A4(_SysBase)",a6 + movel sp,a0 + jsr a6@(_LVOStackSwap) +s_ret: + moveml sp@+,d0/d1/a0/a1/a6 + rts +s_noext: + addw #StackSwapStruct_SIZEOF,sp + jra s_ret + +|----------------------------------------------------------------------------- + + .globl ___stkext_f + +___stkext_f: + moveml d0/d1/a0/a1/a6,sp@- + subw #StackSwapStruct_SIZEOF,sp + jbsr _stkext_f + tstl d0 + jeq sf_noext + movel "A4(_SysBase)",a6 + movel sp,a0 + jsr a6@(_LVOStackSwap) +sf_ret: + moveml sp@+,d0/d1/a0/a1/a6 + rts +sf_noext: + addw #StackSwapStruct_SIZEOF,sp + jra sf_ret + +|----------------------------------------------------------------------------- + + .globl ___stkrst_f + +___stkrst_f: + moveml d0/d1/a0/a1/a6,sp@- + subw #StackSwapStruct_SIZEOF,sp + jbsr _stkrst_f + movel "A4(_SysBase)",a6 + movel sp,a0 + jsr a6@(_LVOStackSwap) + moveml sp@+,d0/d1/a0/a1/a6 + rts + +|----------------------------------------------------------------------------- + + .globl ___stkrst + +___stkrst: + moveml d0/d1/a0/a1/a6,sp@- + subw #StackSwapStruct_SIZEOF,sp + jbsr _stkrst | calculate either target sp or StackSwapStruct + tstl d0 | set target sp? + jeq swpfrm | jump if not + movel d0,a0 | I have a lot of preserved registers and + | returnadresses on the stack. It's necessary + | to copy them to the new location + moveq #6,d0 | 1 rts, 5 regs and 1 signal mask to copy (1+5+1)-1=6 + lea sp@(40:W),a1 | get address of uppermost byte+1 (1+5+1)*4+StackSwapStruct_SIZEOF=40 + cmpl a0,a1 | compare with target location + jls lp1 | jump if source<=target + lea a0@(-28:W),a0 | else start at lower bound (1+5+1)*4=28 + lea a1@(-28:W),a1 + movel a0,sp | set sp to reserve the room +lp0: + movel a1@+,a0@+ | copy with raising addresses + dbra d0,lp0 | as long as d0>=0. + jra endlp | ready +lp1: + movel a1@-,a0@- | copy with falling addresses + dbra d0,lp1 | as long as d0>=0 + movel a0,sp | finally set sp + jra endlp | ready +swpfrm: + movel "A4(_SysBase)",a6 + movel sp,a0 + jsr a6@(_LVOStackSwap) +endlp: + moveml sp@+,d0/d1/a0/a1/a6 | restore registers + rts | and return + +"); + +/****************************************************************************/ + +int +__stk_init(void) +{ + struct Task *task = FindTask(NULL); + + ENTER(); + + __stk_initial_sp_lower = __stk_sp_lower = task->tc_SPLower; /* Lower stack bound */ + __stk_initial_sp_upper = __stk_sp_upper = task->tc_SPUpper; /* Upper stack bound +1 */ + + SHOWPOINTER(__stk_sp_lower); + SHOWPOINTER(__stk_sp_upper); + + D(("stack size = %ld",(ULONG)__stk_sp_upper - (ULONG)__stk_sp_lower)); + + RETURN(OK); + return(OK); +} + +/****************************************************************************/ + +/* Free all spare stackframes */ +void +__stk_exit(void) +{ + ENTER(); + + if(__memory_pool == NULL) + { + struct stackframe *sf, *sf_next; + + SHOWMSG("we don't have a memory pool; cleaning up the stack frames manually"); + + for(sf = __stk_spare ; sf != NULL ; sf = sf_next) + { + sf_next = sf->next; + + FreeMem(sf, (char *)sf->upper - (char *)sf); + } + } + + __stk_spare = NULL; + + LEAVE(); +} + +/****************************************************************************/ + +/* Move a stackframe with a minimum of requiredstack bytes to the used list + and fill the StackSwapStruct structure. */ +static void +pushframe(ULONG requiredstack, struct StackSwapStruct *sss) +{ + struct stackframe *sf; + ULONG recommendedstack; + + ENTER(); + + requiredstack += __stk_safezone + __stk_argbytes; + if (requiredstack < __stk_minframe) + requiredstack = __stk_minframe; + + SHOWVALUE(requiredstack); + + recommendedstack = __stk_maxsize - __stk_size; + if (recommendedstack < requiredstack) + recommendedstack = requiredstack; + + SHOWVALUE(recommendedstack); + + for (;;) + { + sf = __stk_spare; /* get a stackframe from the spares list */ + if (sf == NULL) /* stack overflown */ + { + for ( ; recommendedstack >= requiredstack ; recommendedstack /= 2) + { + D(("allocating %ld bytes for a stack frame",recommendedstack + sizeof(struct stackframe))); + + if(__memory_pool != NULL) + sf = AllocPooled(__memory_pool,recommendedstack + sizeof(struct stackframe)); + else + sf = AllocMem(recommendedstack + sizeof(struct stackframe), MEMF_ANY); + + if (sf != NULL) + break; + + SHOWMSG("that didn't work"); + } + + if (sf == NULL) /* and we have no way to extend it :-| */ + { + SHOWMSG("bad luck... stack overflow!"); + __stkovf(); + } + + sf->upper = (char *)(sf + 1) + recommendedstack; + break; + } + + __stk_spare = sf->next; + if ((ULONG)((char *)sf->upper - (char *)(sf + 1)) >= recommendedstack) + break; + + if(__memory_pool != NULL) + FreePooled(__memory_pool, sf, (char *)sf->upper - (char *)sf); + else + FreeMem(sf, (char *)sf->upper - (char *)sf); + } + + /* Add stackframe to the used list */ + sf->next = __stk_used; + __stk_used = sf; + __stk_limit = (char *)(sf + 1) + __stk_safezone + __stk_argbytes; + + /* prepare StackSwapStruct */ + (void *)sss->stk_Pointer = (void *)sf->upper; + sss->stk_Lower = sf + 1; + (ULONG)sss->stk_Upper = (ULONG)sf->upper; + + /* Update stack statistics. */ + __stk_size += (char *)sf->upper - (char *)(sf + 1); + if (__stk_size > __stk_maxsize) + __stk_maxsize = __stk_size; + + __stk_extensions++; + + SHOWVALUE(__stk_size); + SHOWVALUE(__stk_maxsize); + SHOWVALUE(__stk_extensions); + + LEAVE(); +} + +/****************************************************************************/ + +#define STK_UPPER (__stk_used != NULL ? __stk_used->upper : __stk_initial_sp_upper) +#define STK_LOWER (__stk_used != NULL ? (void *)(__stk_used + 1) : __stk_initial_sp_lower) + +/****************************************************************************/ + +/* Allocate a new stackframe with d0 bytes minimum. */ +int +stkext(struct StackSwapStruct sss, long d0, long d1, long a0, long a1, long a6, long ret1) +{ + void *callsp = &ret1 + 1; + int cpsize = (char *)callsp - (char *)&d0; + int result; + + ENTER(); + + D(("new stack frame with at least %ld bytes space is required", d0)); + + if (callsp >= STK_UPPER || callsp < STK_LOWER) + { + SHOWMSG("that didn't turn out right"); + + result = 0; /* User intentionally left area of stackextension */ + } + else + { + pushframe((ULONG)d0, &sss); + *(char **)&sss.stk_Pointer -= cpsize; + CopyMem(&d0, sss.stk_Pointer, cpsize); + + SHOWMSG("done"); + + result = 1; + } + + RETURN (result); + return (result); +} + +/****************************************************************************/ + +/* Defined in the glue code above. */ +extern void __stkrst_f(void); + +/****************************************************************************/ + +/* Allocate a new stackframe with d0 bytes minimum, copy the callers arguments + and set his returnaddress (offset d1 from the sp when called) to stk_rst_f */ +int +stkext_f(struct StackSwapStruct sss, long d0, long d1, long a0, long a1, long a6, long ret1) +{ + void *argtop, *callsp = &ret1 + 1; + int cpsize; + int result; + + ENTER(); + + D(("new stack frame with at least %ld bytes space is required", d0)); + + if (callsp >= STK_UPPER || callsp < STK_LOWER) + { + SHOWMSG("that didn't turn out right"); + + result = 0; /* User intentionally left area of stackextension */ + } + else + { + argtop = (char *)callsp + __stk_argbytes; /* Top of area with arguments */ + if (argtop > STK_UPPER) + argtop = STK_UPPER; + + cpsize = (char *)argtop - (char *)&d0; + + pushframe((ULONG)d0, &sss); + *(char **)&sss.stk_Pointer -= cpsize; + CopyMem(&d0, sss.stk_Pointer, cpsize); + + __stk_used->savesp = (char *)callsp + d1; /* store sp */ + *(void **)((char *)sss.stk_Upper - ((char *)argtop - (char *)callsp) + d1) = &__stkrst_f; /* set returnaddress */ + + SHOWMSG("done"); + + result = 1; + } + + RETURN (result); + return (result); +} + +/****************************************************************************/ + +/* Move all used stackframes upto (and including) sf to the spares list + and fill the StackSwapStruct structure. */ +static void +popframes(struct stackframe *sf, struct StackSwapStruct *sss) +{ + struct stackframe *sf2; + + ENTER(); + + if (sf->next != NULL) + { + sss->stk_Lower = sf->next + 1; + (ULONG)sss->stk_Upper = (ULONG)sf->next->upper; + __stk_limit = (char *)(sf->next + 1) + __stk_safezone + __stk_argbytes; + } + else + { + sss->stk_Lower = __stk_sp_lower; + (ULONG)sss->stk_Upper = (ULONG)__stk_sp_upper; + __stk_limit = (char *)__stk_initial_sp_lower + __stk_safezone + __stk_argbytes; + } + + sf2 = __stk_spare; + __stk_spare = __stk_used; + __stk_used = sf->next; + sf->next = sf2; + + /* Update stack statistics. */ + for (sf2 = __stk_spare ; sf2 != sf->next ; sf2 = sf2->next) + __stk_size -= (char *)sf2->upper - (char *)(sf2 + 1); + + SHOWVALUE(__stk_size); + + LEAVE(); +} + +/****************************************************************************/ + +/* Set stackpointer back to some previous value + != NULL: on the same stackframe (returns sp) + == NULL: on another stackframe */ +void * +stkrst(struct StackSwapStruct sss, void *d0, long d1, long a0, long a1, long a6, long ret1) +{ + void *callsp = &ret1 + 1; + int cpsize = (char *)callsp - (char *)&d0; + struct stackframe *sf1, *sf2; + void * result = d0; + + ENTER(); + + if (d0 >= STK_LOWER && d0 < STK_UPPER) + goto out; + + sf1 = __stk_used; + if (sf1 == NULL) + goto out; + + for (;;) + { + sf2 = sf1->next; + if (sf2 == NULL) + { + if (d0 < __stk_initial_sp_lower || d0 >= __stk_initial_sp_upper) + goto out; + + break; + } + + if (d0 >= (void *)(sf2 + 1) && d0 < sf2->upper) /* This stackframe fits */ + break; + + sf1 = sf2; + } + + popframes(sf1, &sss); + sss.stk_Pointer = (char *)d0 - cpsize; + CopyMem(&d0, sss.stk_Pointer,cpsize); + + result = NULL; + + out: + + RETURN (result); + return (result); +} + +/****************************************************************************/ + +/* return to last stackframe */ +void +stkrst_f(struct StackSwapStruct sss, long d0, long d1, long a0, long a1, long a6) +{ + void *callsp = &a6 + 1; /* This one has no returnaddress - it's a fallback for rts */ + int cpsize = (char *)callsp - (char *)&d0; + + ENTER(); + + sss.stk_Pointer = (char *)__stk_used->savesp - cpsize; + popframes(__stk_used, &sss); + CopyMem(&d0, sss.stk_Pointer, cpsize); + + LEAVE(); +} + +/****************************************************************************/ + +#endif /* STACK_EXTENSION */ + +/****************************************************************************/ + +#endif /* __GNUC__ && !__PPC__ */ diff --git a/library/stdlib_stackminframe.c b/library/stdlib_stackminframe.c new file mode 100644 index 0000000..cc5870c --- /dev/null +++ b/library/stdlib_stackminframe.c @@ -0,0 +1,38 @@ +/* + * $Id: stdlib_stackminframe.c,v 1.1.1.1 2004-07-26 16:32:08 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +ULONG __stk_minframe = 32768; diff --git a/library/stdlib_stackoverflow.c b/library/stdlib_stackoverflow.c new file mode 100644 index 0000000..7df3cad --- /dev/null +++ b/library/stdlib_stackoverflow.c @@ -0,0 +1,80 @@ +/* + * $Id: stdlib_stackoverflow.c,v 1.1.1.1 2004-07-26 16:32:08 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +void +__stkovf(void) +{ + /* We're in trouble. */ + __stack_overflow = TRUE; + + /* This will restore things to a sane state, display an + * error requester and drop into _exit(). + */ + longjmp(__exit_jmp_buf,1); +} + +/****************************************************************************/ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#if defined(__SASC) + +/****************************************************************************/ + +VOID +_XCOVF(VOID) +{ + /* We're in trouble. */ + __stack_overflow = TRUE; + + /* This will restore things to a sane state, display an + * error requester and drop into _exit(). + */ + longjmp(__exit_jmp_buf,1); +} + +/****************************************************************************/ + +#endif /* __SASC */ diff --git a/library/stdlib_stacksafezone.c b/library/stdlib_stacksafezone.c new file mode 100644 index 0000000..1e50c72 --- /dev/null +++ b/library/stdlib_stacksafezone.c @@ -0,0 +1,38 @@ +/* + * $Id: stdlib_stacksafezone.c,v 1.1.1.1 2004-07-26 16:32:09 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/****************************************************************************/ + +ULONG __stk_safezone = 2048; diff --git a/library/stdlib_stacksize.c b/library/stdlib_stacksize.c new file mode 100644 index 0000000..0f16d9b --- /dev/null +++ b/library/stdlib_stacksize.c @@ -0,0 +1,80 @@ +/* + * $Id: stdlib_stacksize.c,v 1.1.1.1 2004-07-26 16:32:09 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_GCC_HELP_H +#include "stdlib_gcc_help.h" +#endif /* _STDLIB_GCC_HELP_H */ + +/****************************************************************************/ + +/* Quick "hack" to help GCC compile itself */ +#if defined(GCC_HELP_SUPPORT) + +/******************************************************************************/ + +#include "stdlib_headers.h" + +/******************************************************************************/ + +static unsigned int +get_default_stack_size(void) +{ + unsigned int result = 0; + char buffer[40]; + + if(GetVar("GCC_STACK_SIZE",buffer,sizeof(buffer)-1,0) > 0) + { + LONG n; + + if((StrToLong(buffer,&n) > 0) && (n > 0)) + result = (unsigned int)n; + } + + return(result); +} + +/******************************************************************************/ + +unsigned int (* __get_default_stack_size)(void) = get_default_stack_size; +char * __stack_size_string = "$STACK: 200000"; +unsigned int __stack_size = 200000; + +#else + +/******************************************************************************/ + +unsigned int __stack_size; + +/******************************************************************************/ + +#endif /* GCC_HELP_SUPPORT */ diff --git a/library/stdlib_startup.c b/library/stdlib_startup.c new file mode 100644 index 0000000..27e59a4 --- /dev/null +++ b/library/stdlib_startup.c @@ -0,0 +1,464 @@ +/* + * $Id: stdlib_startup.c,v 1.1.1.1 2004-07-26 16:32:10 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*#define DEBUG*/ + +/****************************************************************************/ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#include "stdlib_headers.h" +#include "unistd_headers.h" + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#include +#include +#include +#include +#include + +/****************************************************************************/ + +#include "macros.h" + +/****************************************************************************/ + +static struct MsgPort * old_console_task; +static BOOL restore_console_task; + +/****************************************************************************/ + +static BOOL restore_streams; + +/****************************************************************************/ + +static BPTR old_output; +static BPTR old_input; + +/****************************************************************************/ + +static BPTR output; +static BPTR input; + +/****************************************************************************/ + +char ** __argv; +int __argc; + +/****************************************************************************/ + +UBYTE * __quote_vector; + +/****************************************************************************/ + +static BOOL +is_escape_character(UBYTE c) +{ + BOOL result; + + result = (BOOL)(c == '*' || c == __shell_escape_character); + + return(result); +} + +/****************************************************************************/ + +static BOOL +is_final_quote_character(const char * str) +{ + BOOL result; + + result = (BOOL)(str[0] == '\"' && (str[1] == '\0' || isspace(str[1]))); + + return(result); +} + +/****************************************************************************/ + +int +__startup_init(void) +{ + int result = -1; + + /* Shell startup? */ + if(__WBenchMsg == NULL) + { + int number_of_arguments; + char * command_name; + int command_name_len; + char * arg_str; + int arg_len; + char * command_line; + char * str; + + /* Make a copy of the current command name string. */ + command_name_len = (int)((UBYTE *)BADDR(Cli()->cli_CommandName))[0]; + + __free_program_name = TRUE; + + command_name = AllocVec((ULONG)(command_name_len+1),MEMF_ANY); + if(command_name == NULL) + goto out; + + if(CANNOT GetProgramName(command_name,command_name_len+1)) + goto out; + + __program_name = (char *)command_name; + + /* Get the shell parameter string and find out + * how long it is, stripping a trailing line + * feed and blank spaces if necessary. + */ + arg_str = GetArgStr(); + + while((*arg_str) == ' ' || (*arg_str) == '\t') + arg_str++; + + arg_len = strlen(arg_str); + + while(arg_len > 0 && (arg_str[arg_len-1] == '\n' || arg_str[arg_len-1] == ' ' || arg_str[arg_len-1] == '\t')) + arg_len--; + + /* Make a copy of the shell parameter string. */ + command_line = malloc((size_t)(arg_len+1)); + if(command_line == NULL) + goto out; + + memmove(command_line,arg_str,(size_t)arg_len); + command_line[arg_len] = '\0'; + + /* If we have a valid command line string and a command + * name, proceed to set up the argument vector. + */ + str = command_line; + + /* Count the number of arguments. */ + number_of_arguments = 1; + + while(TRUE) + { + /* Skip leading blank space. */ + while((*str) != '\0' && isspace(*str)) + str++; + + if((*str) == '\0') + break; + + number_of_arguments++; + + /* Quoted parameter starts here? */ + if((*str) == '\"') + { + str++; + + /* Skip the quoted string. */ + while((*str) != '\0' && NOT is_final_quote_character(str)) + { + /* Escape character? */ + if(is_escape_character(*str)) + { + str++; + + if((*str) != '\0') + str++; + } + else + { + str++; + } + } + + /* Skip the closing quote. */ + if((*str) != '\0') + str++; + } + else + { + /* Skip the parameter. */ + while((*str) != '\0' && NOT isspace(*str)) + str++; + + if((*str) == '\0') + break; + } + } + + /* Put all this together into an argument vector. + * We allocate one extra slot to put a NULL pointer + * into. + */ + __argv = (char **)malloc((number_of_arguments+1) * sizeof(*__argv)); + if(__argv == NULL) + goto out; + + /* If necessary, allocate a bit vector to keep track of + * which parameters are quoted and which ones are not. + */ + __quote_vector = __allocate_quote_vector(number_of_arguments+1); + + /* The first parameter is the program name. */ + __argv[0] = command_name; + + str = command_line; + + __argc = 1; + + while(TRUE) + { + /* Skip leading blank space. */ + while((*str) != '\0' && isspace(*str)) + str++; + + if((*str) == '\0') + break; + + /* Quoted parameter starts here? */ + if((*str) == '\"') + { + char * arg; + + /* If necessary, indicate that this parameter was quoted. */ + if(__quote_vector != NULL) + __quote_vector[__argc / 8] |= 1 << (7 - (__argc & 7)); + + str++; + + __argv[__argc++] = str; + + arg = str; + + /* Process the quoted string. */ + while((*str) != '\0' && NOT is_final_quote_character(str)) + { + if(is_escape_character(*str)) + { + str++; + + switch(*str) + { + /* "*e" == "\033" */ + case 'E': + case 'e': + + (*arg++) = '\033'; + break; + + /* "*n" == "\n" */ + case 'N': + case 'n': + + (*arg++) = '\n'; + break; + + case '\0': + + /* NOTE: the termination is handled + * down below. + */ + break; + + default: + + (*arg++) = (*str); + break; + } + + if((*str) != '\0') + str++; + } + else + { + (*arg++) = (*str++); + } + } + + /* Skip the terminating quote. */ + if((*str) != '\0') + str++; + + /* Make sure that the quoted string is properly terminated. This + actually overwrites the final quote character. */ + (*arg) = '\0'; + } + else + { + __argv[__argc++] = str; + + while((*str) != '\0' && NOT isspace(*str)) + str++; + + if((*str) == '\0') + break; + + (*str++) = '\0'; + } + } + + assert( __argc == number_of_arguments ); + assert( str <= &command_line[arg_len] ); + + __argv[__argc] = NULL; + } + else + { + PROFILE_OFF(); + + __program_name = (char *)__WBenchMsg->sm_ArgList[0].wa_Name; + + __original_current_directory = CurrentDir(__WBenchMsg->sm_ArgList[0].wa_Lock); + __current_directory_changed = TRUE; + + if(__WBenchMsg->sm_ToolWindow != NULL) + { + input = Open(__WBenchMsg->sm_ToolWindow,MODE_NEWFILE); + } + else + { + static const char console_prefix[] = "CON:20/20/600/150/"; + static const char console_suffix[] = " Output/AUTO/CLOSE/WAIT"; + STRPTR window_specifier; + STRPTR tool_name; + size_t len; + + tool_name = FilePart(__WBenchMsg->sm_ArgList[0].wa_Name); + + len = strlen(console_prefix) + strlen(tool_name) + strlen(console_suffix); + + window_specifier = malloc(len+1); + if(window_specifier == NULL) + goto out; + + strcpy(window_specifier,console_prefix); + strcat(window_specifier,tool_name); + strcat(window_specifier,console_suffix); + + input = Open(window_specifier,MODE_NEWFILE); + + free(window_specifier); + } + + if(input == ZERO) + input = Open("NIL:",MODE_NEWFILE); + + if(input != ZERO) + { + struct FileHandle * fh = BADDR(input); + + /* Careful: "NIL:" will have a NULL MsgPort in the file handle. */ + if(fh->fh_Type != NULL) + { + old_console_task = SetConsoleTask(fh->fh_Type); + + output = Open("CONSOLE:",MODE_NEWFILE); + if(output != ZERO) + restore_console_task = TRUE; + else + SetConsoleTask((struct MsgPort *)old_console_task); + } + } + + if(output == ZERO) + output = Open("NIL:",MODE_NEWFILE); + + if(input == ZERO || output == ZERO) + goto out; + + old_input = SelectInput(input); + old_output = SelectOutput(output); + + restore_streams = TRUE; + + __argv = (char **)__WBenchMsg; + + PROFILE_ON(); + } + + result = 0; + + out: + + return(result); +} + +/****************************************************************************/ + +void +__startup_exit(void) +{ + PROFILE_OFF(); + + /* Now clean up after the streams set up for the Workbench + * startup... + */ + if(restore_console_task) + { + SetConsoleTask((struct MsgPort *)old_console_task); + old_console_task = NULL; + + restore_console_task = FALSE; + } + + if(restore_streams) + { + SelectInput(old_input); + old_input = ZERO; + + SelectOutput(old_output); + old_output = ZERO; + + restore_streams = FALSE; + } + + if(input != ZERO) + { + Close(input); + input = ZERO; + } + + if(output != ZERO) + { + Close(output); + output = ZERO; + } + + PROFILE_ON(); +} diff --git a/library/stdlib_strtod.c b/library/stdlib_strtod.c new file mode 100644 index 0000000..b8f4fd1 --- /dev/null +++ b/library/stdlib_strtod.c @@ -0,0 +1,307 @@ +/* + * $Id: stdlib_strtod.c,v 1.1.1.1 2004-07-26 16:32:10 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +#ifndef _MATH_FP_SUPPORT_H +#include "math_fp_support.h" +#endif /* _MATH_FP_SUPPORT_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +double +strtod(const char *str, char ** ptr) +{ + double sum = 0.0; + double new_sum; + double result; + int decimal_point_matches; + int is_negative; + int error = 0; + char c; + + ENTER(); + + SHOWSTRING(str); + SHOWPOINTER(ptr); + + assert( str != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(str == NULL) + { + SHOWMSG("invalid str parameter"); + + result = HUGE_VAL; + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + /* Skip all leading blanks. */ + while((c = (*str)) != '\0') + { + if(NOT isspace(c)) + break; + + str++; + } + + /* The first character may be a sign. */ + if((*str) == '-') + { + /* It's a negative number. */ + is_negative = 1; + + str++; + } + else + { + /* It's not going to be negative. */ + is_negative = 0; + + /* But there may be a sign we will choose to + * ignore. + */ + if((*str) == '+') + str++; + } + + /* We begin by trying to convert all the digits + * preceding the decimal point. + */ + while((c = (*str)) != '\0') + { + if('0' <= c && c <= '9') + { + str++; + + if(error == 0) + { + new_sum = (10 * sum) + (c - '0'); + if(new_sum < sum) /* overflow? */ + error = ERANGE; + else + sum = new_sum; + } + } + else + { + break; + } + } + + /* Did we find the decimal point? We accept both the + * locale configured decimal point and the plain old + * dot. + */ + decimal_point_matches = 0; + if(__locale_table[LC_NUMERIC] != NULL) + { + char * point; + + point = (char *)__locale_table[LC_NUMERIC]->loc_DecimalPoint; + if((*point) == (*str)) + { + decimal_point_matches = 1; + + /* Skip the decimal point. */ + str++; + } + } + + if(NOT decimal_point_matches) + { + if((*str) == '.') + { + decimal_point_matches = 1; + + /* Skip the decimal point. */ + str++; + } + } + + if(decimal_point_matches) + { + double divisor = 0.1; + + /* Process all digits following the decimal point. */ + while((c = (*str)) != '\0') + { + if('0' <= c && c <= '9') + { + str++; + + if(error == 0 && divisor != 0.0) + { + new_sum = sum + (c - '0') * divisor; + if(new_sum < sum) /* overflow? */ + error = ERANGE; + else + sum = new_sum; + + divisor = divisor / 10.0; + } + } + else + { + break; + } + } + } + + /* If there is a scale indicator attached, process it. */ + if((*str) == 'e' || (*str) == 'E') + { + int exponent_is_negative; + int new_exponent; + int exponent = 0; + + /* Skip the indicator. */ + str++; + + /* Take care of the exponent's sign. */ + if((*str) == '-') + { + exponent_is_negative = 1; + str++; + } + else + { + exponent_is_negative = 0; + + if((*str) == '+') + str++; + } + + /* Again, process all digits to follow. */ + while((c = (*str)) != '\0') + { + if('0' <= c && c <= '9') + { + str++; + + if(error == 0) + { + new_exponent = (10 * exponent) + (c - '0'); + if(new_exponent < exponent) /* overflow? */ + error = ERANGE; + else + exponent = new_exponent; + } + } + else + { + break; + } + } + + /* If the exponent is valid, scale the number + * accordingly. + */ + if(exponent != 0) + { + if(exponent_is_negative) + { + double divisor; + + /* A negative exponent means division. */ + divisor = pow(10.0,(double)exponent); + if(divisor != 0.0) + { + new_sum = sum / divisor; + if(new_sum == 0.0 && sum != 0.0) + error = ERANGE; + else + sum = new_sum; + } + else + { + error = ERANGE; + } + } + else + { + /* A positive exponent means multiplication. */ + new_sum = sum * pow(10.0,(double)exponent); + if(new_sum < sum) + error = ERANGE; + else + sum = new_sum; + } + } + } + + if(error != 0) + { + errno = error; + + sum = HUGE_VAL; + } + + if(is_negative) + sum = (-sum); + + result = sum; + + /* If desired, remember where we stopped reading the + * number from the buffer. + */ + if(ptr != NULL) + (*ptr) = (char *)str; + + out: + + RETURN(result); + return(result); +} + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/stdlib_strtol.c b/library/stdlib_strtol.c new file mode 100644 index 0000000..e31efd8 --- /dev/null +++ b/library/stdlib_strtol.c @@ -0,0 +1,196 @@ +/* + * $Id: stdlib_strtol.c,v 1.1.1.1 2004-07-26 16:32:10 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +long +strtol(const char *str, char **ptr, int base) +{ + BOOL is_negative; + long result = 0; + long new_sum; + long sum; + char c; + + ENTER(); + + SHOWSTRING(str); + SHOWPOINTER(ptr); + SHOWVALUE(base); + + assert(str != NULL && base >= 0); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(str == NULL) + { + SHOWMSG("invalid str parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(base < 0) + { + SHOWMSG("invalid base parameter"); + + errno = ERANGE; + goto out; + } + + /* Skip all leading blanks. */ + while((c = (*str)) != '\0') + { + if(NOT isspace(c)) + break; + + str++; + } + + /* The first character may be a sign. */ + if(c == '-') + { + /* It's a negative number. */ + is_negative = TRUE; + + str++; + } + else + { + /* It's not going to be negative. */ + is_negative = FALSE; + + /* But there may be a sign we will choose to + * ignore. + */ + if(c == '+') + str++; + } + + c = (*str); + + /* There may be a leading '0x' to indicate that what + * follows is a hexadecimal number. + */ + if(base == 0 || base == 16) + { + if((c == '0') && (str[1] == 'x' || str[1] == 'X')) + { + base = 16; + + str += 2; + + c = (*str); + } + } + + /* If we still don't know what base to use and the + * next letter to follow is a zero then this is + * probably a number in octal notation. + */ + if(base == 0) + { + if(c == '0') + base = 8; + else + base = 10; + } + + sum = 0; + + if(1 <= base && base <= 36) + { + while(c != '\0') + { + if('0' <= c && c <= '9') + c -= '0'; + else if ('a' <= c) + c -= 'a' - 10; + else if ('A' <= c) + c -= 'A' - 10; + else + break; + + /* Ignore invalid numbers. */ + if(c >= base) + break; + + new_sum = base * sum + c; + if(new_sum < sum) /* overflow? */ + { + errno = ERANGE; + + if(is_negative) + result = LONG_MIN; + else + result = LONG_MAX; + + goto out; + } + + sum = new_sum; + + str++; + + c = (*str); + } + } + + if(is_negative) + result = (-sum); + else + result = sum; + + out: + + /* If desired, remember where we stopped reading the + * number from the buffer. + */ + if(ptr != NULL) + (*ptr) = (char *)str; + + RETURN(result); + return(result); +} diff --git a/library/stdlib_strtoul.c b/library/stdlib_strtoul.c new file mode 100644 index 0000000..bdaf1ad --- /dev/null +++ b/library/stdlib_strtoul.c @@ -0,0 +1,193 @@ +/* + * $Id: stdlib_strtoul.c,v 1.1.1.1 2004-07-26 16:32:10 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +unsigned long +strtoul(const char *str, char **ptr, int base) +{ + BOOL is_negative; + unsigned long result = 0; + unsigned long new_sum; + unsigned long sum; + char c; + + ENTER(); + + SHOWSTRING(str); + SHOWPOINTER(ptr); + SHOWVALUE(base); + + assert(str != NULL && base >= 0); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(str == NULL) + { + SHOWMSG("invalid str parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(base < 0) + { + SHOWMSG("invalid base parameter"); + + errno = ERANGE; + goto out; + } + + /* Skip all leading blanks. */ + while((c = (*str)) != '\0') + { + if(NOT isspace(c)) + break; + + str++; + } + + /* The first character may be a sign. */ + if(c == '-') + { + /* It's a negative number. */ + is_negative = TRUE; + + str++; + } + else + { + /* It's not going to be negative. */ + is_negative = FALSE; + + /* But there may be a sign we will choose to + * ignore. + */ + if(c == '+') + str++; + } + + c = (*str); + + /* There may be a leading '0x' to indicate that what + * follows is a hexadecimal number. + */ + if(base == 0 || base == 16) + { + if((c == '0') && (str[1] == 'x' || str[1] == 'X')) + { + base = 16; + + str += 2; + + c = (*str); + } + } + + /* If we still don't know what base to use and the + * next letter to follow is a zero then this is + * probably a number in octal notation. + */ + if(base == 0) + { + if(c == '0') + base = 8; + else + base = 10; + } + + sum = 0; + + if(1 <= base && base <= 36) + { + while(c != '\0') + { + if('0' <= c && c <= '9') + c -= '0'; + else if ('a' <= c) + c -= 'a' - 10; + else if ('A' <= c) + c -= 'A' - 10; + else + break; + + /* Ignore invalid numbers. */ + if(c >= base) + break; + + new_sum = base * sum + c; + if(new_sum < sum) /* overflow? */ + { + errno = ERANGE; + + result = ULONG_MAX; + + goto out; + } + + sum = new_sum; + + str++; + + c = (*str); + } + } + + if(is_negative) + result = (-sum); + else + result = sum; + + out: + + /* If desired, remember where we stopped reading the + * number from the buffer. + */ + if(ptr != NULL) + (*ptr) = (char *)str; + + RETURN(result); + return(result); +} diff --git a/library/stdlib_swapstack.asm b/library/stdlib_swapstack.asm new file mode 100644 index 0000000..abb4b74 --- /dev/null +++ b/library/stdlib_swapstack.asm @@ -0,0 +1,67 @@ +* +* $Id: stdlib_swapstack.asm,v 1.1.1.1 2004-07-26 16:32:11 obarthel Exp $ +* +* :ts=8 +* +* Portable ISO 'C' (1994) runtime library for the Amiga computer +* Copyright (c) 2002-2004 by Olaf Barthel +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* - Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* - Neither the name of Olaf Barthel nor the names of contributors +* may be used to endorse or promote products derived from this +* software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* + + include "exec/macros.i" + + section text,code + +_LVOStackSwap equ -732 + + xref _SysBase + + xdef ___swap_stack_and_call + +___swap_stack_and_call: + + movem.l d2/a2/a3/a6,-(sp) + + move.l _SysBase,a6 + + move.l 20(sp),a2 + move.l 24(sp),a3 + + move.l a2,a0 + jsr _LVOStackSwap(a6) + + jsr (a3) + move.l d0,d2 + + move.l a2,a0 + jsr _LVOStackSwap(a6) + + move.l d2,d0 + + movem.l (sp)+,d2/a2/a3/a6 + rts + + end diff --git a/library/stdlib_swapstack.c b/library/stdlib_swapstack.c new file mode 100644 index 0000000..6c94b1a --- /dev/null +++ b/library/stdlib_swapstack.c @@ -0,0 +1,149 @@ +/* + * $Id: stdlib_swapstack.c,v 1.1.1.1 2004-07-26 16:32:11 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +#ifndef __PPC__ + +/****************************************************************************/ + +asm(" \n\ + .text \n\ + .even \n\ + \n\ +_LVOStackSwap = -732 \n\ + \n\ + .globl _SysBase \n\ + .globl ___swap_stack_and_call \n\ + \n\ +___swap_stack_and_call: \n\ + \n\ + moveml d2/a2/a3/a6,sp@- \n\ + movel sp@(20),a2 \n\ + movel sp@(24),a3 \n\ + movel "A4(_SysBase)",a6 \n\ + \n\ + movel a2,a0 \n\ + jsr a6@(_LVOStackSwap:W) \n\ + \n\ + jsr a3@ \n\ + movel d0,d2 \n\ + \n\ + movel a2,a0 \n\ + jsr a6@(_LVOStackSwap:W) \n\ + \n\ + movel d2,d0 \n\ + \n\ + moveml sp@+,d2/a2/a3/a6 \n\ + \n\ + rts \n\ + \n\ +"); + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +__asm(" \n\ + \n\ + .text \n\ + .align 2 \n\ + \n\ + .set MainInterface, 632 \n\ + .set IExec_StackSwap, 272 \n\ + \n\ + .globl SysBase \n\ + .globl __swap_stack_and_call \n\ + \n\ +__swap_stack_and_call: \n\ + stwu r1, -32(r1) # Make a stack frame \n\ + mflr r0 \n\ + stw r0, 36(r1) \n\ + stmw r29, 8(r1) # Get us three GPRs \n\ + # r29 will store IExec \n\ + mr r4, r31 # Backup ptr to function to call \n\ + mr r3, r30 # Backup ptr to StackSwapStruct \n\ + \n\ + lis r3, SysBase@ha # Retrieve sysbase pointer \n\ + lwz r3, SysBase@l(r3) \n\ + lwz r29, MainInterface(r3) # Get IExec \n\ + \n\ + addi r3, r29, IExec_StackSwap # StackSwap entry \n\ + mr r4, r30 # StackSwap struct in r4 \n\ + mtlr r3 \n\ + blrl # IExec->StackSwap(r4) \n\ + \n\ + mtlr r31 # Call payload \n\ + blrl \n\ + \n\ + addi r3, r29, IExec_StackSwap # Revert to old stack \n\ + mr r4, r30 \n\ + mtlr r3 \n\ + blrl \n\ + \n\ + lmw r29, 8(r1) # Restore registers \n\ + lwz r0, 36(r1) \n\ + mtlr r0 \n\ + addi r1, r1, 32 # Clean up stack \n\ + \n\ + blr \n\ + \n\ +"); + +/****************************************************************************/ + +#endif /* __PPC__ */ + +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_sysbase.c b/library/stdlib_sysbase.c new file mode 100644 index 0000000..0a7a0b0 --- /dev/null +++ b/library/stdlib_sysbase.c @@ -0,0 +1,47 @@ +/* + * $Id: stdlib_sysbase.c,v 1.1.1.1 2004-07-26 16:32:11 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#define __NOLIBBASE__ +#include + +/****************************************************************************/ + +struct ExecBase * SysBase; + +/****************************************************************************/ + +#if defined(__amigaos4__) + +struct ExecIFace * IExec; + +#endif /* __amigaos4__ */ diff --git a/library/stdlib_system.c b/library/stdlib_system.c new file mode 100644 index 0000000..8377f04 --- /dev/null +++ b/library/stdlib_system.c @@ -0,0 +1,185 @@ +/* + * $Id: stdlib_system.c,v 1.1.1.1 2004-07-26 16:32:12 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +int +system(const char * command) +{ + char * command_copy = NULL; + int result; + + ENTER(); + + if(command == NULL) + SHOWPOINTER(command); + else + SHOWSTRING(command); + + if(__check_abort_enabled) + __check_abort(); + + /* A NULL pointer for the name of the command to execute is + * really a query to find out whether a shell is available. + * We return 1 (TRUE). + */ + if(command == NULL) + { + result = 1; + } + else + { + STATIC const struct TagItem system_tags[2] = + { + { SYS_UserShell, TRUE }, + { TAG_END, 0 } + }; + + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info command_nti; + #endif /* UNIX_PATH_SEMANTICS */ + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + char just_the_command_name[MAXPATHLEN+1]; + BOOL need_quotes = FALSE; + char * command_name; + size_t command_len; + BOOL have_quote; + size_t len; + size_t i; + + /* We may need to replace the path specified for the command, + so let's figure out first how long the command name, + including everything, really is. */ + len = strlen(command); + command_len = len; + + have_quote = FALSE; + for(i = 0 ; i < len ; i++) + { + if(command[i] == '\"') + { + need_quotes = TRUE; + have_quote ^= TRUE; + } + + if((command[i] == ' ' || command[i] == '\t') && NOT have_quote) + { + command_len = i; + break; + } + } + + /* This may be too long for proper translation... */ + if(command_len > MAXPATHLEN) + { + errno = ENAMETOOLONG; + + result = -1; + goto out; + } + + /* Grab the command name itself, then have it translated. */ + command_name = just_the_command_name; + for(i = 0 ; i < command_len ; i++) + { + if(command[i] != '\"') + (*command_name++) = command[i]; + } + + (*command_name) = '\0'; + + command_name = just_the_command_name; + + if(__translate_unix_to_amiga_path_name((const char **)&command_name,&command_nti) != 0) + { + result = -1; + goto out; + } + + /* Now put it all together again */ + command_copy = malloc(1 + strlen(command_name) + 1 + strlen(&command[command_len]) + 1); + if(command_copy == NULL) + { + errno = ENOMEM; + result = -1; + goto out; + } + + if(need_quotes) + { + command_copy[0] = '\"'; + + strcpy(&command_copy[1],command_name); + strcat(command_copy,"\""); + } + else + { + strcpy(command_copy,command_name); + } + + strcat(command_copy,&command[command_len]); + + command = command_copy; + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + SHOWSTRING(command); + + PROFILE_OFF(); + result = SystemTagList((STRPTR)command, (struct TagItem *)system_tags); + PROFILE_ON(); + } + + out: + + if(command_copy != NULL) + free(command_copy); + + RETURN(result); + return(result); +} diff --git a/library/stdlib_termination_message.c b/library/stdlib_termination_message.c new file mode 100644 index 0000000..c74292b --- /dev/null +++ b/library/stdlib_termination_message.c @@ -0,0 +1,62 @@ +/* + * $Id: stdlib_termination_message.c,v 1.1.1.1 2004-07-26 16:32:12 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +#ifndef _SIGNAL_HEADERS_H +#include "signal_headers.h" +#endif /* _SIGNAL_HEADERS_H */ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +const char __abnormal_program_termination[] = "Abnormal program termination\n"; + +/****************************************************************************/ + +void +__print_termination_message(const char * termination_message) +{ + if(NOT __termination_message_printed) + { + __termination_message_printed = TRUE; + + if(NOT __termination_message_disabled && NOT __no_standard_io) + fputs(termination_message,stderr); + } +} diff --git a/library/stdlib_threshold.c b/library/stdlib_threshold.c new file mode 100644 index 0000000..1da49fd --- /dev/null +++ b/library/stdlib_threshold.c @@ -0,0 +1,40 @@ +/* + * $Id: stdlib_threshold.c,v 1.1.1.1 2004-07-26 16:32:12 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +ULONG __free_memory_threshold; diff --git a/library/stdlib_udivmodsi3.c b/library/stdlib_udivmodsi3.c new file mode 100644 index 0000000..e8034ec --- /dev/null +++ b/library/stdlib_udivmodsi3.c @@ -0,0 +1,79 @@ +/* + * $Id: stdlib_udivmodsi3.c,v 1.1.1.1 2004-07-26 16:32:12 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ + +asm(" + + .text + .even + + .globl ___umodsi3 + .globl ___UtilityBase + +| D1.L = D0.L % D1.L unsigned + +___umodsi3: + + moveml sp@(4:W),d0/d1 + jbsr ___udivsi4 + movel d1,d0 + rts + + .globl ___udivsi3 + +| D0.L = D0.L / D1.L unsigned + +___udivsi3: + moveml sp@(4:W),d0/d1 +___udivsi4: + movel "A4(___UtilityBase)",a0 + jmp a0@(-156:W) + +"); + +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_udivsi3.c b/library/stdlib_udivsi3.c new file mode 100644 index 0000000..da16baf --- /dev/null +++ b/library/stdlib_udivsi3.c @@ -0,0 +1,68 @@ +/* + * $Id: stdlib_udivsi3.c,v 1.1.1.1 2004-07-26 16:32:12 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(__GNUC__) + +/****************************************************************************/ +#ifndef __PPC__ +asm(" \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl ___udivsi3 \n\ + .globl ___udivsi4 \n\ + \n\ +| D0.L = D0.L / D1.L unsigned \n\ + \n\ +___udivsi3: \n\ + \n\ + moveml sp@(4:W),d0/d1 \n\ + jbra ___udivsi4 \n\ + \n\ +"); +#else +__asm(" \n\ + .text \n\ + .align 2 \n\ + \n\ + .globl __udivsi3 \n\ +__udivsi3: \n\ + divwu r3, r3, r4 \n\ + blr \n\ +"); +#endif + +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_udivsi4.c b/library/stdlib_udivsi4.c new file mode 100644 index 0000000..99f9257 --- /dev/null +++ b/library/stdlib_udivsi4.c @@ -0,0 +1,76 @@ +/* + * $Id: stdlib_udivsi4.c,v 1.1.1.1 2004-07-26 16:32:12 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#if defined(SMALL_DATA) +#define A4(x) "a4@(" #x ":W)" +#elif defined(SMALL_DATA32) +#define A4(x) "a4@(" #x ":L)" +#else +#define A4(x) #x +#endif /* SMALL_DATA */ + +/****************************************************************************/ +#ifndef __PPC__ +asm(" \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl ___udivsi4 \n\ + .globl ___UtilityBase \n\ + \n\ +___udivsi4: \n\ + \n\ + movel "A4(___UtilityBase)",a0 \n\ + jmp a0@(-156:W) \n\ + \n\ +"); +#else +__asm(" \n\ + .text \n\ + .align 2 \n\ + \n\ + .globl __udivsi4 \n\ +__udivsi4: \n\ + divwu r3, r3, r4 \n\ + blr \n\ +"); +#endif + +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_umodsi3.c b/library/stdlib_umodsi3.c new file mode 100644 index 0000000..ad7cb14 --- /dev/null +++ b/library/stdlib_umodsi3.c @@ -0,0 +1,74 @@ +/* + * $Id: stdlib_umodsi3.c,v 1.1.1.1 2004-07-26 16:32:13 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(__GNUC__) + +/****************************************************************************/ + +#ifndef __PPC__ +asm(" \n\ + \n\ + .text \n\ + .even \n\ + \n\ + .globl ___umodsi3 \n\ + .globl ___udivsi4 \n\ + \n\ +| D1.L = D0.L % D1.L unsigned \n\ + \n\ +___umodsi3: \n\ + \n\ + moveml sp@(4:W),d0/d1 \n\ + jbsr ___udivsi4 \n\ + movel d1,d0 \n\ + rts \n\ + \n\ +"); +#else +__asm(" \n\ + .text \n\ + .align 2 \n\ + \n\ + .globl __umodsi3 \n\ + \n\ +__umodsi3: \n\ + divwu r0,r3,r4 \n\ + mullw r0,r0,r4 \n\ + subf r3,r0,r3 \n\ + blr \n\ +"); + +#endif +/****************************************************************************/ + +#endif /* __GNUC__ */ diff --git a/library/stdlib_unsetenv.c b/library/stdlib_unsetenv.c new file mode 100644 index 0000000..ca24785 --- /dev/null +++ b/library/stdlib_unsetenv.c @@ -0,0 +1,101 @@ +/* + * $Id: stdlib_unsetenv.c,v 1.1.1.1 2004-07-26 16:32:13 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +void +unsetenv(const char *original_name) +{ + char * name = (char *)original_name; + char * name_copy = NULL; + unsigned i; + + __check_abort(); + + assert( name != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + for(i = 0 ; i < strlen(name) ; i++) + { + if(name[i] == '=') + { + name_copy = malloc(i+1); + if(name_copy == NULL) + goto out; + + memmove(name_copy,name,i); + name_copy[i] = '\0'; + + name = name_copy; + break; + } + } + + PROFILE_OFF(); + DeleteVar(name,0); + PROFILE_ON(); + + out: + + if(name_copy != NULL) + free(name_copy); +} diff --git a/library/stdlib_usergroup.c b/library/stdlib_usergroup.c new file mode 100644 index 0000000..67f307e --- /dev/null +++ b/library/stdlib_usergroup.c @@ -0,0 +1,51 @@ +/* + * $Id: stdlib_usergroup.c,v 1.1.1.1 2004-07-26 16:32:13 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +void +__usergroup_exit(void) +{ +} + +/****************************************************************************/ + +int +__usergroup_init(void) +{ + return(OK); +} diff --git a/library/stdlib_wcstombs.c b/library/stdlib_wcstombs.c new file mode 100644 index 0000000..bac4779 --- /dev/null +++ b/library/stdlib_wcstombs.c @@ -0,0 +1,45 @@ +/* + * $Id: stdlib_wcstombs.c,v 1.1.1.1 2004-07-26 16:32:13 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +size_t +wcstombs(char *s, const wchar_t *pwcs, size_t n) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/stdlib_wctomb.c b/library/stdlib_wctomb.c new file mode 100644 index 0000000..ad8ad33 --- /dev/null +++ b/library/stdlib_wctomb.c @@ -0,0 +1,45 @@ +/* + * $Id: stdlib_wctomb.c,v 1.1.1.1 2004-07-26 16:32:13 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +int +wctomb(char *s, wchar_t wchar) +{ + /* ZZZ unimplemented */ + return(-1); +} diff --git a/library/stdlib_wildcard_expand.c b/library/stdlib_wildcard_expand.c new file mode 100644 index 0000000..2b1a5fe --- /dev/null +++ b/library/stdlib_wildcard_expand.c @@ -0,0 +1,65 @@ +/* + * $Id: stdlib_wildcard_expand.c,v 1.1.1.1 2004-07-26 16:32:13 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +UBYTE * WEAK __allocate_quote_vector(int num_parameters UNUSED); +int WEAK __wildcard_expand_init(void); +void WEAK __wildcard_expand_exit(void); + +/****************************************************************************/ + +UBYTE * +__allocate_quote_vector(int UNUSED num_parameters) +{ + return(NULL); +} + +/****************************************************************************/ + +int +__wildcard_expand_init(void) +{ + return(0); +} + +/****************************************************************************/ + +void +__wildcard_expand_exit(void) +{ +} diff --git a/library/string_bcmp.c b/library/string_bcmp.c new file mode 100644 index 0000000..c4ae4e6 --- /dev/null +++ b/library/string_bcmp.c @@ -0,0 +1,55 @@ +/* + * $Id: string_bcmp.c,v 1.1.1.1 2004-07-26 16:32:14 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +bcmp(const void *a,const void *b,size_t len) +{ + int result; + + assert( a != NULL && b != NULL ); + assert( (int)len >= 0 ); + + result = memcmp(a,b,len); + + return(result); +} diff --git a/library/string_bcopy.c b/library/string_bcopy.c new file mode 100644 index 0000000..9821635 --- /dev/null +++ b/library/string_bcopy.c @@ -0,0 +1,50 @@ +/* + * $Id: string_bcopy.c,v 1.1.1.1 2004-07-26 16:32:14 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +void +bcopy(const void *src,void *dest,size_t len) +{ + assert( (len == 0) || (src != NULL && dest != NULL && (int)len > 0) ); + + memmove(dest,src,len); +} diff --git a/library/string_bzero.c b/library/string_bzero.c new file mode 100644 index 0000000..dc7378a --- /dev/null +++ b/library/string_bzero.c @@ -0,0 +1,50 @@ +/* + * $Id: string_bzero.c,v 1.1.1.1 2004-07-26 16:32:14 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +void +bzero(void *m,size_t len) +{ + assert( (len == 0) || (m != NULL && (int)len > 0) ); + + memset(m,0,len); +} diff --git a/library/string_headers.h b/library/string_headers.h new file mode 100644 index 0000000..6a34754 --- /dev/null +++ b/library/string_headers.h @@ -0,0 +1,60 @@ +/* + * $Id: string_headers.h,v 1.1.1.1 2004-07-26 16:32:14 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STRING_HEADERS_H +#define _STRING_HEADERS_H + +/****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +/****************************************************************************/ + +#ifndef _STDLIB_LOCALE_UTILITY_H +#include "stdlib_locale_utility.h" +#endif /* _STDLIB_LOCALE_UTILITY_H */ + +/****************************************************************************/ + +#include "macros.h" +#include "debug.h" + +/****************************************************************************/ + +#endif /* _STRING_HEADERS_H */ diff --git a/library/string_index.c b/library/string_index.c new file mode 100644 index 0000000..82104d2 --- /dev/null +++ b/library/string_index.c @@ -0,0 +1,52 @@ +/* + * $Id: string_index.c,v 1.1.1.1 2004-07-26 16:32:14 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +char * +index(const char *s, int c) +{ + char * result; + + result = strchr(s,c); + + return(result); +} diff --git a/library/string_memchr.c b/library/string_memchr.c new file mode 100644 index 0000000..adb92c0 --- /dev/null +++ b/library/string_memchr.c @@ -0,0 +1,225 @@ +/* + * $Id: string_memchr.c,v 1.1.1.1 2004-07-26 16:32:15 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +#define IS_UNALIGNED(a) ((((unsigned long)(a)) & 1) != 0) +#define IS_SHORT_ALIGNED(a) ((((unsigned long)(a)) & 3) == 2) +#define IS_LONG_ALIGNED(a) ((((unsigned long)(a)) & 1) == 0) + +/****************************************************************************/ + +/* Check if one of the four bytes which make up a long word is zero. */ +#define LONG_CONTAINS_ZERO_OCTET(x) (((x) + 0xfefefeff) & ~((x) | 0x7f7f7f7f)) + +/****************************************************************************/ + +INLINE static void * +__memchr(const unsigned char * m,unsigned char val,size_t len) +{ + void * result = NULL; + + assert( m != NULL && len > 0 ); + + /* The setup below is intended to speed up searching in larger + * memory blocks. This can be very elaborate and should not be + * done unless a payoff can be expected. + */ + if(len > 4 * sizeof(long)) + { + /* Try to align the memory block to an even address. */ + if(IS_UNALIGNED(m)) + { + len--; + + if((*m) == val) + { + result = (void *)m; + goto out; + } + + m++; + } + + /* Try to align the memory block to an address which is + * a multiple of a long word. + */ + if(len >= sizeof(short) && IS_SHORT_ALIGNED(m)) + { + len--; + + if((*m) == val) + { + result = (void *)m; + goto out; + } + + m++; + + len--; + + if((*m) == val) + { + result = (void *)m; + goto out; + } + + m++; + } + + /* If the memory block is aligned to an address from which + * data can be read one long word at a time, perform the + * search in this manner. + */ + if(len >= sizeof(long) && IS_LONG_ALIGNED(m)) + { + const unsigned long * _m = (const unsigned long *)m; + unsigned long _val = val; + unsigned long x; + + /* Build a long word which contains the byte value to + * find, repeated four times. + */ + _val |= (_val << 8); + _val |= (_val << 16); + + do + { + /* Technically, what we want to achieve is to look + * at a single long word and be able to tell whether + * it contains the value we are looking for in one + * of the octets which it consists of. This is + * achieved by an XOR operation which sets those + * octets to zero which match the search value. The + * result of this operation is then tested to see + * whether it contains any zero octets. + */ + x = (*_m) ^ _val; + if(LONG_CONTAINS_ZERO_OCTET(x)) + { + /* We got what we wanted. Now figure out which byte + * would match the value we were looking for. + */ + m = (const unsigned char *)_m; + goto out; + } + + _m++; + len -= sizeof(long); + } + while(len >= sizeof(long)); + + m = (const unsigned char *)_m; + } + } + + out: + + /* If there are bytes left in need of comparison, take + * care of them here. This also includes 'aborted' + * comparison attempts from above. + */ + while(len-- > 0) + { + if((*m) == val) + { + result = (void *)m; + break; + } + + m++; + } + + return(result); +} + +/****************************************************************************/ + +void * +memchr(const void * ptr, int val, size_t len) +{ + const unsigned char * m = ptr; + void * result = NULL; + + assert( ptr != NULL ); + assert( (int)len >= 0 ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(ptr == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(len > 0) + { + #if 0 + { + val &= 255; + + do + { + if((*m) == val) + { + result = (void *)m; + break; + } + + m++; + } + while(--len > 0); + } + #else + { + result = __memchr(m,(unsigned char)(val & 255),len); + } + #endif + } + + out: + + return(result); +} diff --git a/library/string_memcmp.c b/library/string_memcmp.c new file mode 100644 index 0000000..ec9ba7b --- /dev/null +++ b/library/string_memcmp.c @@ -0,0 +1,205 @@ +/* + * $Id: string_memcmp.c,v 1.1.1.1 2004-07-26 16:32:15 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +#define IS_UNALIGNED(a) ((((unsigned long)(a)) & 1) != 0) +#define IS_SHORT_ALIGNED(a) ((((unsigned long)(a)) & 3) == 2) +#define IS_LONG_ALIGNED(a) ((((unsigned long)(a)) & 1) == 0) + +/****************************************************************************/ + +INLINE static int +__memcmp(const char *m1,const char *m2,size_t len) +{ + int result = 0; + + assert( m1 != NULL && m2 != NULL && len > 0 ); + + /* The setup below is intended to speed up searching in larger + * memory blocks. This can be very elaborate and should not be + * done unless a payoff can be expected. + */ + if(len > 4 * sizeof(long)) + { + /* Try to align both memory blocks to even addresses. */ + if(IS_UNALIGNED(m1) && IS_UNALIGNED(m2)) + { + len--; + + if((*m1) != (*m2)) + { + result = (*m1) - (*m2); + goto out; + } + + m1++; + m2++; + } + + /* Try to align both memory blocks to addresses which are a + * long word multiple. + */ + if(len >= sizeof(short) && IS_SHORT_ALIGNED(m1) && IS_SHORT_ALIGNED(m2)) + { + const short * _m1 = (const short *)m1; + const short * _m2 = (const short *)m2; + + /* Check if the two words are different, and if they are, + * figure out down below which of the bytes were different. + */ + if((*_m1++) != (*_m2++)) + goto out; + + m1 = (const char *)_m1; + m2 = (const char *)_m2; + + len -= sizeof(short); + } + + /* If both memory blocks are aligned to addresses which can be + * read directly one long word at a time, perform the comparison + * in that manner. + */ + if(len >= sizeof(long) && IS_LONG_ALIGNED(m1) && IS_LONG_ALIGNED(m2)) + { + const long * _m1 = (const long *)m1; + const long * _m2 = (const long *)m2; + + do + { + /* If the two long words are different, figure out down + * below which of the bytes were different. + */ + if((*_m1) != (*_m2)) + { + m1 = (const char *)_m1; + m2 = (const char *)_m2; + + goto out; + } + + _m1++; + _m2++; + + len -= sizeof(long); + } + while(len >= sizeof(long)); + + m1 = (const char *)_m1; + m2 = (const char *)_m2; + } + } + + out: + + /* If there are bytes left in need of comparison, take + * care of them here. This also includes 'aborted' + * comparison attempts from above. + */ + while(len-- > 0) + { + if((*m1) != (*m2)) + { + result = (*m1) - (*m2); + break; + } + + m1++; + m2++; + } + + return(result); +} + +/****************************************************************************/ + +int +memcmp(const void *ptr1, const void *ptr2, size_t len) +{ + int result = 0; + + assert( ptr1 != NULL && ptr2 != NULL ); + assert( (int)len >= 0 ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(ptr1 == NULL || ptr2 == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(ptr1 != ptr2 && len > 0) + { + const char * m1 = ptr1; + const char * m2 = ptr2; + + #if 0 + { + do + { + if((*m1) != (*m2)) + { + result = (*m1) - (*m2); + break; + } + + m1++; + m2++; + } + while(--len > 0); + } + #else + { + result = __memcmp(m1,m2,len); + } + #endif + } + + out: + + return(result); +} diff --git a/library/string_memcpy.c b/library/string_memcpy.c new file mode 100644 index 0000000..a95e2a7 --- /dev/null +++ b/library/string_memcpy.c @@ -0,0 +1,370 @@ +/* + * $Id: string_memcpy.c,v 1.1.1.1 2004-07-26 16:32:15 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +#if (defined(__GNUC__) && defined(__mc68020__) && defined(NDEBUG) && defined(undefined)) + +/****************************************************************************/ + +asm(" + .text + .even + + .globl ___bcopy + +___bcopy: + + moveml sp@(4),a0-a1 + movel sp@(12),d0 + + movew a0,d1 | Make sure that A0 is long word aligned. + andiw #3,d1 + beq already_aligned + + notw d1 | This may de-align A1, but that's life. + andiw #3,d1 + +align_loop: + + moveb a0@+,a1@+ | Move from one to four bytes to long + subql #1,d0 | word align A0. + dbeq d1,align_loop + beq done + +already_aligned: + + movew d0,d1 + andiw #511,d1 + movew d1,sp@- + moveq #9,d1 + lsrl d1,d0 + beq no_big_chunks_to_move + + moveml d2-d7/a2-a6,sp@- + swap d0 + movew d0,sp@- + swap d0 + bra move_big_chunk_end + +move_big_chunk: + + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@ + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(48) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(96) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(144) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(192) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(240) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(288) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(336) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(384) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(432) + moveml a0@+,d1-d7/a2 + moveml d1-d7/a2,a1@(480) + addaw #512,a1 + +move_big_chunk_end: + + dbf d0,move_big_chunk + subqw #1,sp@ + bge move_big_chunk + + addqw #2,sp + + moveml sp@+,d2-d7/a2-a6 + +no_big_chunks_to_move: + + movew sp@+,d0 + + movew d0,d1 + lsrw #5,d1 | D1 now holds numbytes / 32 and + andiw #31,d0 | D0 holds numbytes % 32. + + bra move_eight_longs_end + +move_eight_longs: + + movel a0@+,a1@+ + movel a0@+,a1@+ + movel a0@+,a1@+ + movel a0@+,a1@+ + movel a0@+,a1@+ + movel a0@+,a1@+ + movel a0@+,a1@+ + movel a0@+,a1@+ + +move_eight_longs_end: + + dbf d1,move_eight_longs + + movew d0,d1 + lsrw #2,d1 | D1 now holds numbytes / 4 and + + bra move_long_end + +move_long: + + movel a0@+,a1@+ + +move_long_end: + + dbf d1,move_long + + andiw #3,d0 | D0 holds numbytes % 4. + bra move_byte_end + +move_byte: + + moveb a0@+,a1@+ + +move_byte_end: + + dbf d0,move_byte + +done: + + rts + +"); + +/****************************************************************************/ + +extern void __bcopy(const void *src,void *dst,size_t len); + +/****************************************************************************/ + +void * +memcpy(void *dst, const void *src, size_t len) +{ + void * result = dst; + + assert( (len == 0) || (dst != NULL && src != NULL && (int)len > 0) ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(dst == NULL || src == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(len > 0 && dst != src) + { + /* The two memory regions may not overlap. */ + assert((dst) >= (src)+len || + (src) >= (dst)+len); + + __bcopy(src,dst,len); + } + + out: + + return(result); +} + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +#define IS_UNALIGNED(a) ((((unsigned long)(a)) & 1) != 0) +#define IS_SHORT_ALIGNED(a) ((((unsigned long)(a)) & 3) == 2) +#define IS_LONG_ALIGNED(a) ((((unsigned long)(a)) & 1) == 0) + +/****************************************************************************/ + +INLINE static void +__memcpy(unsigned char * to,unsigned char * from,size_t len) +{ + /* The setup below is intended to speed up copying larger + * memory blocks. This can be very elaborate and should not be + * done unless a payoff can be expected. + */ + if(len > 4 * sizeof(long)) + { + /* Try to align both source and destination to an even address. */ + if(IS_UNALIGNED(to) && IS_UNALIGNED(from)) + { + (*to++) = (*from++); + len--; + } + + /* Try to align both source and destination to addresses which are + * multiples of four. + */ + if(len >= sizeof(short) && IS_SHORT_ALIGNED(to) && IS_SHORT_ALIGNED(from)) + { + (*to++) = (*from++); + (*to++) = (*from++); + + len -= sizeof(short); + } + + /* If both source and destination are aligned to addresses which are + * multiples of four and there is still enough data left to be copied, + * try to move it in larger chunks. + */ + if(len >= sizeof(long) && IS_LONG_ALIGNED(to) && IS_LONG_ALIGNED(from)) + { + unsigned long * _to = (unsigned long *)to; + unsigned long * _from = (unsigned long *)from; + + /* An unrolled transfer loop, which shifts 32 bytes per iteration. */ + while(len >= 8 * sizeof(long)) + { + /* The following should translate into load/store + opcodes which encode the access offsets (0..7) + into the respective displacement values. This + should help the PowerPC by avoiding pipeline + stalls (removing the postincrement on the address + will do that) but has no noticeable impact on the + 68k platform (I checked). */ + + _to[0] = _from[0]; + _to[1] = _from[1]; + _to[2] = _from[2]; + _to[3] = _from[3]; + _to[4] = _from[4]; + _to[5] = _from[5]; + _to[6] = _from[6]; + _to[7] = _from[7]; + + _to += 8; + _from += 8; + + /* + (*_to++) = (*_from++); + (*_to++) = (*_from++); + (*_to++) = (*_from++); + (*_to++) = (*_from++); + (*_to++) = (*_from++); + (*_to++) = (*_from++); + (*_to++) = (*_from++); + (*_to++) = (*_from++); + */ + + len -= 8 * sizeof(long); + } + + /* Try to mop up any small amounts of data still in need of + * copying... + */ + while(len >= sizeof(long)) + { + (*_to++) = (*_from++); + + len -= sizeof(long); + } + + to = (char *)_to; + from = (char *)_from; + } + } + + /* If there's anything left, copy the rest. */ + while(len-- > 0) + (*to++) = (*from++); +} + +/****************************************************************************/ + +void * +memcpy(void *dst, const void *src, size_t len) +{ + void * result = dst; + + assert( (len == 0) || (dst != NULL && src != NULL && (int)len > 0) ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(dst == NULL || src == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(len > 0 && dst != src) + { + char * to = dst; + const char * from = src; + + /* The two memory regions may not overlap. */ + assert((to) >= (from)+len || + (from) >= (to )+len); + + #if 0 + { + while(len-- > 0) + (*to++) = (*from++); + } + #else + { + __memcpy((unsigned char *)to,(unsigned char *)from,len); + } + #endif + } + + out: + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ && __mc68020__ */ diff --git a/library/string_memmove.c b/library/string_memmove.c new file mode 100644 index 0000000..a44051e --- /dev/null +++ b/library/string_memmove.c @@ -0,0 +1,623 @@ +/* + * $Id: string_memmove.c,v 1.1.1.1 2004-07-26 16:32:16 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +#if (defined(__GNUC__) && defined(__mc68020__) && defined(NDEBUG) && defined(undefined)) + +/****************************************************************************/ + +asm(" + .text + .even + + .globl ___ovbcopy + +___ovbcopy: + + moveml sp@(4),a0-a1 + movel sp@(12),d0 + + movel a2,sp@- + cmpal a0,a1 + bcs forwards + +| If A0 is less than A1 then we _may_ have to do the memory move +| backwards. However, since doing the memory move backwards is less +| efficient if we have to do any byte moves, I'll first check to see +| whether there is actually any overlap. + + lea a0@(0,d0:l),a2 + cmpal a2,a1 | If A2 is greater than A1 then there is overlap, + bcs backwards | and we'd better do the move backwards. + +forwards: + + movew a0,d1 | Make sure that A0 is long word aligned. + notw d1 | This may de-align A1, but that's life. + andiw #3,d1 + +align_loop1: + + moveb a0@+,a1@+ | Move from one to four bytes to long + subql #1,d0 | word align A0. + dbeq d1,align_loop1 + beq done + + movew d0,d1 + andiw #511,d1 + movew d1,sp@- + moveq #9,d1 + lsrl d1,d0 + beq no_big_chunks_to_move1 + + moveml d2-d7/a3-a6,sp@- + swap d0 + movew d0,sp@- + swap d0 + + bras move_big_chunk_end1 + +move_big_chunk1: + + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@ + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(48) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(96) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(144) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(192) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(240) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(288) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(336) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(384) + moveml a0@+,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@(432) + moveml a0@+,d1-d7/a2 + moveml d1-d7/a2,a1@(480) + addaw #512,a1 + +move_big_chunk_end1: + + dbf d0,move_big_chunk1 + + subqw #1,sp@ + bge move_big_chunk1 + + addqw #2,sp + + moveml sp@+,d2-d7/a3-a6 + +no_big_chunks_to_move1: + + movew sp@+,d0 + + movew d0,d1 + lsrw #5,d1 | D1 now holds numbytes / 32 and + andiw #31,d0 | D0 holds numbytes % 32. + + bras move_eight_longs_end1 + +move_eight_longs1: + + movel a0@+,a1@+ + movel a0@+,a1@+ + movel a0@+,a1@+ + movel a0@+,a1@+ + movel a0@+,a1@+ + movel a0@+,a1@+ + movel a0@+,a1@+ + movel a0@+,a1@+ + +move_eight_longs_end1: + + dbf d1,move_eight_longs1 + + movew d0,d1 + lsrw #2,d1 | D1 now holds numbytes / 4 + + bras move_long_end1 + +move_long1: + + movel a0@+,a1@+ + +move_long_end1: + + dbf d1,move_long1 + + andiw #3,d0 | D0 now holds numbytes % 4. + + bra move_byte_end1 + +move_byte1: + + moveb a0@+,a1@+ + +move_byte_end1: + + dbf d0,move_byte1 + +done: + + movel sp@+,a2 + rts + +backwards: + + addal d0,a0 + addal d0,a1 + + movew a0,d1 | Make sure that A0 is long word aligned. + subqw #1,d1 | This may de-align A1, but that's life. + andiw #3,d1 + +align_loop2: + + moveb a0@-,a1@- + subql #1,d0 + dbeq d1,align_loop2 + beq done + + movew d0,d1 + andiw #511,d1 + movew d1,sp@- + moveq #9,d1 + lsrl d1,d0 + beq no_big_chunks_to_move2 + + moveml d2-d7/a3-a6,sp@- + swap d0 + movew d0,sp@- + swap d0 + + subaw #48,a0 + bras move_big_chunk_end2 + +move_big_chunk2: + + moveml a0@,d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@- + moveml a0@(-48),d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@- + moveml a0@(-96),d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@- + moveml a0@(-144),d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@- + moveml a0@(-192),d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@- + moveml a0@(-240),d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@- + moveml a0@(-288),d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@- + moveml a0@(-336),d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@- + moveml a0@(-384),d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@- + moveml a0@(-432),d1-d7/a2-a6 + moveml d1-d7/a2-a6,a1@- + moveml a0@(-464),d1-d7/a2 + moveml d1-d7/a2,a1@- + subaw #512,a0 + +move_big_chunk_end2: + + dbf d0,move_big_chunk2 + + subqw #1,sp@ + bge move_big_chunk2 + + addaw #48,a0 + + addqw #2,sp + + moveml sp@+,d2-d7/a3-a6 + +no_big_chunks_to_move2: + + movew sp@+,d0 + + movew d0,d1 + lsrw #5,d1 | D1 now holds numbytes / 32 and + andiw #31,d0 | D0 holds numbytes % 32. + + bras move_eight_longs_end2 + +move_eight_longs2: + + movel a0@-,a1@- + movel a0@-,a1@- + movel a0@-,a1@- + movel a0@-,a1@- + movel a0@-,a1@- + movel a0@-,a1@- + movel a0@-,a1@- + movel a0@-,a1@- + +move_eight_longs_end2: + + dbf d1,move_eight_longs2 + + movew d0,d1 + lsrw #2,d1 | D1 now holds numbytes / 4 + + bra move_long_end2 + +move_long2: + + movel a0@-,a1@- + +move_long_end2: + + dbf d1,move_long2 + + andiw #3,d0 | D0 now holds numbytes % 4. + bra move_byte_end2 + +move_byte2: + + moveb a0@-,a1@- + +move_byte_end2: + + dbf d0,move_byte2 + + movel sp@+,a2 + rts + +"); + +/****************************************************************************/ + +extern void __ovbcopy(const void * src,void * dest,size_t len); + +/****************************************************************************/ + +void * +memmove(void *dest, const void * src, size_t len) +{ + void * result = dest; + + assert( (len == 0) || (dest != NULL && src != NULL && (int)len > 0) ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(dest == NULL || src == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(len > 0 && dest != src) + __ovbcopy(src,dest,len); + + out: + + return(result); +} + +/****************************************************************************/ + +#else + +/****************************************************************************/ + +#define IS_UNALIGNED(a) ((((unsigned long)(a)) & 1) != 0) +#define IS_SHORT_ALIGNED(a) ((((unsigned long)(a)) & 3) == 2) +#define IS_LONG_ALIGNED(a) ((((unsigned long)(a)) & 1) == 0) + +/****************************************************************************/ + +INLINE static void +__memmove(unsigned char * to,unsigned char * from,size_t len) +{ + if(from < to && to < from + len) + { + to += len; + from += len; + + /* The setup below is intended to speed up copying larger + * memory blocks. This can be very elaborate and should not be + * done unless a payoff can be expected. + */ + if(len > 4 * sizeof(long)) + { + size_t distance; + + /* Try to align both source and destination to an even address. */ + if(IS_UNALIGNED(to) && IS_UNALIGNED(from)) + { + (*--to) = (*--from); + len--; + } + + /* Try to align both source and destination to addresses which are + * multiples of four. + */ + if(len >= sizeof(short) && IS_SHORT_ALIGNED(to) && IS_SHORT_ALIGNED(from)) + { + (*--to) = (*--from); + (*--to) = (*--from); + + len -= sizeof(short); + } + + /* Check the distance between source and destination. If it's shorter + * than a long word, don't dive into the copying routine below since + * the overlapping copying may clobber data. + */ + distance = (size_t)(to - from); + + /* If both source and destination are aligned to addresses which are + * multiples of four and there is still enough data left to be copied, + * try to move it in larger chunks. + */ + if(distance >= sizeof(long) && len >= sizeof(long) && IS_LONG_ALIGNED(to) && IS_LONG_ALIGNED(from)) + { + unsigned long * _to = (unsigned long *)to; + unsigned long * _from = (unsigned long *)from; + + /* An unrolled transfer loop, which shifts 32 bytes per iteration. */ + while(len >= 8 * sizeof(long)) + { + /* The following should translate into load/store + opcodes which encode the access offsets (-1..-8) + into the respective displacement values. This + should help the PowerPC by avoiding pipeline + stalls (removing the predecrement on the address + will do that) but has no noticeable impact on the + 68k platform (I checked). */ + + _to[-1] = _from[-1]; + _to[-2] = _from[-2]; + _to[-3] = _from[-3]; + _to[-4] = _from[-4]; + _to[-5] = _from[-5]; + _to[-6] = _from[-6]; + _to[-7] = _from[-7]; + _to[-8] = _from[-8]; + + _to -= 8; + _from -= 8; + + /* + (*--_to) = (*--_from); + (*--_to) = (*--_from); + (*--_to) = (*--_from); + (*--_to) = (*--_from); + (*--_to) = (*--_from); + (*--_to) = (*--_from); + (*--_to) = (*--_from); + (*--_to) = (*--_from); + */ + + len -= 8 * sizeof(long); + } + + /* Try to mop up any small amounts of data still in need of + * copying... + */ + while(len >= sizeof(long)) + { + (*--_to) = (*--_from); + + len -= sizeof(long); + } + + to = (char *)_to; + from = (char *)_from; + } + } + + /* If there's anything left, copy the rest. */ + while(len-- > 0) + (*--to) = (*--from); + } + else + { + /* The setup below is intended to speed up copying larger + * memory blocks. This can be very elaborate and should not be + * done unless a payoff can be expected. + */ + if(len > 4 * sizeof(long)) + { + size_t distance; + + /* Try to align both source and destination to an even address. */ + if(IS_UNALIGNED(to) && IS_UNALIGNED(from)) + { + (*to++) = (*from++); + len--; + } + + /* Try to align both source and destination to addresses which are + * multiples of four. + */ + if(len >= sizeof(short) && IS_SHORT_ALIGNED(to) && IS_SHORT_ALIGNED(from)) + { + (*to++) = (*from++); + (*to++) = (*from++); + + len -= sizeof(short); + } + + /* Check the distance between source and destination. If it's shorter + * than a long word, don't dive into the copying routine below since + * the overlapping copying may clobber data. + */ + if(to >= from) + distance = (size_t)(to - from); + else + distance = (size_t)(from - to); + + /* If both source and destination are aligned to addresses which are + * multiples of four and there is still enough data left to be copied, + * try to move it in larger chunks. + */ + if(distance >= sizeof(long) && len >= sizeof(long) && IS_LONG_ALIGNED(to) && IS_LONG_ALIGNED(from)) + { + unsigned long * _to = (unsigned long *)to; + unsigned long * _from = (unsigned long *)from; + + /* An unrolled transfer loop, which shifts 32 bytes per iteration. */ + while(len >= 8 * sizeof(long)) + { + /* The following should translate into load/store + opcodes which encode the access offsets (0..7) + into the respective displacement values. This + should help the PowerPC by avoiding pipeline + stalls (removing the postincrement on the address + will do that) but has no noticeable impact on the + 68k platform (I checked). */ + + _to[0] = _from[0]; + _to[1] = _from[1]; + _to[2] = _from[2]; + _to[3] = _from[3]; + _to[4] = _from[4]; + _to[5] = _from[5]; + _to[6] = _from[6]; + _to[7] = _from[7]; + + _to += 8; + _from += 8; + + /* + (*_to++) = (*_from++); + (*_to++) = (*_from++); + (*_to++) = (*_from++); + (*_to++) = (*_from++); + (*_to++) = (*_from++); + (*_to++) = (*_from++); + (*_to++) = (*_from++); + (*_to++) = (*_from++); + */ + + len -= 8 * sizeof(long); + } + + /* Try to mop up any small amounts of data still in need of + * copying... + */ + while(len >= sizeof(long)) + { + (*_to++) = (*_from++); + + len -= sizeof(long); + } + + to = (char *)_to; + from = (char *)_from; + } + } + + /* If there's anything left, copy the rest. */ + while(len-- > 0) + (*to++) = (*from++); + } +} + +/****************************************************************************/ + +void * +memmove(void *dest, const void * src, size_t len) +{ + void * result = dest; + + assert( (len == 0) || (dest != NULL && src != NULL && (int)len > 0) ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(dest == NULL || src == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(len > 0 && dest != src) + { + char * to = dest; + const char * from = src; + + #if 0 + { + if(from < to && to < from + len) + { + to += len; + from += len; + + while(len-- > 0) + (*--to) = (*--from); + } + else + { + while(len-- > 0) + (*to++) = (*from++); + } + } + #else + { + __memmove((unsigned char *)to,(unsigned char *)from,len); + } + #endif + } + + out: + + return(result); +} + +/****************************************************************************/ + +#endif /* __GNUC__ && __mc68020__ */ diff --git a/library/string_memset.c b/library/string_memset.c new file mode 100644 index 0000000..d31b5e0 --- /dev/null +++ b/library/string_memset.c @@ -0,0 +1,167 @@ +/* + * $Id: string_memset.c,v 1.1.1.1 2004-07-26 16:32:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +#define IS_UNALIGNED(a) ((((unsigned long)(a)) & 1) != 0) +#define IS_SHORT_ALIGNED(a) ((((unsigned long)(a)) & 3) == 2) +#define IS_LONG_ALIGNED(a) ((((unsigned long)(a)) & 1) == 0) + +/****************************************************************************/ + +INLINE static void +__memset(unsigned char * to,unsigned char value,size_t len) +{ + /* The setup below is intended to speed up changing larger + * memory blocks. This can be very elaborate and should not be + * done unless a payoff can be expected. + */ + if(len > 4 * sizeof(long)) + { + if(IS_UNALIGNED(to)) + { + (*to++) = value; + len--; + } + + if(len >= sizeof(short) && IS_SHORT_ALIGNED(to)) + { + (*to++) = value; + (*to++) = value; + + len -= sizeof(short); + } + + if(len >= sizeof(long) && IS_LONG_ALIGNED(to)) + { + unsigned long * _to = (unsigned long *)to; + unsigned long _value = value; + + _value |= (_value << 8); + _value |= (_value << 16); + + while(len >= 8 * sizeof(long)) + { + /* The following should translate into load/store + opcodes which encode the access offsets (0..7) + into the respective displacement values. This + should help the PowerPC by avoiding pipeline + stalls (removing the postincrement on the address + will do that) but has no noticeable impact on the + 68k platform (I checked). */ + + _to[0] = _value; + _to[1] = _value; + _to[2] = _value; + _to[3] = _value; + _to[4] = _value; + _to[5] = _value; + _to[6] = _value; + _to[7] = _value; + + _to += 8; + + /* + (*_to++) = _value; + (*_to++) = _value; + (*_to++) = _value; + (*_to++) = _value; + (*_to++) = _value; + (*_to++) = _value; + (*_to++) = _value; + (*_to++) = _value; + */ + + len -= 8 * sizeof(long); + } + + while(len >= sizeof(long)) + { + (*_to++) = _value; + + len -= sizeof(long); + } + + to = (char *)_to; + } + } + + while(len-- > 0) + (*to++) = value; +} + +/****************************************************************************/ + +void * +memset(void *ptr, int val, size_t len) +{ + void * result = ptr; + unsigned char * m = ptr; + + assert( (len == 0) || (ptr != NULL && (int)len > 0) ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(ptr == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + #if 0 + { + while(len-- > 0) + (*m++) = val; + } + #else + { + __memset(m,(unsigned char)(val & 255),len); + } + #endif + + out: + + return(result); +} diff --git a/library/string_rindex.c b/library/string_rindex.c new file mode 100644 index 0000000..8239cab --- /dev/null +++ b/library/string_rindex.c @@ -0,0 +1,52 @@ +/* + * $Id: string_rindex.c,v 1.1.1.1 2004-07-26 16:32:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +char * +rindex(const char *s, int c) +{ + char * result; + + result = strrchr(s,c); + + return(result); +} diff --git a/library/string_strcat.c b/library/string_strcat.c new file mode 100644 index 0000000..4d1a1f9 --- /dev/null +++ b/library/string_strcat.c @@ -0,0 +1,72 @@ +/* + * $Id: string_strcat.c,v 1.1.1.1 2004-07-26 16:32:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +char * +strcat(char *dest, const char *src) +{ + char * result = dest; + + assert( dest != NULL && src != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(dest == NULL || src == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + while((*dest) != '\0') + dest++; + + while(((*dest++) = (*src++)) != '\0') + DO_NOTHING; + + out: + + return(result); +} diff --git a/library/string_strchr.c b/library/string_strchr.c new file mode 100644 index 0000000..9a8ee12 --- /dev/null +++ b/library/string_strchr.c @@ -0,0 +1,84 @@ +/* + * $Id: string_strchr.c,v 1.1.1.1 2004-07-26 16:32:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +char * +strchr(const char *s, int c) +{ + const unsigned char * us = (const unsigned char *)s; + char * result = NULL; + unsigned char us_c; + unsigned char find_this = (c & 0xff); + + assert( s != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(us == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + while(TRUE) + { + us_c = (*us); + if(us_c == find_this) + { + result = (char *)us; + break; + } + + if(us_c == '\0') + break; + + us++; + } + + out: + + return(result); +} diff --git a/library/string_strcmp.c b/library/string_strcmp.c new file mode 100644 index 0000000..ceea297 --- /dev/null +++ b/library/string_strcmp.c @@ -0,0 +1,80 @@ +/* + * $Id: string_strcmp.c,v 1.1.1.1 2004-07-26 16:32:17 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +int +strcmp(const char *s1, const char * s2) +{ + int result = 0; + + assert( s1 != NULL && s2 != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s1 == NULL || s2 == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(s1 != s2) + { + while((*s1) == (*s2)) + { + if((*s1) == '\0') + break; + + s1++; + s2++; + } + + result = (*s1) - (*s2); + } + + out: + + return(result); +} diff --git a/library/string_strcoll.c b/library/string_strcoll.c new file mode 100644 index 0000000..b1189ab --- /dev/null +++ b/library/string_strcoll.c @@ -0,0 +1,82 @@ +/* + * $Id: string_strcoll.c,v 1.1.1.1 2004-07-26 16:32:18 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +int +strcoll(const char *s1, const char *s2) +{ + DECLARE_LOCALEBASE(); + int result = 0; + + assert( s1 != NULL && s2 != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s1 == NULL || s2 == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__locale_table[LC_COLLATE] != NULL) + { + assert( LocaleBase != NULL ); + + result = StrnCmp(__locale_table[LC_COLLATE],(STRPTR)s1,(STRPTR)s2,-1,SC_COLLATE1); + } + else + { + result = strcmp(s1,s2); + } + + out: + + return(result); +} diff --git a/library/string_strcpy.c b/library/string_strcpy.c new file mode 100644 index 0000000..29f32e9 --- /dev/null +++ b/library/string_strcpy.c @@ -0,0 +1,72 @@ +/* + * $Id: string_strcpy.c,v 1.1.1.1 2004-07-26 16:32:18 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +char * +strcpy(char *dest, const char *src) +{ + char * result = dest; + + assert( dest != NULL && src != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(dest == NULL || src == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(dest != src) + { + while(((*dest++) = (*src++)) != '\0') + DO_NOTHING; + } + + out: + + return(result); +} diff --git a/library/string_strcspn.c b/library/string_strcspn.c new file mode 100644 index 0000000..ec2b83d --- /dev/null +++ b/library/string_strcspn.c @@ -0,0 +1,79 @@ +/* + * $Id: string_strcspn.c,v 1.1.1.1 2004-07-26 16:32:18 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +size_t +strcspn(const char *s, const char *set) +{ + const char * start = s; + size_t result = 0; + char c; + + assert(s != NULL && set != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s == NULL || set == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + while((c = (*s)) != '\0') + { + /* Is this character found in the set? */ + if(strchr(set,c) != NULL) + break; /* Stop if it's in there. */ + + s++; + } + + result = (size_t)(s - start); + + out: + + return(result); +} diff --git a/library/string_strdup.c b/library/string_strdup.c new file mode 100644 index 0000000..21b4734 --- /dev/null +++ b/library/string_strdup.c @@ -0,0 +1,99 @@ +/* + * $Id: string_strdup.c,v 1.1.1.1 2004-07-26 16:32:18 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +#include "stdlib_protos.h" + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#undef strdup + +/****************************************************************************/ + +char * +__strdup(const char *s,const char * file,int line) +{ + char * result = NULL; + size_t total_size; + + assert( s != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + total_size = strlen(s)+1; + + result = __malloc(total_size,file,line); + if(result == NULL) + goto out; + + memmove(result,s,total_size); + + out: + + return(result); +} + +/****************************************************************************/ + +char * +strdup(const char *s) +{ + char * result; + + result = __strdup(s,NULL,0); + + return(result); +} diff --git a/library/string_strerror.c b/library/string_strerror.c new file mode 100644 index 0000000..f26983c --- /dev/null +++ b/library/string_strerror.c @@ -0,0 +1,198 @@ +/* + * $Id: string_strerror.c,v 1.1.1.1 2004-07-26 16:32:18 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +static char * error_table[EILSEQ - EPERM + 1] = +{ + "Operation not permitted", + "No such file or directory", + "No such process", + "Interrupted system call", + "Input/output error", + "Device not configured", + "Argument list too long", + "Exec format error", + "Bad file descriptor", + "No child processes", + "Resource deadlock avoided", + "Cannot allocate memory", + "Permission denied", + "Bad address", + "Block device required", + "Device busy", + "File exists", + "Cross-device link", + "Operation not supported by device", + "Not a directory", + "Is a directory", + "Invalid argument", + "Too many open files in system", + "Too many open files", + "Inappropriate ioctl for device", + "Text file busy", + "File too large", + "No space left on device", + "Illegal seek", + "Read-only file system", + "Too many links", + "Broken pipe", + "Numerical argument out of domain", + "Result too large", + "Resource temporarily unavailable", + "Operation now in progress", + "Operation already in progress", + "Socket operation on non-socket", + "Destination address required", + "Message too long", + "Protocol wrong type for socket", + "Protocol not available", + "Protocol not supported", + "Socket type not supported", + "Operation not supported on socket", + "Protocol family not supported", + "Address family not supported by protocol family", + "Address already in use", + "Can't assign requested address", + "Network is down", + "Network is unreachable", + "Network dropped connection on reset", + "Software caused connection abort", + "Connection reset by peer", + "No buffer space available", + "Socket is already connected", + "Socket is not connected", + "Can't send after socket shutdown", + "Too many references: can't splice", + "Connection timed out", + "Connection refused", + "Too many levels of symbolic links", + "File name too long", + "Host is down", + "No route to host", + "Directory not empty", + "Too many processes", + "Too many users", + "Disc quota exceeded", + "Stale NFS file handle", + "Too many levels of remote in path", + "RPC struct is bad", + "RPC version wrong", + "RPC program not available", + "Program version wrong", + "Bad procedure for program", + "No locks available", + "Function not implemented", + "Inappropriate file type or format", + "Authentication error", + "Need authenticator", + "Identifier removed", + "No message of the desired type.", + "Value too large to be stored in data type.", + "Encoding error detected" +}; + +/****************************************************************************/ + +char * +strerror(int error_number) +{ + char * result; + + if(error_number < EPERM || error_number > EILSEQ) + { + static char error_buffer[80]; + char number[30]; + char *s = number; + int is_negative = 0; + unsigned int n; + int i,len,c; + + /* We convert the error number into in an unsigned + integer, so that numbers such as 0x80000000 + can come out of the conversion. */ + if(error_number < 0) + { + is_negative = 1; + + n = (-error_number); + } + else + { + n = error_number; + } + + /* Convert the error number into a string of digits. */ + len = 0; + + do + { + (*s++) = '0' + (n % 10); + n /= 10; + len++; + } + while(n > 0 && len < (int)sizeof(number)-1); + + /* Add the sign, if necessary. */ + if(is_negative && len < (int)sizeof(number)-1) + { + (*s++) = '-'; + len++; + } + + (*s) = '\0'; + + /* Reverse the string in place. */ + for(i = 0 ; i < len / 2 ; i++) + { + c = number[len-1-i]; + number[len-1-i] = number[i]; + number[i] = c; + } + + strcpy(error_buffer,"Unknown error "); + strcat(error_buffer,number); + + result = error_buffer; + } + else + { + result = error_table[error_number - EPERM]; + } + + return(result); +} diff --git a/library/string_strlen.c b/library/string_strlen.c new file mode 100644 index 0000000..f3fe1c0 --- /dev/null +++ b/library/string_strlen.c @@ -0,0 +1,72 @@ +/* + * $Id: string_strlen.c,v 1.1.1.1 2004-07-26 16:32:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +size_t +strlen(const char *s) +{ + const char * start = s; + size_t result = 0; + + assert( s != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + while((*s) != '\0') + s++; + + result = (size_t)(s - start); + + out: + + return(result); +} diff --git a/library/string_strncat.c b/library/string_strncat.c new file mode 100644 index 0000000..49c7004 --- /dev/null +++ b/library/string_strncat.c @@ -0,0 +1,91 @@ +/* + * $Id: string_strncat.c,v 1.1.1.1 2004-07-26 16:32:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +char * +strncat(char *dest, const char *src, size_t n) +{ + char * result = dest; + + assert( dest != NULL && src != NULL ); + assert( (int)n >= 0 ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(dest == NULL || src == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + /* If the number of characters is 0 or negative, then this + * function is supposed to have no effect. + */ + if((int)n > 0) + { + while((*dest) != '\0') + dest++; + + while(n-- > 0) + { + if(((*dest++) = (*src++)) == '\0') + { + /* Back up one character so that the + terminating NUL is written in the + correct location. */ + dest--; + break; + } + } + + /* Always NUL-terminate the destination string. */ + (*dest) = '\0'; + } + + out: + + return(result); +} diff --git a/library/string_strncmp.c b/library/string_strncmp.c new file mode 100644 index 0000000..a47c272 --- /dev/null +++ b/library/string_strncmp.c @@ -0,0 +1,90 @@ +/* + * $Id: string_strncmp.c,v 1.1.1.1 2004-07-26 16:32:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +int +strncmp(const char *s1, const char *s2, size_t n) +{ + int result = 0; + + assert( s1 != NULL && s2 != NULL ); + assert( (int)n >= 0 ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s1 == NULL || s2 == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + /* If the number of characters is 0 or negative, then this + * function is supposed to have no effect. + */ + if(s1 != s2 && (int)n > 0) + { + while(n-- > 0) + { + if((*s1) == (*s2)) + { + if((*s1) == '\0') + break; + + s1++; + s2++; + } + else + { + result = (*s1) - (*s2); + break; + } + } + } + + out: + + return(result); +} diff --git a/library/string_strncpy.c b/library/string_strncpy.c new file mode 100644 index 0000000..2dfd934 --- /dev/null +++ b/library/string_strncpy.c @@ -0,0 +1,85 @@ +/* + * $Id: string_strncpy.c,v 1.1.1.1 2004-07-26 16:32:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +char * +strncpy(char *dest, const char *src, size_t n) +{ + char * result = dest; + + assert( dest != NULL && src != NULL ); + assert( (int)n >= 0 ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(dest == NULL || src == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + /* If the number of characters is 0 or negative, then this + * function is supposed to have no effect. + */ + if((int)n > 0) + { + while(n-- > 0) + { + if(((*dest++) = (*src++)) == '\0') + { + /* Fill the rest with NUL bytes... */ + while(n-- > 0) + (*dest++) = '\0'; + + break; + } + } + } + + out: + + return(result); +} diff --git a/library/string_strpbrk.c b/library/string_strpbrk.c new file mode 100644 index 0000000..e0bca97 --- /dev/null +++ b/library/string_strpbrk.c @@ -0,0 +1,80 @@ +/* + * $Id: string_strpbrk.c,v 1.1.1.1 2004-07-26 16:32:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +char * +strpbrk(const char *s, const char *set) +{ + char *result = NULL; + char c; + + assert(s != NULL && set != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s == NULL || set == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + while((c = (*s)) != '\0') + { + /* Is this character found in the set? */ + if(strchr(set,c) != NULL) + { + /* If it's in there, remember where we found it. */ + result = (char *)s; + break; + } + + s++; + } + + out: + + return(result); +} diff --git a/library/string_strrchr.c b/library/string_strrchr.c new file mode 100644 index 0000000..48f88d4 --- /dev/null +++ b/library/string_strrchr.c @@ -0,0 +1,89 @@ +/* + * $Id: string_strrchr.c,v 1.1.1.1 2004-07-26 16:32:19 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +char * +strrchr(const char *s, int c) +{ + const unsigned char * us = (const unsigned char *)s; + char * result = NULL; + unsigned char us_c; + unsigned char find_this = (c & 0xff); + + assert( s != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(us == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + /* This is technically the opposite of strchr(), but the + * implementation is very similar. However, instead of + * stopping on the first location that holds the desired + * value we just remember where we found it. When the + * end of the string finally arrives we will thus be + * able to return a pointer to the last occurence of + * the character. + */ + while(TRUE) + { + us_c = (*us); + if(us_c == find_this) + result = (char *)us; + + if(us_c == '\0') + break; + + us++; + } + + out: + + return(result); +} diff --git a/library/string_strspn.c b/library/string_strspn.c new file mode 100644 index 0000000..404c3f1 --- /dev/null +++ b/library/string_strspn.c @@ -0,0 +1,79 @@ +/* + * $Id: string_strspn.c,v 1.1.1.1 2004-07-26 16:32:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +size_t +strspn(const char *s, const char *set) +{ + const char * start = s; + size_t result = 0; + char c; + + assert(s != NULL && set != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s == NULL || set == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + while((c = (*s)) != '\0') + { + /* Is this character found in the set? */ + if(strchr(set,c) == NULL) + break; /* Stop if it's not in there. */ + + s++; + } + + result = (size_t)(s - start); + + out: + + return(result); +} diff --git a/library/string_strstr.c b/library/string_strstr.c new file mode 100644 index 0000000..9339910 --- /dev/null +++ b/library/string_strstr.c @@ -0,0 +1,102 @@ +/* + * $Id: string_strstr.c,v 1.1.1.1 2004-07-26 16:32:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +char * +strstr(const char *src, const char *sub) +{ + char * result = NULL; + + assert( src != NULL && sub != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(src == NULL || sub == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + /* If 'sub' points to a string with zero length, then + * we must return 'src'. + */ + if((*sub) == '\0') + { + result = (char *)src; + } + else + { + size_t i; + char c; + + /* Try to find 'sub' in 'src'. Watch how we avoid calling + * strlen() even once... + */ + while((*src) != '\0') + { + for(i = 0 ; ; i++) + { + c = sub[i]; + + /* End of substring? We got a match... */ + if(c == '\0') + { + result = (char *)src; + goto out; + } + + if(c != src[i]) + break; + } + + src++; + } + } + + out: + + return(result); +} diff --git a/library/string_strtok.c b/library/string_strtok.c new file mode 100644 index 0000000..142434d --- /dev/null +++ b/library/string_strtok.c @@ -0,0 +1,105 @@ +/* + * $Id: string_strtok.c,v 1.1.1.1 2004-07-26 16:32:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +/****************************************************************************/ + +char * +strtok(char *str, const char *separator_set) +{ + static char * last; + + char * result = NULL; + size_t size; + + assert( separator_set != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(separator_set == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + /* Did we get called before? Restart at the last valid position. */ + if(str == NULL) + { + str = last; + + /* However, we may have hit the end of the + string already. */ + if(str == NULL) + goto out; + } + + last = NULL; + + /* Skip the characters which count as + separators. */ + str += strspn(str, separator_set); + if((*str) == '\0') + goto out; + + /* Count the number of characters which aren't + separators. */ + size = strcspn(str, separator_set); + if(size == 0) + goto out; + + /* This is where the search can resume later. */ + last = &str[size+1]; + if((*last) == '\0') + last = NULL; + + /* This is the token we found; make sure that + it looks like a valid string. */ + str[size] = '\0'; + + result = str; + + out: + + return(result); +} diff --git a/library/string_strxfrm.c b/library/string_strxfrm.c new file mode 100644 index 0000000..9767422 --- /dev/null +++ b/library/string_strxfrm.c @@ -0,0 +1,114 @@ +/* + * $Id: string_strxfrm.c,v 1.1.1.1 2004-07-26 16:32:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRING_HEADERS_H +#include "string_headers.h" +#endif /* _STRING_HEADERS_H */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +size_t +strxfrm(char *dest, const char *src, size_t len) +{ + DECLARE_LOCALEBASE(); + size_t result = 0; + + ENTER(); + + SHOWPOINTER(dest); + SHOWSTRING(src); + SHOWVALUE(len); + + assert( src != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(src == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__locale_table[LC_COLLATE] != NULL) + { + assert( LocaleBase != NULL ); + + result = StrConvert(__locale_table[LC_COLLATE],(STRPTR)src,dest,len,SC_COLLATE1); + } + else + { + if(len > 0 && dest != NULL) + { + char c; + + result = 0; + + while((c = (*src++)) != '\0') + { + result++; + + if(len > 0) + { + len--; + + (*dest++) = c; + } + } + + (*dest) = '\0'; + } + else + { + result = strlen(src); + } + } + + out: + + RETURN(result); + return(result); +} diff --git a/library/strings_headers.h b/library/strings_headers.h new file mode 100644 index 0000000..9616cb4 --- /dev/null +++ b/library/strings_headers.h @@ -0,0 +1,52 @@ +/* + * $Id: strings_headers.h,v 1.1.1.1 2004-07-26 16:32:20 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STRINGS_HEADERS_H +#define _STRINGS_HEADERS_H + +/****************************************************************************/ + +#include +#include +#include +#include +#include + +/****************************************************************************/ + +#include "macros.h" +#include "debug.h" + +/****************************************************************************/ + +#endif /* _STRINGS_HEADERS_H */ diff --git a/library/strings_strcasecmp.c b/library/strings_strcasecmp.c new file mode 100644 index 0000000..837f97f --- /dev/null +++ b/library/strings_strcasecmp.c @@ -0,0 +1,85 @@ +/* + * $Id: strings_strcasecmp.c,v 1.1.1.1 2004-07-26 16:32:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRINGS_HEADERS_H +#include "strings_headers.h" +#endif /* _STRINGS_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +strcasecmp(const char * _s1, const char * _s2) +{ + const unsigned char *s1 = (const unsigned char *)_s1; + const unsigned char *s2 = (const unsigned char *)_s2; + int result = 0; + + assert( s1 != NULL && s2 != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s1 == NULL || s2 == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(s1 != s2) + { + unsigned char c1,c2; + + while((c1 = toupper(*s1++)) == (c2 = toupper(*s2++))) + { + if(c1 == '\0') + break; + } + + result = (int)c1 - (int)c2; + } + + out: + + return(result); +} diff --git a/library/strings_strncasecmp.c b/library/strings_strncasecmp.c new file mode 100644 index 0000000..efbeb89 --- /dev/null +++ b/library/strings_strncasecmp.c @@ -0,0 +1,94 @@ +/* + * $Id: strings_strncasecmp.c,v 1.1.1.1 2004-07-26 16:32:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STRINGS_HEADERS_H +#include "strings_headers.h" +#endif /* _STRINGS_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +strncasecmp(const char * _s1, const char * _s2,size_t n) +{ + const unsigned char *s1 = (const unsigned char *)_s1; + const unsigned char *s2 = (const unsigned char *)_s2; + unsigned char c1,c2; + int result = 0; + + assert( s1 != NULL && s2 != NULL ); + assert( (int)n >= 0 ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s1 == NULL || s2 == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(s1 != s2) + { + while(n-- > 0) + { + c1 = toupper(*s1++); + c2 = toupper(*s2++); + + if(c1 == c2) + { + if(c1 == '\0') + break; + } + else + { + result = (int)c1 - (int)c2; + break; + } + } + } + + out: + + return(result); +} diff --git a/library/time_asctime.c b/library/time_asctime.c new file mode 100644 index 0000000..82fb84e --- /dev/null +++ b/library/time_asctime.c @@ -0,0 +1,192 @@ +/* + * $Id: time_asctime.c,v 1.1.1.1 2004-07-26 16:32:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _TIME_HEADERS_H +#include "time_headers.h" +#endif /* _TIME_HEADERS_H */ + +/****************************************************************************/ + +static void +add_to_string(char * to,int to_size,const char * string,int * offset_ptr) +{ + int offset; + int len; + + assert( to != NULL && to_size > 0 && string != NULL && offset_ptr != NULL ); + + offset = (*offset_ptr); + + assert( offset < to_size ); + + len = strlen(string); + if(offset + len > (to_size-1)) + len = (to_size-1) - offset; + + if(len > 0) + { + memmove(&to[offset],string,(size_t)len); + offset += len; + + assert( offset < to_size ); + + to[offset] = '\0'; + + (*offset_ptr) = offset; + } +} + +/****************************************************************************/ + +char * +asctime(const struct tm *tm) +{ + static char buffer[40]; + + struct tm copy_tm; + char number[16]; + char * result = NULL; + const char * b; + int offset = 0; + + ENTER(); + + SHOWPOINTER(tm); + + assert( tm != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(tm == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + /* Fill in the week day if it's not in proper range. */ + if(tm->tm_wday < 0 || tm->tm_wday > 6) + { + struct tm other_tm; + time_t seconds; + + other_tm = (*tm); + + seconds = mktime(&other_tm); + if(seconds != (time_t)-1) + { + __convert_time(seconds,0,&other_tm); + + copy_tm = (*tm); + copy_tm.tm_wday = other_tm.tm_wday; + + tm = ©_tm; + } + } + + if(0 <= tm->tm_wday && tm->tm_wday <= 6) + b = __abbreviated_week_day_names[tm->tm_wday]; + else + b = "---"; + + add_to_string(buffer,sizeof(buffer),b, &offset); + add_to_string(buffer,sizeof(buffer)," ", &offset); + + if(0 <= tm->tm_mon && tm->tm_mon <= 11) + b = __abbreviated_month_names[tm->tm_mon]; + else + b = "---"; + + add_to_string(buffer,sizeof(buffer),b, &offset); + add_to_string(buffer,sizeof(buffer)," ", &offset); + + if(1 <= tm->tm_mday && tm->tm_mday <= 31) + b = __number_to_string((unsigned int)tm->tm_mday,number,sizeof(number),2); + else + b = "--"; + + add_to_string(buffer,sizeof(buffer),b, &offset); + add_to_string(buffer,sizeof(buffer)," ", &offset); + + if(0 <= tm->tm_hour && tm->tm_hour <= 23) + b = __number_to_string((unsigned int)tm->tm_hour,number,sizeof(number),2); + else + b = "--"; + + add_to_string(buffer,sizeof(buffer),b, &offset); + add_to_string(buffer,sizeof(buffer),":", &offset); + + if(0 <= tm->tm_min && tm->tm_min <= 59) + b = __number_to_string((unsigned int)tm->tm_min,number,sizeof(number),2); + else + b = "--"; + + add_to_string(buffer,sizeof(buffer),b, &offset); + add_to_string(buffer,sizeof(buffer),":", &offset); + + if(0 <= tm->tm_sec && tm->tm_sec <= 59) + b = __number_to_string((unsigned int)tm->tm_sec,number,sizeof(number),2); + else + b = "--"; + + add_to_string(buffer,sizeof(buffer),b, &offset); + add_to_string(buffer,sizeof(buffer)," ", &offset); + + if(0 <= tm->tm_year) + b = __number_to_string((unsigned int)1900 + tm->tm_year,number,sizeof(number),0); + else + b = "----"; + + add_to_string(buffer,sizeof(buffer),b,&offset); + + SHOWSTRING(buffer); + + add_to_string(buffer,sizeof(buffer),"\n",&offset); + + assert( offset < sizeof(buffer) ); + assert( strlen(buffer) < sizeof(buffer) ); + + result = buffer; + + out: + + RETURN(result); + return(result); +} diff --git a/library/time_clock.c b/library/time_clock.c new file mode 100644 index 0000000..464b4e9 --- /dev/null +++ b/library/time_clock.c @@ -0,0 +1,88 @@ +/* + * $Id: time_clock.c,v 1.1.1.1 2004-07-26 16:32:21 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TIME_HEADERS_H +#include "time_headers.h" +#endif /* _TIME_HEADERS_H */ + +/****************************************************************************/ + +clock_t +clock(void) +{ + struct DateStamp now; + LONG minutes_now,ticks_now; + LONG minutes_start,ticks_start; + clock_t result; + + ENTER(); + + /* Get the current time. */ + + PROFILE_OFF(); + DateStamp(&now); + PROFILE_ON(); + + /* Break the current and start time down into minutes and ticks. */ + minutes_now = now.ds_Days * 24 * 60 + now.ds_Minute; + ticks_now = now.ds_Tick; + + minutes_start = __start_time.ds_Days * 24 * 60 + __start_time.ds_Minute; + ticks_start = __start_time.ds_Tick; + + /* Subtract the start time from the current time. We start + * with the ticks. + */ + ticks_now -= ticks_start; + + /* Check for underflow. */ + while(ticks_now < 0) + { + /* Borrow a minute from the current time. */ + ticks_now += 60 * TICKS_PER_SECOND; + + minutes_now--; + } + + /* Now for the minutes. */ + minutes_now -= minutes_start; + + /* Check if any time has passed at all, then return the difference. */ + if(minutes_now >= 0) + result = (clock_t)(minutes_now * 60 * TICKS_PER_SECOND + ticks_now); + else + result = (clock_t)0; + + RETURN(result); + return(result); +} diff --git a/library/time_converttime.c b/library/time_converttime.c new file mode 100644 index 0000000..9fe2af4 --- /dev/null +++ b/library/time_converttime.c @@ -0,0 +1,87 @@ +/* + * $Id: time_converttime.c,v 1.1.1.1 2004-07-26 16:32:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TIME_HEADERS_H +#include "time_headers.h" +#endif /* _TIME_HEADERS_H */ + +/****************************************************************************/ + +struct tm * +__convert_time(ULONG seconds, LONG gmt_offset, struct tm * tm) +{ + DECLARE_UTILITYBASE(); + struct ClockData clock_data; + struct tm * result; + ULONG delta; + + ENTER(); + + assert( UtilityBase != NULL ); + + /* We need to convert the time from Unix-style UTC + * back into Amiga style local time. + * + * First, the Unix time offset will have to go. + */ + if(seconds < UNIX_TIME_OFFSET) + seconds = 0; + else + seconds -= UNIX_TIME_OFFSET; + + /* Now the local time offset will have to go. */ + seconds -= gmt_offset; + + Amiga2Date(seconds, &clock_data); + + tm->tm_sec = clock_data.sec; + tm->tm_min = clock_data.min; + tm->tm_hour = clock_data.hour; + tm->tm_mday = clock_data.mday; + tm->tm_mon = clock_data.month - 1; + tm->tm_year = clock_data.year - 1900; + tm->tm_wday = clock_data.wday; + tm->tm_isdst = -1; + + clock_data.mday = 1; + clock_data.month = 1; + + delta = Date2Amiga(&clock_data); + + tm->tm_yday = (seconds - delta) / (24 * 60 * 60); + + result = tm; + + RETURN(result); + return(result); +} diff --git a/library/time_ctime.c b/library/time_ctime.c new file mode 100644 index 0000000..0bbf241 --- /dev/null +++ b/library/time_ctime.c @@ -0,0 +1,73 @@ +/* + * $Id: time_ctime.c,v 1.1.1.1 2004-07-26 16:32:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _TIME_HEADERS_H +#include "time_headers.h" +#endif /* _TIME_HEADERS_H */ + +/****************************************************************************/ + +char * +ctime(const time_t *tptr) +{ + char * result = NULL; + + ENTER(); + + assert( tptr != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(tptr == NULL) + { + SHOWMSG("invalid tptr parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + result = asctime(localtime(tptr)); + + out: + + RETURN(result); + return(result); +} diff --git a/library/time_data.c b/library/time_data.c new file mode 100644 index 0000000..40dc126 --- /dev/null +++ b/library/time_data.c @@ -0,0 +1,96 @@ +/* + * $Id: time_data.c,v 1.1.1.1 2004-07-26 16:32:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TIME_HEADERS_H +#include "time_headers.h" +#endif /* _TIME_HEADERS_H */ + +/****************************************************************************/ + +struct DateStamp __start_time; + +/****************************************************************************/ + +const char * const __abbreviated_week_day_names[7] = +{ + "Sun", + "Mon", + "Tue", + "Wed", + "Thu", + "Fri", + "Sat" +}; + +const char * const __week_day_names[7] = +{ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday" +}; + +const char * const __abbreviated_month_names[12] = +{ + "Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec" +}; + +const char * const __month_names[12] = +{ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December" +}; diff --git a/library/time_difftime.c b/library/time_difftime.c new file mode 100644 index 0000000..1b091f8 --- /dev/null +++ b/library/time_difftime.c @@ -0,0 +1,56 @@ +/* + * $Id: time_difftime.c,v 1.1.1.1 2004-07-26 16:32:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TIME_HEADERS_H +#include "time_headers.h" +#endif /* _TIME_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +double +difftime(time_t t1,time_t t0) +{ + double result; + + result = ((double)t1) - ((double)t0); + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/time_gettimeofday.c b/library/time_gettimeofday.c new file mode 100644 index 0000000..f68428a --- /dev/null +++ b/library/time_gettimeofday.c @@ -0,0 +1,94 @@ +/* + * $Id: time_gettimeofday.c,v 1.1.1.1 2004-07-26 16:32:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TIME_HEADERS_H +#include "time_headers.h" +#endif /* _TIME_HEADERS_H */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +gettimeofday(struct timeval *tp, struct timezone *tzp) +{ + ULONG seconds,microseconds; + struct DateStamp ds; + + ENTER(); + + PROFILE_OFF(); + DateStamp(&ds); + PROFILE_ON(); + + seconds = UNIX_TIME_OFFSET + 60 * ((ULONG)ds.ds_Minute + 24 * 60 * (ULONG)ds.ds_Days) + (ds.ds_Tick / TICKS_PER_SECOND); + microseconds = (1000000 * (ds.ds_Tick % TICKS_PER_SECOND)) / TICKS_PER_SECOND; + + if(__default_locale != NULL) + seconds += 60 * __default_locale->loc_GMTOffset; + + if(tp != NULL) + { + tp->tv_sec = (long)seconds; + tp->tv_usec = (long)microseconds; + + SHOWVALUE(tp->tv_sec); + SHOWVALUE(tp->tv_usec); + } + + if(tzp != NULL) + { + if(__default_locale != NULL) + tzp->tz_minuteswest = __default_locale->loc_GMTOffset; + else + tzp->tz_minuteswest = 0; + + tzp->tz_dsttime = -1; + + SHOWVALUE(tzp->tz_minuteswest); + SHOWVALUE(tzp->tz_dsttime); + } + + RETURN(0); + return(0); +} diff --git a/library/time_gmtime.c b/library/time_gmtime.c new file mode 100644 index 0000000..455f15a --- /dev/null +++ b/library/time_gmtime.c @@ -0,0 +1,74 @@ +/* + * $Id: time_gmtime.c,v 1.1.1.1 2004-07-26 16:32:22 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _TIME_HEADERS_H +#include "time_headers.h" +#endif /* _TIME_HEADERS_H */ + +/****************************************************************************/ + +struct tm * +gmtime(const time_t *t) +{ + static struct tm tm; + struct tm * result = NULL; + + ENTER(); + + assert( t != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(t == NULL) + { + SHOWMSG("invalid t parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + result = __convert_time((*t), 0, &tm); + + out: + + RETURN(result); + return(result); +} diff --git a/library/time_headers.h b/library/time_headers.h new file mode 100644 index 0000000..fa1b9ca --- /dev/null +++ b/library/time_headers.h @@ -0,0 +1,103 @@ +/* + * $Id: time_headers.h,v 1.1.1.1 2004-07-26 16:32:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TIME_HEADERS_H +#define _TIME_HEADERS_H + +/****************************************************************************/ + +#include +#include +#include + +#include + +#include + +#include + +#include + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +#include +#include +#include +#include +#include + +/****************************************************************************/ + +#ifndef _STDLIB_LOCALE_UTILITY_H +#include "stdlib_locale_utility.h" +#endif /* _STDLIB_LOCALE_UTILITY_H */ + +/****************************************************************************/ + +#include "macros.h" +#include "debug.h" + +/****************************************************************************/ + +#ifndef _MATH_FP_SUPPORT_H +#include "math_fp_support.h" +#endif /* _MATH_FP_SUPPORT_H */ + +/****************************************************************************/ + +extern struct DateStamp __start_time; + +/****************************************************************************/ + +extern const char * const __abbreviated_week_day_names[7]; +extern const char * const __week_day_names[7]; +extern const char * const __abbreviated_month_names[12]; +extern const char * const __month_names[12]; + +/****************************************************************************/ + +extern char * __number_to_string(unsigned int number,char * string,size_t max_len,size_t min_len); +extern struct tm * __convert_time(ULONG seconds, LONG gmt_offset, struct tm * tm); + +/****************************************************************************/ + +#endif /* _TIME_HEADERS_H */ diff --git a/library/time_localtime.c b/library/time_localtime.c new file mode 100644 index 0000000..21a171f --- /dev/null +++ b/library/time_localtime.c @@ -0,0 +1,89 @@ +/* + * $Id: time_localtime.c,v 1.1.1.1 2004-07-26 16:32:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _TIME_HEADERS_H +#include "time_headers.h" +#endif /* _TIME_HEADERS_H */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +struct tm * +localtime(const time_t *t) +{ + static struct tm tm; + struct tm * result = NULL; + LONG gmt_offset; + + ENTER(); + + assert( t != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(t == NULL) + { + SHOWMSG("invalid t parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + /* The time parameter given represents local time and + * must be converted to UTC before we proceed. + */ + if(__default_locale != NULL) + gmt_offset = 60 * __default_locale->loc_GMTOffset; + else + gmt_offset = 0; + + SHOWVALUE(gmt_offset); + + result = __convert_time((*t), gmt_offset, &tm); + + out: + + RETURN(result); + return(result); +} diff --git a/library/time_mktime.c b/library/time_mktime.c new file mode 100644 index 0000000..bf848c6 --- /dev/null +++ b/library/time_mktime.c @@ -0,0 +1,201 @@ +/* + * $Id: time_mktime.c,v 1.1.1.1 2004-07-26 16:32:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _TIME_HEADERS_H +#include "time_headers.h" +#endif /* _TIME_HEADERS_H */ + +/****************************************************************************/ + +time_t +mktime(struct tm *tm) +{ + DECLARE_UTILITYBASE(); + struct ClockData clock_data; + ULONG seconds, delta; + time_t result = (time_t)-1; + int error = EINVAL; + + ENTER(); + + assert( tm != NULL ); + assert( UtilityBase != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(tm == NULL) + { + SHOWMSG("invalid tm parameter"); + + error = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + /* The month must be valid. */ + if(tm->tm_mon < 0 || tm->tm_mon > 11) + { + SHOWVALUE(tm->tm_mon); + SHOWMSG("invalid month"); + goto out; + } + + /* The day of the month must be valid. */ + if(tm->tm_mday < 1 || tm->tm_mday > 31) + { + SHOWVALUE(tm->tm_mday); + SHOWMSG("invalid day of month"); + goto out; + } + + /* The year must be valid. */ + if(tm->tm_year < 78) + { + SHOWVALUE(tm->tm_year); + SHOWMSG("invalid year"); + goto out; + } + + /* Is this the month of February? */ + if(tm->tm_mon == 1) + { + char max_month_days; + int year; + + /* We need to have the full year number for the + * leap year calculation below. + */ + year = tm->tm_year + 1900; + + /* Now for the famous leap year calculation rules... We + * need to find out if the number of days in the month + * of February are appropriate for the data given. + */ + if((year % 4) != 0) + max_month_days = 28; + else if ((year % 400) == 0) + max_month_days = 29; + else if ((year % 100) == 0) + max_month_days = 28; + else + max_month_days = 29; + + /* The day of the month must be valid. */ + if(tm->tm_mday > max_month_days) + { + SHOWVALUE(tm->tm_mday); + SHOWMSG("invalid day of month"); + goto out; + } + } + else + { + static const char max_month_days[12] = + { + 31, 0,31, + 30,31,30, + 31,31,30, + 31,30,31 + }; + + /* The day of the month must be valid. */ + if(tm->tm_mday > max_month_days[tm->tm_mon]) + { + SHOWVALUE(tm->tm_mday); + SHOWMSG("invalid day of month"); + goto out; + } + } + + /* The hour must be valid. */ + if(tm->tm_hour < 0 || tm->tm_hour > 23) + { + SHOWVALUE(tm->tm_hour); + SHOWMSG("invalid hour"); + goto out; + } + + /* The minute must be valid. */ + if(tm->tm_min < 0 || tm->tm_min > 59) + { + SHOWVALUE(tm->tm_min); + SHOWMSG("invalid minute"); + goto out; + } + + if(tm->tm_sec < 0 || tm->tm_sec > 59) + { + SHOWVALUE(tm->tm_sec); + SHOWMSG("invalid seconds"); + goto out; + } + + clock_data.sec = tm->tm_sec; + clock_data.min = tm->tm_min; + clock_data.hour = tm->tm_hour; + clock_data.mday = tm->tm_mday; + clock_data.month = tm->tm_mon + 1; + clock_data.year = tm->tm_year + 1900; + + seconds = Date2Amiga(&clock_data); + + /* The AmigaOS "epoch" starts with January 1st, 1978, which was + * a Sunday. + */ + tm->tm_wday = (seconds / (24 * 60 * 60)) % 7; + + clock_data.mday = 1; + clock_data.month = 1; + + delta = Date2Amiga(&clock_data); + + tm->tm_yday = (seconds - delta) / (24 * 60 * 60); + + result = seconds + UNIX_TIME_OFFSET; + + error = 0; + + out: + + errno = error; + + RETURN(result); + return(result); +} diff --git a/library/time_numbertostring.c b/library/time_numbertostring.c new file mode 100644 index 0000000..ef406e6 --- /dev/null +++ b/library/time_numbertostring.c @@ -0,0 +1,96 @@ +/* + * $Id: time_numbertostring.c,v 1.1.1.1 2004-07-26 16:32:23 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TIME_HEADERS_H +#include "time_headers.h" +#endif /* _TIME_HEADERS_H */ + +/****************************************************************************/ + +char * +__number_to_string( + unsigned int number, + char * string, + size_t max_len, + size_t min_len) +{ + char * s = string; + size_t len,i; + char c; + + assert( string != NULL && max_len >= min_len ); + + /* One off for the terminating NUL. */ + if(max_len > 0) + max_len--; + + len = 0; + + /* Convert the number digit by digit, building the + * string in reverse order. + */ + do + { + if(max_len == 0) + break; + + max_len--; + + (*s++) = '0' + (number % 10); + number /= 10; + + len++; + } + while(number > 0); + + /* Pad the string to the requested length, if necessary. */ + while(max_len > 0 && len < min_len) + { + max_len--; + + (*s++) = '0'; + len++; + } + + (*s) = '\0'; + + /* Reverse the string in place. */ + for(i = 0 ; i < len / 2 ; i++) + { + c = string[len-1-i]; + string[len-1-i] = string[i]; + string[i] = c; + } + + return(string); +} diff --git a/library/time_strftime.c b/library/time_strftime.c new file mode 100644 index 0000000..b26ad6f --- /dev/null +++ b/library/time_strftime.c @@ -0,0 +1,626 @@ +/* + * $Id: time_strftime.c,v 1.1.1.1 2004-07-26 16:32:24 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _TIME_HEADERS_H +#include "time_headers.h" +#endif /* _TIME_HEADERS_H */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +struct format_hook_data +{ + char * buffer; + int max_size; + int len; +}; + +/****************************************************************************/ + +static void +format_hook_function( + struct Hook * hook, + long c, + struct Locale * UNUSED unused_locale) +{ + struct format_hook_data * data = hook->h_Data; + + if(c != '\0') + { + if(data->max_size > 0) + { + /* There's still room for another character. */ + (*data->buffer++) = (char)c; + + data->len++; + + data->max_size--; + } + else + { + /* Indicate that the buffer was too short. */ + data->len = 0; + } + } +} + +/****************************************************************************/ + +static void +store_string_via_hook(const char * string,int len,struct Hook * hook) +{ + DECLARE_UTILITYBASE(); + + assert( string != NULL && hook != NULL ); + assert( UtilityBase != NULL ); + + if(len < 0) + len = strlen(string); + + while(len-- > 0) + CallHookPkt(hook,(APTR)((ULONG)(*string++)),NULL); +} + +/****************************************************************************/ + +static void +format_date(const char *format,const struct tm *tm,time_t time_value,struct Hook * hook) +{ + struct tm other_tm; + struct tm copy_tm; + time_t other_time_value = 0; /* ZZZ compiler claims that this assignment is unnecessary. */ + char buffer[40]; + const char * str; + char c; + int i; + + assert( format != NULL && tm != NULL && hook != NULL); + + /* Fill in the week day if it's not in proper range. */ + if(tm->tm_wday < 0 || tm->tm_wday > 6) + { + time_t seconds; + + other_tm = (*tm); + + seconds = mktime(&other_tm); + if(seconds != (time_t)-1) + { + __convert_time(seconds,0,&other_tm); + + copy_tm = (*tm); + copy_tm.tm_wday = other_tm.tm_wday; + + tm = ©_tm; + } + } + + while((c = (*format++)) != '\0') + { + /* This is the simple case. */ + if(c != '%') + { + store_string_via_hook(&c,1,hook); + continue; + } + + /* OK, what kind of format is expected? */ + c = (*format++); + + /* We stop if the string ends here. Hm... should this count as an error? */ + if(c == '\0') + break; + + switch(c) + { + /* Abbreviated weekday name ("Sun"). */ + case 'a': + + assert( 0 <= tm->tm_wday && tm->tm_wday <= 6 ); + + if(0 <= tm->tm_wday && tm->tm_wday <= 6) + str = __abbreviated_week_day_names[tm->tm_wday]; + else + str = "-"; + + store_string_via_hook(str,-1,hook); + break; + + /* Full weekday name ("Sunday"). */ + case 'A': + + assert( 0 <= tm->tm_wday && tm->tm_wday <= 6 ); + + if(0 <= tm->tm_wday && tm->tm_wday <= 6) + str = __week_day_names[tm->tm_wday]; + else + str = "-"; + + store_string_via_hook(str,-1,hook); + break; + + /* Abbreviated month name ("Jan"). */ + case 'b': + + assert( 0 <= tm->tm_mon && tm->tm_mon <= 11 ); + + if(0 <= tm->tm_mon && tm->tm_mon <= 11) + str = __abbreviated_month_names[tm->tm_mon]; + else + str = "-"; + + store_string_via_hook(str,-1,hook); + break; + + /* Full month name ("January"). */ + case 'B': + + assert( 0 <= tm->tm_mon && tm->tm_mon <= 11 ); + + if(0 <= tm->tm_mon && tm->tm_mon <= 11) + str = __month_names[tm->tm_mon]; + else + str = ""; + + store_string_via_hook(str,-1,hook); + break; + + /* Locale specific date and time ("%a %b %d %H:%M:%S %Y"). */ + case 'c': + + assert( 0 <= tm->tm_wday && tm->tm_wday <= 6 ); + + if(0 <= tm->tm_wday && tm->tm_wday <= 6) + str = __abbreviated_week_day_names[tm->tm_wday]; + else + str = "-"; + + store_string_via_hook(str,-1,hook); + store_string_via_hook(" ",1,hook); + + assert( 0 <= tm->tm_mon && tm->tm_mon <= 11 ); + + if(0 <= tm->tm_mon && tm->tm_mon <= 11) + str = __abbreviated_month_names[tm->tm_mon]; + else + str = "-"; + + store_string_via_hook(str,-1,hook); + store_string_via_hook(" ",1,hook); + + assert( 1 <= tm->tm_mday && tm->tm_mday <= 31 ); + + __number_to_string((unsigned int)tm->tm_mday,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + store_string_via_hook(" ",1,hook); + + assert( 0 <= tm->tm_hour && tm->tm_hour <= 23 ); + + __number_to_string((unsigned int)tm->tm_hour,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + store_string_via_hook(":",1,hook); + + assert( 0 <= tm->tm_min && tm->tm_min <= 59 ); + + __number_to_string((unsigned int)tm->tm_min,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + store_string_via_hook(":",1,hook); + + assert( 0 <= tm->tm_sec && tm->tm_sec <= 59 ); + + __number_to_string((unsigned int)tm->tm_sec,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + store_string_via_hook(" ",1,hook); + + assert( 0 <= tm->tm_year ); + + __number_to_string((unsigned int)1900 + tm->tm_year,buffer,sizeof(buffer),0); + store_string_via_hook(buffer,-1,hook); + + break; + + /* Day of the month ("01"-"31"). */ + case 'd': + + assert( 1 <= tm->tm_mday && tm->tm_mday <= 31 ); + + __number_to_string((unsigned int)tm->tm_mday,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + break; + + /* Hour ("00"-"23"). */ + case 'H': + + assert( 0 <= tm->tm_hour && tm->tm_hour <= 23 ); + + __number_to_string((unsigned int)tm->tm_hour,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + break; + + /* Hour ("00"-"12"). */ + case 'I': + + assert( 0 <= tm->tm_hour && tm->tm_hour <= 23 ); + + __number_to_string((unsigned int)((tm->tm_hour > 12) ? (tm->tm_hour - 12) : tm->tm_hour),buffer,sizeof(buffer),2); + + store_string_via_hook(buffer,2,hook); + break; + + /* Day of the year ("001"-"366"). */ + case 'j': + + other_tm = (*tm); + other_tm.tm_mday = 1; + other_tm.tm_mon = 0; + + other_time_value = mktime(&other_tm); + + __number_to_string((unsigned int)(other_time_value - time_value) / (24 * 60 * 60) + 1,buffer,sizeof(buffer),3); + store_string_via_hook(buffer,-1,hook); + break; + + /* Month ("01"-"12"). */ + case 'm': + + assert( 0 <= tm->tm_mon && tm->tm_mon <= 11 ); + + __number_to_string((unsigned int)tm->tm_mon+1,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + break; + + /* Minute ("00"-"59"). */ + case 'M': + + assert( 0 <= tm->tm_min && tm->tm_min <= 59 ); + + __number_to_string((unsigned int)tm->tm_min,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + break; + + /* 'Ante meridiem'/'Post meridiem' indicator. */ + case 'p': + + assert( 0 <= tm->tm_hour && tm->tm_hour <= 23 ); + + store_string_via_hook((tm->tm_hour < 12) ? "AM" :" PM",2,hook); + break; + + /* Seconds ("00"-"59"). */ + case 'S': + + assert( 0 <= tm->tm_sec && tm->tm_sec <= 59 ); + + __number_to_string((unsigned int)tm->tm_sec,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + break; + + /* Week number of the year; first week is the one that contains + * the first Sunday of the year ("00"-"53"). + */ + case 'U': + + /* Go back to January and find the first Sunday. */ + other_tm = (*tm); + other_tm.tm_mon = 0; + + for(i = 0 ; i < 7 ; i++) + { + other_tm.tm_mday = i+1; + + other_time_value = mktime(&other_tm); + if(other_tm.tm_wday == 0) + break; + } + + /* Store the number of weeks difference between + * the given day and the first Sunday. + */ + if(time_value < other_time_value) + { + /* This must be week zero. */ + __number_to_string((unsigned int)0,buffer,sizeof(buffer),2); + } + else + { + __number_to_string((unsigned int)(time_value - other_time_value) / (7 * 24 * 60 * 60) + 1,buffer,sizeof(buffer),2); + } + + store_string_via_hook(buffer,2,hook); + break; + + /* Week day ("0"-"6"). */ + case 'w': + + assert( 0 <= tm->tm_wday && tm->tm_wday <= 6 ); + + __number_to_string((unsigned int)tm->tm_wday,buffer,sizeof(buffer),0); + store_string_via_hook(buffer,1,hook); + break; + + /* Week number of the year; first week is the one that contains + * the first Monday of the year ("00"-"53"). + */ + case 'W': + + /* Go back to January and find the first Monday. */ + other_tm = (*tm); + other_tm.tm_mon = 0; + + for(i = 0 ; i < 7 ; i++) + { + other_tm.tm_mday = i+1; + + other_time_value = mktime(&other_tm); + if(other_tm.tm_wday == 1) + break; + } + + /* Store the number of weeks difference between + * the given day and the first Monday. + */ + if(time_value < other_time_value) + { + /* This must be week zero. */ + __number_to_string((unsigned int)0,buffer,sizeof(buffer),2); + } + else + { + __number_to_string((unsigned int)(time_value - other_time_value) / (7 * 24 * 60 * 60) + 1,buffer,sizeof(buffer),2); + } + + store_string_via_hook(buffer,2,hook); + break; + + /* Locale-specific date ("%a %b %d, %Y"). */ + case 'x': + + assert( 0 <= tm->tm_wday && tm->tm_wday <= 6 ); + + if(0 <= tm->tm_wday && tm->tm_wday <= 6) + str = __abbreviated_week_day_names[tm->tm_wday]; + else + str = "-"; + + store_string_via_hook(str,-1,hook); + store_string_via_hook(" ",1,hook); + + assert( 0 <= tm->tm_mon && tm->tm_mon <= 11 ); + + if(0 <= tm->tm_mon && tm->tm_mon <= 11) + str = __abbreviated_month_names[tm->tm_mon]; + else + str = "-"; + + store_string_via_hook(str,-1,hook); + store_string_via_hook(" ",1,hook); + + assert( 1 <= tm->tm_mday && tm->tm_mday <= 31 ); + + __number_to_string((unsigned int)tm->tm_mday,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + store_string_via_hook(", ",2,hook); + + assert( 0 <= tm->tm_year ); + + __number_to_string((unsigned int)1900 + tm->tm_year,buffer,sizeof(buffer),0); + store_string_via_hook(buffer,-1,hook); + + break; + + /* Locale-specific time ("%H:%M:%S"). */ + case 'X': + + assert( 0 <= tm->tm_hour && tm->tm_hour <= 23 ); + + __number_to_string((unsigned int)tm->tm_hour,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + store_string_via_hook(":",1,hook); + + assert( 0 <= tm->tm_min && tm->tm_min <= 59 ); + + __number_to_string((unsigned int)tm->tm_min,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + store_string_via_hook(":",1,hook); + + assert( 0 <= tm->tm_sec && tm->tm_sec <= 59 ); + + __number_to_string((unsigned int)tm->tm_sec,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + break; + + /* Year without century ("00"-"99"). */ + case 'y': + + assert( 0 <= tm->tm_year ); + + __number_to_string((unsigned int)tm->tm_year % 100,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,2,hook); + break; + + /* Year with century ("1970"-"2147483647"). */ + case 'Y': + + assert( 0 <= tm->tm_year ); + + __number_to_string((unsigned int)1900 + tm->tm_year,buffer,sizeof(buffer),0); + store_string_via_hook(buffer,-1,hook); + break; + + /* Time zone name. */ + case 'Z': + + store_string_via_hook("GMT",3,hook); + + if(__default_locale != NULL) + { + int hours_west_of_gmt; + char sign; + + hours_west_of_gmt = __default_locale->loc_GMTOffset / 60; + if(hours_west_of_gmt < 0) + { + sign = '+'; + + hours_west_of_gmt = (-hours_west_of_gmt); + } + else if (hours_west_of_gmt > 0) + { + sign = '-'; + } + + if(hours_west_of_gmt != 0) + { + store_string_via_hook(&sign,1,hook); + __number_to_string((unsigned int)hours_west_of_gmt,buffer,sizeof(buffer),2); + store_string_via_hook(buffer,-1,hook); + } + } + + break; + + /* Store that character 'as is'. */ + default: + + store_string_via_hook(&c,1,hook); + break; + } + } +} + +/****************************************************************************/ + +size_t +strftime(char *s, size_t maxsize, const char *format, const struct tm *tm) +{ + DECLARE_LOCALEBASE(); + struct format_hook_data data; + struct Hook hook; + size_t result = 0; + struct tm tm_copy; + time_t time_value; + + ENTER(); + + SHOWPOINTER(s); + SHOWVALUE(maxsize); + SHOWSTRING(format); + SHOWPOINTER(tm); + + assert( s != NULL && format != NULL && tm != NULL ); + assert( (int)maxsize >= 0 ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(s == NULL || format == NULL || tm == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + data.len = 0; + + if(maxsize > 0) + { + tm_copy = (*tm); + + time_value = mktime(&tm_copy); + if(time_value == (time_t)-1) + { + SHOWMSG("invalid time"); + goto out; + } + + data.buffer = s; + data.max_size = maxsize-1; + + memset(&hook,0,sizeof(hook)); + + #if defined(__amigaos4__) + { + hook.h_Entry = (HOOKFUNC)format_hook_function; + } + #else + { + hook.h_Entry = (HOOKFUNC)HookEntry; + hook.h_SubEntry = (HOOKFUNC)format_hook_function; + } + #endif /* __amigaos4__ */ + + hook.h_Data = &data; + + /* Try to use the locale.library date/time conversion function. */ + if(__locale_table[LC_TIME] != NULL) + { + struct DateStamp ds; + + time_value -= UNIX_TIME_OFFSET; + + ds.ds_Days = time_value / (24 * 60 * 60); + ds.ds_Minute = (time_value % (24 * 60 * 60)) / 60; + ds.ds_Tick = (time_value % 60) * TICKS_PER_SECOND; + + assert( LocaleBase != NULL ); + + FormatDate(__locale_table[LC_TIME],(STRPTR)format,&ds,&hook); + } + else + { + format_date(format,tm,time_value,&hook); + } + + (*data.buffer) = '\0'; + + SHOWSTRING(s); + } + + result = data.len; + + out: + + RETURN(result); + return(result); +} diff --git a/library/time_time.c b/library/time_time.c new file mode 100644 index 0000000..41627e6 --- /dev/null +++ b/library/time_time.c @@ -0,0 +1,69 @@ +/* + * $Id: time_time.c,v 1.1.1.1 2004-07-26 16:32:25 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TIME_HEADERS_H +#include "time_headers.h" +#endif /* _TIME_HEADERS_H */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +time_t +time(time_t * tptr) +{ + struct DateStamp ds; + ULONG seconds; + time_t result; + + PROFILE_OFF(); + DateStamp(&ds); + PROFILE_ON(); + + seconds = 60 * ((ULONG)ds.ds_Minute + 24 * 60 * (ULONG)ds.ds_Days) + (ds.ds_Tick / TICKS_PER_SECOND); + + /* time() should try to return the current time in UTC form. Thus, + * we have to take the local time zone into account. + */ + if(__default_locale != NULL) + result = UNIX_TIME_OFFSET + seconds + 60 * __default_locale->loc_GMTOffset; + else + result = UNIX_TIME_OFFSET + seconds; + + if(tptr != NULL) + (*tptr) = result; + + return(result); +} diff --git a/library/unistd_access.c b/library/unistd_access.c new file mode 100644 index 0000000..6348044 --- /dev/null +++ b/library/unistd_access.c @@ -0,0 +1,231 @@ +/* + * $Id: unistd_access.c,v 1.1.1.1 2004-07-26 16:32:25 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +access(const char * path_name, int mode) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info path_name_nti; + #endif /* UNIX_PATH_SEMANTICS */ + int result = -1; + BPTR lock = ZERO; + + ENTER(); + + SHOWSTRING(path_name); + SHOWVALUE(mode); + + assert( path_name != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL) + { + SHOWMSG("invalid path name"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + if(mode < 0 || mode > (R_OK|W_OK|X_OK|F_OK)) + { + SHOWMSG("invalid mode"); + + errno = EINVAL; + goto out; + } + + #if defined(UNIX_PATH_SEMANTICS) + { + STRPTR actual_path_name = NULL; + + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + + if(NOT path_name_nti.is_root) + actual_path_name = (STRPTR)path_name; + } + + if(actual_path_name != NULL) + { + D(("trying to get a lock on '%s'",actual_path_name)); + + lock = Lock(actual_path_name,SHARED_LOCK); + if(lock == ZERO) + { + __translate_access_io_error_to_errno(IoErr(),&errno); + goto out; + } + } + } + #else + { + D(("trying to get a lock on '%s'",path_name)); + + PROFILE_OFF(); + lock = Lock((STRPTR)path_name,SHARED_LOCK); + PROFILE_ON(); + + if(lock == ZERO) + { + __translate_access_io_error_to_errno(IoErr(),&errno); + goto out; + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + if((mode != F_OK) && (mode & (R_OK|W_OK|X_OK)) != 0) + { + D_S(struct FileInfoBlock,fib); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(lock == ZERO) + { + memset(fib,0,sizeof(*fib)); + + /* This is a simulated directory which cannot be + * modified under program control. + */ + fib->fib_Protection = FIBF_WRITE; + fib->fib_DirEntryType = ST_ROOT; + } + else + { + LONG status; + + PROFILE_OFF(); + status = Examine(lock,fib); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("couldn't examine"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + } + } + #else + { + LONG status; + + PROFILE_OFF(); + status = Examine(lock,fib); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("couldn't examine"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + fib->fib_Protection ^= FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE; + + if(FLAG_IS_SET(mode,R_OK)) + { + if(FLAG_IS_CLEAR(fib->fib_Protection,FIBF_READ)) + { + SHOWMSG("not readable"); + + errno = EACCES; + goto out; + } + } + + if(FLAG_IS_SET(mode,W_OK)) + { + if(FLAG_IS_CLEAR(fib->fib_Protection,FIBF_WRITE) || + FLAG_IS_CLEAR(fib->fib_Protection,FIBF_DELETE)) + { + SHOWMSG("not writable"); + + errno = EACCES; + goto out; + } + } + + if(FLAG_IS_SET(mode,X_OK)) + { + /* Note: 'X' means 'search' for directories, which is always + * permitted on the Amiga. + */ + if((fib->fib_DirEntryType < 0) && FLAG_IS_CLEAR(fib->fib_Protection,FIBF_EXECUTE)) + { + SHOWMSG("not executable"); + + errno = EACCES; + goto out; + } + } + } + + result = 0; + + out: + + PROFILE_OFF(); + UnLock(lock); + PROFILE_ON(); + + RETURN(result); + return(result); +} diff --git a/library/unistd_chdir.c b/library/unistd_chdir.c new file mode 100644 index 0000000..8c72dcf --- /dev/null +++ b/library/unistd_chdir.c @@ -0,0 +1,184 @@ +/* + * $Id: unistd_chdir.c,v 1.1.1.1 2004-07-26 16:32:25 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +chdir(const char * path_name) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info path_name_nti; + #endif /* UNIX_PATH_SEMANTICS */ + D_S(struct FileInfoBlock,fib); + BPTR dir_lock = ZERO; + LONG status; + int result = -1; + + ENTER(); + + SHOWSTRING(path_name); + + assert( path_name != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL) + { + SHOWMSG("invalid path name"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + + /* The pseudo root directory is a very special case indeed. We + * just accept it and don't pretend to have obtained a lock + * on anything. + */ + if(path_name_nti.is_root) + { + SHOWMSG("this is the / directory"); + + __restore_path_name(&path_name,&path_name_nti); + + /* ZZZ this must not fail */ + __set_current_path(path_name); + + result = 0; + + goto out; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + D(("trying to get a lock on '%s'",path_name)); + + PROFILE_OFF(); + dir_lock = Lock((STRPTR)path_name,SHARED_LOCK); + PROFILE_ON(); + + if(dir_lock == ZERO) + { + __translate_access_io_error_to_errno(IoErr(),&errno); + goto out; + } + + PROFILE_OFF(); + status = Examine(dir_lock,fib); + PROFILE_ON(); + + if(status == DOSFALSE) + { + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + if(fib->fib_DirEntryType < 0) + { + SHOWMSG("this is not a directory"); + + errno = ENOTDIR; + goto out; + } + + PROFILE_OFF(); + + if(__current_directory_changed) + { + BPTR old_dir; + + old_dir = CurrentDir(dir_lock); + + if(__unlock_current_directory) + UnLock(old_dir); + } + else + { + __original_current_directory = CurrentDir(dir_lock); + + __current_directory_changed = TRUE; + } + + __unlock_current_directory = TRUE; + + PROFILE_ON(); + + dir_lock = ZERO; + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + __restore_path_name(&path_name,&path_name_nti); + + /* ZZZ this must not fail */ + __set_current_path(path_name); + } + #endif /* UNIX_PATH_SEMANTICS */ + + result = 0; + + out: + + PROFILE_OFF(); + UnLock(dir_lock); + PROFILE_ON(); + + RETURN(result); + return(result); +} diff --git a/library/unistd_chown.c b/library/unistd_chown.c new file mode 100644 index 0000000..ad0b99a --- /dev/null +++ b/library/unistd_chown.c @@ -0,0 +1,169 @@ +/* + * $Id: unistd_chown.c,v 1.1.1.1 2004-07-26 16:32:26 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +chown(const char * path_name, uid_t owner, gid_t group) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info path_name_nti; + #endif /* UNIX_PATH_SEMANTICS */ + struct DevProc * dvp = NULL; + LONG status; + int result = -1; + + ENTER(); + + SHOWSTRING(path_name); + SHOWVALUE(owner); + SHOWVALUE(group); + + assert( path_name != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL) + { + SHOWMSG("invalid path name"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + if(owner > 65535 || group > 65535) + { + SHOWMSG("invalid owner or group"); + + errno = EINVAL; + goto out; + } + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + + if(path_name_nti.is_root) + { + errno = EACCES; + goto out; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + D(("changing owner of '%s'",path_name)); + + if(((struct Library *)DOSBase)->lib_Version >= 39) + { + PROFILE_OFF(); + status = SetOwner((STRPTR)path_name,(LONG)((((ULONG)owner) << 16) | group)); + PROFILE_ON(); + + if(status == DOSFALSE) + { + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + result = 0; + } + else + { + D_S(struct bcpl_name,new_name); + size_t len; + + len = strlen(path_name); + if(len >= sizeof(new_name->name)) + { + errno = ENAMETOOLONG; + goto out; + } + + PROFILE_OFF(); + dvp = GetDeviceProc((STRPTR)path_name,NULL); + PROFILE_ON(); + + if(dvp == NULL) + { + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + new_name->name[0] = len; + memmove(&new_name->name[1],path_name,len); + + PROFILE_OFF(); + status = DoPkt(dvp->dvp_Port,ACTION_SET_OWNER,dvp->dvp_Lock,MKBADDR(new_name),(LONG)((((ULONG)owner) << 16) | group),0,0); + PROFILE_ON(); + + if(status == DOSFALSE) + { + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + result = 0; + } + + out: + + PROFILE_OFF(); + FreeDeviceProc(dvp); + PROFILE_ON(); + + RETURN(result); + return(result); +} diff --git a/library/unistd_currentpathname.c b/library/unistd_currentpathname.c new file mode 100644 index 0000000..bcf2c16 --- /dev/null +++ b/library/unistd_currentpathname.c @@ -0,0 +1,40 @@ +/* + * $Id: unistd_currentpathname.c,v 1.1.1.1 2004-07-26 16:32:26 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +char __current_path_name[MAXPATHLEN]; diff --git a/library/unistd_data.c b/library/unistd_data.c new file mode 100644 index 0000000..a7db6fe --- /dev/null +++ b/library/unistd_data.c @@ -0,0 +1,60 @@ +/* + * $Id: unistd_data.c,v 1.1.1.1 2004-07-26 16:32:26 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +/* Names of files and directories to delete when shutting down. */ +struct MinList __unlink_list; + +/****************************************************************************/ + +/* Local timer I/O. */ +struct MsgPort * __timer_port; +struct timerequest * __timer_request; + +/****************************************************************************/ + +/* If the program's current directory was changed, here is where + * we find out about it. + */ +BPTR __original_current_directory; +BOOL __current_directory_changed; +BOOL __unlock_current_directory; diff --git a/library/unistd_dup.c b/library/unistd_dup.c new file mode 100644 index 0000000..bd0945b --- /dev/null +++ b/library/unistd_dup.c @@ -0,0 +1,48 @@ +/* + * $Id: unistd_dup.c,v 1.1.1.1 2004-07-26 16:32:26 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +dup(int file_descriptor) +{ + return(dup2(file_descriptor,-1)); +} diff --git a/library/unistd_dup2.c b/library/unistd_dup2.c new file mode 100644 index 0000000..ba17bbf --- /dev/null +++ b/library/unistd_dup2.c @@ -0,0 +1,149 @@ +/* + * $Id: unistd_dup2.c,v 1.1.1.1 2004-07-26 16:32:26 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +dup2(int file_descriptor1, int file_descriptor2) +{ + DECLARE_UTILITYBASE(); + struct fd * fd1; + int result = -1; + + ENTER(); + + SHOWVALUE(file_descriptor1); + SHOWVALUE(file_descriptor2); + + assert( UtilityBase != NULL ); + + if(__check_abort_enabled) + __check_abort(); + + assert( file_descriptor1 >= 0 && file_descriptor1 < __num_fd ); + assert( __fd[file_descriptor1] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor1]->fd_Flags,FDF_IN_USE) ); + + fd1 = __get_file_descriptor(file_descriptor1); + if(fd1 == NULL) + { + errno = EBADF; + goto out; + } + + if(file_descriptor2 < 0) + { + /* Try to find a place to put the duplicate into. */ + file_descriptor2 = __find_vacant_fd_entry(); + if(file_descriptor2 < 0) + { + /* No free space, so let's grow the table. */ + if(__grow_fd_table() < 0) + { + SHOWMSG("not enough memory for new file descriptor"); + goto out; + } + + file_descriptor2 = __find_vacant_fd_entry(); + assert( file_descriptor2 >= 0 ); + } + } + else if (file_descriptor1 != file_descriptor2) + { + /* Make sure the requested duplicate exists. */ + while(file_descriptor2 >= __num_fd) + { + if(__check_abort_enabled) + __check_abort(); + + if(__grow_fd_table() < 0) + goto out; + } + + assert( file_descriptor2 >= 0 && file_descriptor2 < __num_fd ); + assert( __fd[file_descriptor2] != NULL ); + } + + if(file_descriptor1 != file_descriptor2) + { + struct file_hook_message message; + struct fd * fd2; + + /* Have a look at the requested file descriptor. */ + assert( 0 <= file_descriptor2 && file_descriptor2 < __num_fd ); + + fd2 = __fd[file_descriptor2]; + + assert( fd2 != NULL ); + + /* Make sure that the entry is cleaned up before we used it. */ + if(FLAG_IS_SET(fd2->fd_Flags,FDF_IN_USE)) + { + SHOWMSG("closing file descriptor #2"); + + if(close(file_descriptor2) < 0) + goto out; + } + + SHOWMSG("calling the hook"); + + message.action = file_hook_action_duplicate_fd; + message.duplicate_fd = fd2; + + assert( fd1->fd_Hook != NULL ); + + CallHookPkt(fd1->fd_Hook,fd1,&message); + + result = message.result; + if(result != 0) + { + errno = message.error; + goto out; + } + } + + result = file_descriptor2; + + out: + + RETURN(result); + return(result); +} diff --git a/library/unistd_fchown.c b/library/unistd_fchown.c new file mode 100644 index 0000000..cbc6148 --- /dev/null +++ b/library/unistd_fchown.c @@ -0,0 +1,91 @@ +/* + * $Id: unistd_fchown.c,v 1.1.1.1 2004-07-26 16:32:26 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +fchown(int file_descriptor, uid_t owner, gid_t group) +{ + DECLARE_UTILITYBASE(); + struct file_hook_message message; + int result = -1; + struct fd * fd; + + ENTER(); + + SHOWVALUE(file_descriptor); + SHOWVALUE(owner); + SHOWVALUE(group); + + assert( UtilityBase != NULL ); + + assert( file_descriptor >= 0 && file_descriptor < __num_fd ); + assert( __fd[file_descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + errno = EBADF; + goto out; + } + + SHOWMSG("calling the hook"); + + message.action = file_hook_action_change_owner; + message.owner = owner; + message.group = group; + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + + result = message.result; + errno = message.error; + + out: + + RETURN(result); + return(result); +} diff --git a/library/unistd_fdopen.c b/library/unistd_fdopen.c new file mode 100644 index 0000000..e89ad01 --- /dev/null +++ b/library/unistd_fdopen.c @@ -0,0 +1,107 @@ +/* + * $Id: unistd_fdopen.c,v 1.1.1.1 2004-07-26 16:32:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +FILE * +fdopen(int file_descriptor, const char * type) +{ + FILE * result = NULL; + int slot_number; + + ENTER(); + + SHOWVALUE(file_descriptor); + SHOWSTRING(type); + + assert(type != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(type == NULL) + { + SHOWMSG("invalid type parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + slot_number = __find_vacant_iob_entry(); + if(slot_number < 0) + { + if(__grow_iob_table() < 0) + { + SHOWMSG("not enough memory for a file buffer slot"); + goto out; + } + + slot_number = __find_vacant_iob_entry(); + assert( slot_number >= 0 ); + } + + assert( file_descriptor >= 0 && file_descriptor < __num_fd ); + assert( __fd[file_descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); + + if(__open_iob(NULL, type, file_descriptor, slot_number) < 0) + { + SHOWMSG("couldn't open the file for the file descriptor"); + goto out; + } + + result = (FILE *)__iob[slot_number]; + + out: + + RETURN(result); + return(result); +} diff --git a/library/unistd_fileno.c b/library/unistd_fileno.c new file mode 100644 index 0000000..e5579f8 --- /dev/null +++ b/library/unistd_fileno.c @@ -0,0 +1,96 @@ +/* + * $Id: unistd_fileno.c,v 1.1.1.1 2004-07-26 16:32:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +fileno(FILE * file) +{ + struct iob * iob = (struct iob *)file; + int result = -1; + + ENTER(); + + SHOWPOINTER(file); + + assert( file != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(file == NULL) + { + SHOWMSG("invalid file parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + assert( __is_valid_iob(iob) ); + assert( FLAG_IS_SET(iob->iob_Flags,IOBF_IN_USE) ); + + if(FLAG_IS_CLEAR(iob->iob_Flags,IOBF_IN_USE)) + { + errno = EBADF; + goto out; + } + + assert( iob->iob_Descriptor >= 0 && iob->iob_Descriptor < __num_fd ); + assert( __fd[iob->iob_Descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[iob->iob_Descriptor]->fd_Flags,FDF_IN_USE) ); + + result = iob->iob_Descriptor; + + out: + + RETURN(result); + return(result); +} diff --git a/library/unistd_ftruncate.c b/library/unistd_ftruncate.c new file mode 100644 index 0000000..96e6575 --- /dev/null +++ b/library/unistd_ftruncate.c @@ -0,0 +1,122 @@ +/* + * $Id: unistd_ftruncate.c,v 1.1.1.1 2004-07-26 16:32:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +ftruncate(int file_descriptor, off_t length) +{ + DECLARE_UTILITYBASE(); + struct file_hook_message message; + int result = -1; + struct fd * fd; + long int position; + + ENTER(); + + SHOWVALUE(file_descriptor); + SHOWVALUE(length); + + assert( UtilityBase != NULL ); + + assert( file_descriptor >= 0 && file_descriptor < __num_fd ); + assert( __fd[file_descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + errno = EBADF; + goto out; + } + + if(length < 0) + { + SHOWMSG("invalid length"); + + errno = EINVAL; + goto out; + } + + assert( FLAG_IS_SET(fd->fd_Flags,FDF_IN_USE) ); + + if(FLAG_IS_CLEAR(fd->fd_Flags,FDF_WRITE)) + { + SHOWMSG("file descriptor is not write-enabled"); + + errno = EBADF; + goto out; + } + + /* Remember where we started. */ + position = lseek(file_descriptor,0,SEEK_CUR); + if(position < 0) + goto out; + + SHOWMSG("calling the hook"); + + message.action = file_hook_action_truncate; + message.size = length; + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + + if(message.result < 0) + { + errno = message.error; + goto out; + } + + /* Return to the original file position. */ + if(lseek(file_descriptor,position,SEEK_SET) < 0) + goto out; + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/unistd_getcwd.c b/library/unistd_getcwd.c new file mode 100644 index 0000000..8258af5 --- /dev/null +++ b/library/unistd_getcwd.c @@ -0,0 +1,224 @@ +/* + * $Id: unistd_getcwd.c,v 1.1.1.1 2004-07-26 16:32:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +#include "stdlib_protos.h" + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +#undef getcwd + +/****************************************************************************/ + +char * +__getcwd(char * buffer,size_t buffer_size,const char *file,int line) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info buffer_nti; + #endif /* UNIX_PATH_SEMANTICS */ + char * buffer_allocated = NULL; + char * result = NULL; + BPTR dir_lock = ZERO; + + ENTER(); + + SHOWPOINTER(buffer); + SHOWVALUE(buffer_size); + + assert( buffer != NULL ); + assert( (int)buffer_size >= 0 ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(buffer == NULL || buffer_size == 0) + { + SHOWMSG("invalid buffer parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + PROFILE_OFF(); + dir_lock = Lock("",SHARED_LOCK); + PROFILE_ON(); + + if(dir_lock == ZERO) + { + SHOWMSG("could not get a lock on the current directory"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + /* If no buffer is provided, the behaviour of this function is + actually undefined. But we try to play nice and allocate + a custom buffer for the result to be returned. */ + if(buffer == NULL) + { + /* If the buffer size is not given, use the maximum we support. */ + if(buffer_size == 0) + buffer_size = MAXPATHLEN; + + buffer_allocated = __malloc(buffer_size,file,line); + if(buffer_allocated == NULL) + { + SHOWMSG("not enough memory for result buffer"); + + errno = ENOMEM; + goto out; + } + + buffer = buffer_allocated; + } + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__current_path_name[0] != '\0') + { + if(buffer_size == 0) + { + errno = ENOMEM; + goto out; + } + + assert( (int)buffer_size > 0 ); + + memmove(buffer,__current_path_name,buffer_size-1); + buffer[buffer_size-1] = '\0'; + + D(("returning absolute path name '%s'",buffer)); + + result = buffer; + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + if(result == NULL) + { + LONG status; + + PROFILE_OFF(); + status = NameFromLock(dir_lock,buffer,(LONG)buffer_size); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("could not get name from lock"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + const char * path_name = buffer; + size_t len; + + if(buffer_size == 0) + { + errno = ENOMEM; + goto out; + } + + assert( (int)buffer_size > 0 ); + + if(__translate_amiga_to_unix_path_name(&path_name,&buffer_nti) != 0) + goto out; + + len = strlen(path_name); + if(len > buffer_size-1) + len = buffer_size-1; + + memmove(buffer,path_name,len); + buffer[len] = '\0'; + } + } + #endif /* UNIX_PATH_SEMANTICS */ + } + + SHOWSTRING(buffer); + + result = buffer; + + out: + + if(result == NULL && buffer_allocated != NULL) + free(buffer_allocated); + + PROFILE_OFF(); + UnLock(dir_lock); + PROFILE_ON(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +char * +getcwd(char * buffer, size_t buffer_size) +{ + char * result; + + result = __getcwd(buffer,buffer_size,NULL,0); + + return(result); +} diff --git a/library/unistd_getopt.c b/library/unistd_getopt.c new file mode 100644 index 0000000..7baf2a2 --- /dev/null +++ b/library/unistd_getopt.c @@ -0,0 +1,163 @@ +/* + * $Id: unistd_getopt.c,v 1.1.1.1 2004-07-26 16:32:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int opterr = 1; +int optind = 1; +int optopt; +char * optarg; + +/****************************************************************************/ + +int +getopt(int argc, char * argv[], char *opts) +{ + static int sp = 1; + int result = EOF; + char *cp; + int c; + + ENTER(); + + SHOWVALUE(argc); + SHOWPOINTER(argv); + SHOWSTRING(opts); + + assert( argc > 0 && argv != NULL && opts != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(argv == NULL || opts == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + SHOWVALUE(optind); + + if(sp == 1) + { + if(optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') + { + goto out; + } + else if (strcmp(argv[optind], "--") == SAME) + { + optind++; + + goto out; + } + } + + optopt = c = argv[optind][sp]; + + if(c == ':' || (cp = strchr(opts, c)) == NULL) + { + if(opterr != 0) + fprintf(stderr, "%s%s%c\n", argv[0], ": illegal option -- ", c); + + if(argv[optind][++sp] == '\0') + { + optind++; + + sp = 1; + } + + result = '?'; + goto out; + } + + if(*++cp == ':') + { + if(argv[optind][sp+1] != '\0') + { + optarg = &argv[optind++][sp+1]; + } + else if (++optind >= argc) + { + if(opterr != 0) + fprintf(stderr, "%s%s%c\n", argv[0], ": option requires an argument -- ", c); + + sp = 1; + + result = '?'; + goto out; + } + else + { + optarg = argv[optind++]; + } + + sp = 1; + } + else + { + if(argv[optind][++sp] == '\0') + { + sp = 1; + + optind++; + } + + optarg = NULL; + } + + result = c; + + out: + + RETURN(result); + return(result); +} diff --git a/library/unistd_getpid.c b/library/unistd_getpid.c new file mode 100644 index 0000000..027a3c4 --- /dev/null +++ b/library/unistd_getpid.c @@ -0,0 +1,85 @@ +/* + * $Id: unistd_getpid.c,v 1.1.1.1 2004-07-26 16:32:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +pid_t +getpid(void) +{ + pid_t result; + + ENTER(); + + #if 0 + { + struct Process * this_process; + ULONG max_cli_number,i; + + this_process = (struct Process *)FindTask(NULL); + result = 0; + + Forbid(); + + max_cli_number = MaxCli(); + + for(i = 1 ; i <= max_cli_number ; i++) + { + if(FindCliProc(i) == this_process) + { + result = (pid_t)i; + break; + } + } + + Permit(); + } + #else + { + result = (pid_t)FindTask(NULL); + } + #endif + + /* ZZZ what should we do if are about to return zero? */ + assert( result != 0 ); + + RETURN(result); + return(result); +} diff --git a/library/unistd_headers.h b/library/unistd_headers.h new file mode 100644 index 0000000..c678e15 --- /dev/null +++ b/library/unistd_headers.h @@ -0,0 +1,78 @@ +/* + * $Id: unistd_headers.h,v 1.1.1.1 2004-07-26 16:32:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#define _UNISTD_HEADERS_H + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +extern char __current_path_name[MAXPATHLEN]; + +/****************************************************************************/ + +/* Names of files and directories to delete when shutting down. */ +extern struct MinList __unlink_list; + +/****************************************************************************/ + +/* Local timer I/O. */ +extern struct MsgPort * __timer_port; +extern struct timerequest * __timer_request; + +/****************************************************************************/ + +/* If the program's current directory was changed, here is where + * we find out about it. + */ +extern BPTR __original_current_directory; +extern BOOL __current_directory_changed; +extern BOOL __unlock_current_directory; + +/****************************************************************************/ + +extern BOOL __unix_path_semantics; + +/****************************************************************************/ + +extern int __set_current_path(const char * path_name); +extern void __strip_double_slash(char * file_name,int len); + +/****************************************************************************/ + +#endif /* _UNISTD_HEADERS_H */ diff --git a/library/unistd_init_exit.c b/library/unistd_init_exit.c new file mode 100644 index 0000000..a88a12a --- /dev/null +++ b/library/unistd_init_exit.c @@ -0,0 +1,122 @@ +/* + * $Id: unistd_init_exit.c,v 1.1.1.1 2004-07-26 16:32:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +#include "stdlib_protos.h" + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +__unistd_init(void) +{ + ENTER(); + + NewList((struct List *)&__unlink_list); + + RETURN(OK); + return(OK); +} + +/****************************************************************************/ + +void +__unistd_exit(void) +{ + ENTER(); + + PROFILE_OFF(); + + if(__unlink_list.mlh_Head != NULL && NOT IsListEmpty((struct List *)&__unlink_list)) + { + struct UnlinkNode * uln; + BPTR old_dir; + + while((uln = (struct UnlinkNode *)RemHead((struct List *)&__unlink_list))) + { + old_dir = CurrentDir(uln->uln_Lock); + + D(("deleting '%s'",uln->uln_Name)); + + DeleteFile(uln->uln_Name); + + CurrentDir(old_dir); + + UnLock(uln->uln_Lock); + } + } + + if(__timer_request != NULL) + { + if(__timer_request->tr_node.io_Device != NULL) + CloseDevice((struct IORequest *)__timer_request); + + DeleteIORequest((struct IORequest *)__timer_request); + __timer_request = NULL; + } + + if(__timer_port != NULL) + { + DeleteMsgPort(__timer_port); + __timer_port = NULL; + } + + if(__current_directory_changed) + { + BPTR old_dir; + + old_dir = CurrentDir(__original_current_directory); + __original_current_directory = ZERO; + + if(__unlock_current_directory) + { + UnLock(old_dir); + + __unlock_current_directory = FALSE; + } + + __current_directory_changed = FALSE; + } + + PROFILE_ON(); + + LEAVE(); +} diff --git a/library/unistd_isatty.c b/library/unistd_isatty.c new file mode 100644 index 0000000..7b409c7 --- /dev/null +++ b/library/unistd_isatty.c @@ -0,0 +1,87 @@ +/* + * $Id: unistd_isatty.c,v 1.1.1.1 2004-07-26 16:32:28 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +isatty(int file_descriptor) +{ + DECLARE_UTILITYBASE(); + struct file_hook_message message; + int result = -1; + struct fd * fd; + + ENTER(); + + SHOWVALUE(file_descriptor); + + assert( UtilityBase != NULL ); + + assert( file_descriptor >= 0 && file_descriptor < __num_fd ); + assert( __fd[file_descriptor] != NULL ); + assert( FLAG_IS_SET(__fd[file_descriptor]->fd_Flags,FDF_IN_USE) ); + + if(__check_abort_enabled) + __check_abort(); + + fd = __get_file_descriptor(file_descriptor); + if(fd == NULL) + { + errno = EBADF; + goto out; + } + + SHOWMSG("calling the hook"); + + message.action = file_hook_action_is_interactive; + + assert( fd->fd_Hook != NULL ); + + CallHookPkt(fd->fd_Hook,fd,&message); + + result = message.result; + errno = message.error; + + out: + + RETURN(result); + return(result); +} diff --git a/library/unistd_lchown.c b/library/unistd_lchown.c new file mode 100644 index 0000000..d2f8085 --- /dev/null +++ b/library/unistd_lchown.c @@ -0,0 +1,84 @@ +/* + * $Id: unistd_lchown.c,v 1.1.1.1 2004-07-26 16:32:29 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +lchown(const char * path_name, uid_t owner, gid_t group) +{ + int result = -1; + + ENTER(); + + SHOWSTRING(path_name); + SHOWVALUE(owner); + SHOWVALUE(group); + + assert( path_name != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL) + { + SHOWMSG("invalid path name"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + result = chown(path_name,owner,group); + + out: + + RETURN(result); + return(result); +} diff --git a/library/unistd_link.c b/library/unistd_link.c new file mode 100644 index 0000000..7f980e9 --- /dev/null +++ b/library/unistd_link.c @@ -0,0 +1,140 @@ +/* + * $Id: unistd_link.c,v 1.1.1.1 2004-07-26 16:32:29 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +link(const char * existing_path,const char * new_path) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info existing_path_name_nti; + struct name_translation_info new_path_name_nti; + #endif /* UNIX_PATH_SEMANTICS */ + BPTR existing_path_lock = ZERO; + int result = -1; + LONG status; + + ENTER(); + + SHOWSTRING(existing_path); + SHOWSTRING(new_path); + + assert( existing_path != NULL && new_path != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(existing_path == NULL || new_path == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&existing_path,&existing_path_name_nti) != 0) + goto out; + + if(__translate_unix_to_amiga_path_name(&new_path,&new_path_name_nti) != 0) + goto out; + + if(existing_path_name_nti.is_root || new_path_name_nti.is_root) + { + errno = EACCES; + goto out; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + D(("trying to get a lock on '%s'",existing_path)); + + PROFILE_OFF(); + existing_path_lock = Lock((STRPTR)existing_path,SHARED_LOCK); + PROFILE_ON(); + + if(existing_path_lock == ZERO) + { + SHOWMSG("that didn't work"); + + __translate_access_io_error_to_errno(IoErr(),&errno); + goto out; + } + + D(("trying to make a link named '%s'",new_path)); + + PROFILE_OFF(); + status = MakeLink((STRPTR)new_path,existing_path_lock,LINK_HARD); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("that didn't work"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + result = 0; + + out: + + PROFILE_OFF(); + UnLock(existing_path_lock); + PROFILE_ON(); + + RETURN(result); + return(result); +} diff --git a/library/unistd_readlink.c b/library/unistd_readlink.c new file mode 100644 index 0000000..a2c55c3 --- /dev/null +++ b/library/unistd_readlink.c @@ -0,0 +1,180 @@ +/* + * $Id: unistd_readlink.c,v 1.1.1.1 2004-07-26 16:32:29 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +readlink(const char * path_name, char * buffer, int buffer_size) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info path_name_nti; + struct name_translation_info buffer_nti; + #endif /* UNIX_PATH_SEMANTICS */ + struct DevProc * dvp = NULL; + BPTR lock = ZERO; + int result = -1; + + ENTER(); + + SHOWSTRING(path_name); + SHOWPOINTER(buffer); + SHOWVALUE(buffer_size); + + assert( path_name != NULL && buffer != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL || buffer == NULL) + { + SHOWSTRING("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics && __translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + } + #endif /* UNIX_PATH_SEMANTICS */ + + D(("trying to get a lock on '%s'",path_name)); + + PROFILE_OFF(); + lock = Lock((STRPTR)path_name,SHARED_LOCK); + PROFILE_ON(); + + if(lock != ZERO) + { + LONG status; + + SHOWMSG("trying to obtain the absolute path"); + + PROFILE_OFF(); + status = NameFromLock(lock,buffer,buffer_size); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("that didn't work"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + } + else + { + LONG read_link_result; + + PROFILE_OFF(); + dvp = GetDeviceProc((STRPTR)path_name,NULL); + PROFILE_ON(); + + if(dvp == NULL) + { + SHOWMSG("didn't get deviceproc"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + PROFILE_OFF(); + read_link_result = ReadLink(dvp->dvp_Port,dvp->dvp_Lock,(STRPTR)path_name,buffer,(ULONG)buffer_size); + PROFILE_ON(); + + if(read_link_result == -1) + { + SHOWMSG("couldn't read the link"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + else if (read_link_result == -2) + { + SHOWMSG("buffer was too short"); + + errno = ENOBUFS; + goto out; + } + } + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_amiga_to_unix_path_name((char const **)&buffer,&buffer_nti) != 0) + goto out; + + __restore_path_name((char const **)&buffer,&buffer_nti); + + strcpy(buffer,buffer_nti.substitute); + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + result = strlen(buffer); + + SHOWSTRING(buffer); + + out: + + PROFILE_OFF(); + + FreeDeviceProc(dvp); + UnLock(lock); + + PROFILE_ON(); + + RETURN(result); + return(result); +} diff --git a/library/unistd_realpath.c b/library/unistd_realpath.c new file mode 100644 index 0000000..704cc9f --- /dev/null +++ b/library/unistd_realpath.c @@ -0,0 +1,151 @@ +/* + * $Id: unistd_realpath.c,v 1.1.1.1 2004-07-26 16:32:29 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +char * +realpath(const char * path_name, char * buffer) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info path_name_nti; + struct name_translation_info buffer_nti; + #endif /* UNIX_PATH_SEMANTICS */ + struct DevProc * dvp = NULL; + BPTR lock = ZERO; + char *result = NULL; + + ENTER(); + + SHOWSTRING(path_name); + SHOWPOINTER(buffer); + + assert( path_name != NULL && buffer != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL || buffer == NULL) + { + SHOWSTRING("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics && __translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + } + #endif /* UNIX_PATH_SEMANTICS */ + + D(("trying to get a lock on '%s'",path_name)); + + PROFILE_OFF(); + lock = Lock((STRPTR)path_name,SHARED_LOCK); + PROFILE_ON(); + + if(lock != ZERO) + { + LONG status; + + SHOWMSG("trying to obtain the absolute path"); + + PROFILE_OFF(); + status = NameFromLock(lock,buffer,PATH_MAX); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("that didn't work"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + } + else + { + SHOWMSG("couldn't get a lock"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_amiga_to_unix_path_name((char const **)&buffer,&buffer_nti) != 0) + goto out; + + __restore_path_name((char const **)&buffer,&buffer_nti); + + strcpy(buffer,buffer_nti.substitute); + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + result = buffer; + + SHOWSTRING(buffer); + + out: + + PROFILE_OFF(); + + FreeDeviceProc(dvp); + UnLock(lock); + + PROFILE_ON(); + + RETURN(result); + return(result); +} diff --git a/library/unistd_restorepathname.c b/library/unistd_restorepathname.c new file mode 100644 index 0000000..99f1ffd --- /dev/null +++ b/library/unistd_restorepathname.c @@ -0,0 +1,47 @@ +/* + * $Id: unistd_restorepathname.c,v 1.1.1.1 2004-07-26 16:32:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +void +__restore_path_name(char const ** name_ptr,struct name_translation_info * nti) +{ + assert( name_ptr != NULL && (*name_ptr) != NULL && nti != NULL ); + + /* Reset the name pointer to its previous position. */ + (*name_ptr) = nti->original_name; +} diff --git a/library/unistd_setcurrentpath.c b/library/unistd_setcurrentpath.c new file mode 100644 index 0000000..83aefb5 --- /dev/null +++ b/library/unistd_setcurrentpath.c @@ -0,0 +1,71 @@ +/* + * $Id: unistd_setcurrentpath.c,v 1.1.1.1 2004-07-26 16:32:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +int +__set_current_path(const char * path_name) +{ + int result = -1; + + SHOWSTRING(path_name); + + ENTER(); + + assert( path_name != NULL ); + + if(strlen(path_name)+1 > sizeof(__current_path_name)) + { + SHOWMSG("path is too long"); + + errno = ENAMETOOLONG; + goto out; + } + + /* Only store the path if it's absolute. */ + if(path_name[0] == '/') + strcpy(__current_path_name,path_name); + else + strcpy(__current_path_name,""); + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/unistd_sleep.c b/library/unistd_sleep.c new file mode 100644 index 0000000..7166df9 --- /dev/null +++ b/library/unistd_sleep.c @@ -0,0 +1,176 @@ +/* + * $Id: unistd_sleep.c,v 1.1.1.1 2004-07-26 16:32:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +unsigned int +sleep(unsigned int seconds) +{ + static BOOL sleeping; + unsigned int result = 0; + + ENTER(); + + SHOWVALUE(seconds); + + if(__check_abort_enabled) + __check_abort(); + + if(seconds > 0) + { + if(NOT sleeping) + { + BOOL timer_open; + + sleeping = TRUE; + + if(__timer_request == NULL) + { + timer_open = FALSE; + + SHOWMSG("trying to open the timer"); + + PROFILE_OFF(); + + __timer_port = CreateMsgPort(); + if(__timer_port != NULL) + { + __timer_request = (struct timerequest *)CreateIORequest(__timer_port,sizeof(*__timer_request)); + if(__timer_request != NULL) + { + if(OpenDevice(TIMERNAME,UNIT_VBLANK,(struct IORequest *)__timer_request,0) == 0) + timer_open = TRUE; + } + } + + if(NOT timer_open) + { + SHOWMSG("that didn't work"); + + DeleteIORequest((struct IORequest *)__timer_request); + __timer_request = NULL; + + DeleteMsgPort(__timer_port); + __timer_port = NULL; + } + + PROFILE_ON(); + } + else + { + timer_open = TRUE; + } + + if(timer_open) + { + ULONG signals_to_wait_for; + ULONG seconds_then; + ULONG timer_signal; + struct DateStamp ds; + ULONG signals; + + __timer_request->tr_node.io_Command = TR_ADDREQUEST; + __timer_request->tr_time.tv_secs = seconds; + __timer_request->tr_time.tv_micro = 0; + + timer_signal = (1UL << __timer_port->mp_SigBit); + + signals_to_wait_for = timer_signal; + + SetSignal(0,signals_to_wait_for); + + if(__check_abort_enabled) + SET_FLAG(signals_to_wait_for,SIGBREAKF_CTRL_C); + + PROFILE_OFF(); + DateStamp(&ds); + PROFILE_ON(); + + seconds_then = (ds.ds_Days * 24 * 60 + ds.ds_Minute) * 60 + ds.ds_Tick / TICKS_PER_SECOND; + + SendIO((struct IORequest *)__timer_request); + + while(TRUE) + { + PROFILE_OFF(); + signals = Wait(signals_to_wait_for); + PROFILE_ON(); + + if(FLAG_IS_SET(signals,SIGBREAKF_CTRL_C)) + { + ULONG seconds_now; + + if(CheckIO((struct IORequest *)__timer_request)) + AbortIO((struct IORequest *)__timer_request); + + WaitIO((struct IORequest *)__timer_request); + + SetSignal(SIGBREAKF_CTRL_C,SIGBREAKF_CTRL_C); + __check_abort(); + + PROFILE_OFF(); + DateStamp(&ds); + PROFILE_ON(); + + seconds_now = (ds.ds_Days * 24 * 60 + ds.ds_Minute) * 60 + ds.ds_Tick / TICKS_PER_SECOND; + + seconds_now -= seconds_then; + if(seconds_now < seconds) + result = (seconds - seconds_now); + + break; + } + + if(FLAG_IS_SET(signals,timer_signal)) + { + WaitIO((struct IORequest *)__timer_request); + break; + } + } + } + + sleeping = FALSE; + } + } + + RETURN(result); + return(result); +} diff --git a/library/unistd_strip_double_slash.c b/library/unistd_strip_double_slash.c new file mode 100644 index 0000000..6ed0069 --- /dev/null +++ b/library/unistd_strip_double_slash.c @@ -0,0 +1,87 @@ +/* + * $Id: unistd_strip_double_slash.c,v 1.1.1.1 2004-07-26 16:32:30 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* Remove '//' from an AmigaDOS path name. For example, "volume:one/two//three" + is equivalent to "volume:one/three" and the following function removes the + redundant part of the path. */ +void +__strip_double_slash(char * file_name,int len) +{ + int start,delta,position,i; + + assert( file_name != NULL && len > 0 ); + + position = len; + + while(len > 1) + { + position--; + if((position == 0) || (file_name[position] == ':') || (file_name[position - 1] == ':')) + break; + + if((position > 1) && (file_name[position] == '/') && (file_name[position - 1] == '/') && (file_name[position - 2] != ':') && (file_name[position - 2] != '/')) + { + start = position; + + position -= 2; + + while((position > 0) && (file_name[position] != ':') && (file_name[position] != '/')) + position--; + + if((file_name[position] == ':') || (file_name[position] == '/')) + position++; + + i = position; + delta = start - position + 1; + + len -= delta; + + while(i < len) + { + file_name[i] = file_name[i + delta]; + + i++; + } + + file_name[len] = '\0'; + + position = len; + } + } +} diff --git a/library/unistd_symlink.c b/library/unistd_symlink.c new file mode 100644 index 0000000..88efb64 --- /dev/null +++ b/library/unistd_symlink.c @@ -0,0 +1,101 @@ +/* + * $Id: unistd_symlink.c,v 1.1.1.1 2004-07-26 16:32:31 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +/* ZZZ symbolic_path must be interpreted relative to the current (!) + * directory here. + */ +int +symlink(const char * actual_path, const char * symbolic_path) +{ + int result = -1; + LONG status; + + ENTER(); + + SHOWSTRING(actual_path); + SHOWSTRING(symbolic_path); + + assert( actual_path != NULL && symbolic_path != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(actual_path == NULL || symbolic_path == NULL) + { + SHOWMSG("invalid parameters"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + SHOWMSG("trying to make that link"); + + PROFILE_OFF(); + status = MakeLink((STRPTR)symbolic_path,(LONG)actual_path,LINK_SOFT); + PROFILE_ON(); + + if(status == DOSFALSE) + { + SHOWMSG("that didn't work"); + + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + result = 0; + + out: + + RETURN(result); + return(result); +} diff --git a/library/unistd_translatea2u.c b/library/unistd_translatea2u.c new file mode 100644 index 0000000..dacc797 --- /dev/null +++ b/library/unistd_translatea2u.c @@ -0,0 +1,284 @@ +/* + * $Id: unistd_translatea2u.c,v 1.1.1.1 2004-07-26 16:32:31 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +int +__translate_amiga_to_unix_path_name(char const ** name_ptr,struct name_translation_info * nti) +{ + const int max_unix_len = sizeof(nti->substitute)-1; + char local_replacement[sizeof(nti->substitute)]; + BOOL have_double_slash; + int len,replace_len; + int result = -1; + int i; + char * replace; + char * name; + + assert( name_ptr != NULL && (*name_ptr) != NULL && nti != NULL ); + + replace = nti->substitute; + + name = (char *)(*name_ptr); + + len = strlen(name); + if(len >= (int)sizeof(nti->substitute)) + { + D(("path name '%s' is too long (%ld characters total; maximum is %ld)!",name,len,sizeof(nti->substitute)-1)); + + errno = ENAMETOOLONG; + goto out; + } + + /* Check if the name would become too long to handle. */ + + /* Reduce any '//' embedded in the name if possible. */ + have_double_slash = FALSE; + + for(i = 0 ; i < len-1 ; i++) + { + if(name[i] == '/' && name[i+1] == '/') + { + have_double_slash = TRUE; + break; + } + } + + if(have_double_slash) + { + /* We will need to make a copy of the name. Make sure that it fits. */ + if(len > max_unix_len) + { + errno = ENAMETOOLONG; + goto out; + } + + strcpy(local_replacement,name); + name = local_replacement; + + __strip_double_slash(name,len); + + len = strlen(name); + } + + /* The empty string corresponds to the current + * directory, which is the ".". + */ + if(len == 0) + { + strcpy(replace,"."); + } + else + { + char * volume_name; + int volume_name_len; + + /* Figure out if the path includes a volume, device or assignment name. + If so, strip it from the path, to be translated and added later. */ + volume_name = NULL; + volume_name_len = 0; + + for(i = 0 ; i < len ; i++) + { + if(name[i] == ':') + { + volume_name = name; + volume_name_len = i; + + name += volume_name_len+1; + len -= volume_name_len+1; + + break; + } + } + + /* Replace all "/" characters in the name which don't just act as + * separators with "..". Otherwise, copy the name string to the + * replacement buffer. + */ + replace_len = 0; + + while(name[0] == '/') + { + if(replace_len + 3 > max_unix_len) + { + errno = ENAMETOOLONG; + goto out; + } + + memmove(&replace[replace_len],"../",3); + replace_len += 3; + + name++; + len--; + + if(len == 0) + { + /* Strip the trailing '/'. */ + replace[--replace_len] = '\0'; + } + } + + for(i = 0 ; i < len ; i++) + { + if(name[i] == '/' && (name[i+1] == '/' || name[i+1] == '\0')) + { + if(replace_len + 3 > max_unix_len) + { + errno = ENAMETOOLONG; + goto out; + } + + memmove(&replace[replace_len],"/..",3); + replace_len += 3; + } + else + { + if(replace_len + 1 > max_unix_len) + { + errno = ENAMETOOLONG; + goto out; + } + + replace[replace_len++] = name[i]; + } + } + + assert( replace_len <= max_unix_len ); + + replace[replace_len] = '\0'; + + /* If necessary, add and translate the volume name found above. */ + if(volume_name != NULL) + { + /* Check if the complete path will fit. This assumes the worst + case scenario. */ + if(1 + volume_name_len + 1 + replace_len > max_unix_len) + { + errno = ENAMETOOLONG; + goto out; + } + + if(volume_name_len > 0) + { + if(replace_len > 0) + { + /* Add the volume name in front of the path. */ + memmove(&replace[1 + volume_name_len + 1],replace,(size_t)(replace_len+1)); + replace[0] = replace[1 + volume_name_len] = '/'; + memmove(&replace[1],volume_name,(size_t)volume_name_len); + } + else + { + /* There is only the volume name. */ + replace[0] = '/'; + memmove(&replace[1],volume_name,(size_t)volume_name_len); + replace[volume_name_len + 1] = '\0'; + } + } + else + { + int path_prefix_len = 0; + + /* We need to expand ':'. If the current directory name is + known and refers to an absolute path, we borrow the + absolute path name component. */ + if(__current_path_name[0] != '\0') + { + int path_name_len; + + path_name_len = strlen(__current_path_name); + + /* Figure out where the absolute path name portion ends. */ + for(i = 1 ; i <= path_name_len ; i++) + { + if(__current_path_name[i] == '/' || + __current_path_name[i] == '\0') + { + path_prefix_len = i; + break; + } + } + + /* If we found the absolute path name portion, use it. */ + if(path_prefix_len > 0) + { + if(path_prefix_len + 1 + replace_len > max_unix_len) + { + errno = ENAMETOOLONG; + goto out; + } + + if(replace_len > 0) + { + memmove(&replace[path_prefix_len + 1],replace,(size_t)(replace_len+1)); + memmove(replace,__current_path_name,(size_t)path_prefix_len); + replace[path_prefix_len] = '/'; + } + else + { + memmove(replace,__current_path_name,(size_t)path_prefix_len); + replace[path_prefix_len] = '\0'; + } + } + } + + if(path_prefix_len == 0) + { + /* The ':foo' path gets translated into '/foo'. */ + memmove(&replace[1],replace,(size_t)(replace_len+1)); + replace[0] = '/'; + } + } + } + } + + name = replace; + + assert( strlen(name) < (size_t)max_unix_len ); + + nti->original_name = (char *)(*name_ptr); + (*name_ptr) = name; + + D(("translated '%s' to '%s'",nti->original_name,name)); + + result = 0; + + out: + + return(result); +} diff --git a/library/unistd_translaterel.c b/library/unistd_translaterel.c new file mode 100644 index 0000000..73e9738 --- /dev/null +++ b/library/unistd_translaterel.c @@ -0,0 +1,103 @@ +/* + * $Id: unistd_translaterel.c,v 1.1.1.1 2004-07-26 16:32:31 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +int +__translate_relative_path_name(char const ** name_ptr,char *replacement_buffer,size_t replacement_buffer_size) +{ + int result = -1; + char * name; + + assert( name_ptr != NULL && (*name_ptr) != NULL && replacement_buffer != NULL ); + + /* If we have a current directory which all references should + * be made relative to, do just that. Absolute paths + * are not modified, though. + */ + name = (char *)(*name_ptr); + if(__current_path_name[0] != '\0' && name[0] != '/') + { + size_t total_len; + BOOL add_slash; + + /* Get the current directory name and get + * ready to attach the file name at the end. + */ + total_len = strlen(__current_path_name); + + if(__current_path_name[total_len-1] != '/' && + __current_path_name[total_len-1] != ':' && + name[0] != '\0') + { + add_slash = TRUE; + + total_len++; + } + else + { + add_slash = FALSE; + } + + total_len += strlen(name); + + /* Check if the complete string will fit, including the terminating NUL byte. */ + if(total_len+1 > replacement_buffer_size) + { + errno = ENAMETOOLONG; + goto out; + } + + /* Put the file name together. */ + strcpy(replacement_buffer,__current_path_name); + + if(add_slash) + strcat(replacement_buffer,"/"); + + strcat(replacement_buffer,name); + + assert( strlen(replacement_buffer) < replacement_buffer_size ); + + (*name_ptr) = replacement_buffer; + } + + result = 0; + + out: + + return(result); +} diff --git a/library/unistd_translateu2a.c b/library/unistd_translateu2a.c new file mode 100644 index 0000000..be06681 --- /dev/null +++ b/library/unistd_translateu2a.c @@ -0,0 +1,504 @@ +/* + * $Id: unistd_translateu2a.c,v 1.1.1.1 2004-07-26 16:32:32 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*#define DEBUG*/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +int +__translate_unix_to_amiga_path_name(char const ** name_ptr,struct name_translation_info * nti) +{ + char volume_name[sizeof(nti->substitute)]; + int volume_name_len; + BOOL have_double_slash; + BOOL have_slash_dot_slash; + BOOL have_slash_dot_dot_slash; + int result = -1; + char * replace; + char * name; + int len,i,j; + + /*PUSHDEBUGLEVEL(2);*/ + + assert( name_ptr != NULL && (*name_ptr) != NULL && nti != NULL ); + + name = (char *)(*name_ptr); + replace = nti->substitute; + + nti->is_root = FALSE; + + /* Check if the name would become too long to handle. */ + len = strlen(name); + if(len >= (int)sizeof(nti->substitute)) + { + D(("path name '%s' is too long (%ld characters total; maximum is %ld)!",name,len,sizeof(nti->substitute)-1)); + + errno = ENAMETOOLONG; + goto out; + } + + /* Prepend an absolute path to the name, if such a path was previously set + as the current directory. */ + if(__translate_relative_path_name((const char **)&name,nti->substitute,sizeof(nti->substitute)) != 0) + { + SHOWMSG("relative path name could not be worked into the pattern"); + goto out; + } + + D(("initial name = '%s'",name)); + + len = strlen(name); + + /* If there is one, strip the trailing slash ('foo/' -> 'foo'). */ + if(len > 1 && name[len-1] == '/') + { + if(name != replace) + { + memmove(replace,name,(size_t)len-1); + name = replace; + } + + len--; + + name[len] = '\0'; + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + + /* If there are neighboring slashes, strip all but one + ('foo//bar' -> 'foo/bar'). The "//" pattern in a Unix + file name is apparently harmless, but on AmigaDOS it + has a very definite meaning. */ + have_double_slash = FALSE; + + for(i = 0 ; i < len-1 ; i++) + { + if(name[i] == '/' && name[i+1] == '/') + { + have_double_slash = TRUE; + break; + } + } + + if(have_double_slash) + { + BOOL have_slash; + char * from; + char * to; + char c; + + have_slash = FALSE; + from = name; + to = replace; + + while((c = (*from++)) != '\0') + { + if(c == '/') + { + if(NOT have_slash) + (*to++) = c; + + have_slash = TRUE; + } + else + { + (*to++) = c; + + have_slash = FALSE; + } + } + + (*to) = '\0'; + + name = replace; + + len = strlen(name); + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + + /* Ditch all leading './' ('./foo' -> 'foo'). */ + if(name[0] == '.' && name[1] == '/') + { + do + { + name += 2; + len -= 2; + } + while(name[0] == '.' && name[1] == '/'); + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + + /* Ditch all embedded '/./' ('foo/./bar' -> 'foo/bar'). */ + have_slash_dot_slash = FALSE; + + for(i = j = 0 ; i < len - 2 ; i++) + { + if(name[i] == '/' && name[i+1] == '.' && name[i+2] == '/') + { + have_slash_dot_slash = TRUE; + break; + } + } + + if(have_slash_dot_slash) + { + for(i = j = 0 ; i < len ; i++) + { + replace[j++] = name[i]; + + if(name[i] == '/' && name[i+1] == '.' && name[i+2] == '/') + i += 2; + } + + len = j; + + name = replace; + + name[len] = '\0'; + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + + /* Special case: the path name may end with "/." signifying that the + directory itself is requested ('foo/.' -> 'foo'). */ + if(len >= 2 && strncmp(&name[len-2],"/.",2) == SAME) + { + /* If it's just '/.' then it's really '/'. */ + if(len == 2) + { + name = "/"; + len = 1; + } + else + { + if(name != replace) + { + memmove(replace,name,(size_t)(len - 2)); + name = replace; + } + + len -= 2; + + name[len] = '\0'; + } + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + + /* Check for absolute path. */ + if(name[0] == '/') + { + if(name[1] == '\0') + { + SHOWMSG("this is the root directory"); + + nti->is_root = TRUE; + } + + /* Ok, so this is an absolute path. We first + check for a few special cases, the first + being a reference to "/tmp". */ + if((strncmp(name,"/tmp",4) == SAME) && (name[4] == '/' || name[4] == '\0')) + { + if(name[4] == '/') + { + /* Convert "/tmp/foo" to "T:foo". */ + memmove(&replace[2],&name[5],strlen(&name[5])+1); + memmove(replace,"T:",2); + } + else + { + /* Convert "/tmp" to "T:". */ + strcpy(replace,"T:"); + } + + name = replace; + + len = strlen(name); + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + else if (strcmp(name,"/dev/null") == SAME) + { + name = "NIL:"; + + len = strlen(name); + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + else + { + int path_name_start = 0; + + volume_name_len = 0; + + /* Find out how long the first component + of the absolute path is. */ + len = strlen(name); + for(i = 1 ; i <= len ; i++) + { + if(name[i] == '/' || name[i] == '\0') + { + volume_name_len = i-1; + + /* Is there anything following + * the path name? + */ + if(name[i] == '/') + path_name_start = i+1; + + break; + } + } + + /* Copy the first component and attach a colon. "/foo" becomes + "foo:" (without the trailing NUL byte, this will get attached + later). */ + memmove(replace,&name[1],(size_t)volume_name_len); + replace[volume_name_len++] = ':'; + + /* Now add the finishing touches. "/foo/bar" finally + becomes "foo:bar" and "/foo" becomes "foo:" with the + trailing NUL byte attached. */ + if(path_name_start > 0) + memmove(&replace[volume_name_len],&name[path_name_start],strlen(&name[path_name_start])+1); + else + replace[volume_name_len] = '\0'; + + name = replace; + + len = strlen(name); + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + } + + /* Extract and remove the volume name from the path. We + are going to need it later. */ + volume_name_len = 0; + + for(i = 0 ; i < len ; i++) + { + if(name[i] == ':') + { + /* Look for extra colon characters embedded in the name + (as in "foo/bar:baz") which really don't belong here. */ + for(j = 0 ; j < i ; j++) + { + if(name[j] == '/') + { + D(("name '%s' still contains colon characters",name)); + + errno = EINVAL; /* invalid name */ + goto out; + } + } + + volume_name_len = i+1; + + memmove(volume_name,name,(size_t)volume_name_len); + volume_name[volume_name_len] = '\0'; + + name += volume_name_len; + len -= volume_name_len; + + D(("name = '%s' (line %ld)",name,__LINE__)); + + break; + } + } + + /* Look for extra colon characters embedded in the name + (as in "foo:bar:baz") which really don't belong here. */ + for(i = 0 ; i < len ; i++) + { + if(name[i] == ':') + { + D(("name '%s' still contains colon characters",name)); + + errno = EINVAL; /* invalid name */ + goto out; + } + } + + /* Now parse the path name and replace all embedded '..' with + the AmigaDOS counterparts ('foo/../bar' -> 'foo//bar'). */ + have_slash_dot_dot_slash = FALSE; + + for(i = j = 0 ; i < len - 3 ; i++) + { + if(name[i] == '/' && name[i+1] == '.' && name[i+2] == '.' && name[i+3] == '/') + { + have_slash_dot_dot_slash = TRUE; + break; + } + } + + if(have_slash_dot_dot_slash) + { + for(i = j = 0 ; i < len ; i++) + { + replace[j++] = name[i]; + + if(name[i] == '/' && name[i+1] == '.' && name[i+2] == '.' && name[i+3] == '/') + { + replace[j++] = '/'; + i += 3; + } + } + + len = j; + + name = replace; + + name[len] = '\0'; + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + + /* Translate a trailing '/..' to '//' */ + if(len >= 3 && strncmp(&name[len-3],"/..",3) == SAME) + { + if(name != replace) + { + memmove(replace,name,(size_t)(len - 2)); + name = replace; + } + + len -= 2; + + name[len++] = '/'; + + name[len] = '\0'; + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + + /* Translate a leading '../' ('../foo' -> '/foo') */ + if(len >= 3 && strncmp(name,"../",3) == SAME) + { + memmove(replace,&name[2],(size_t)(len - 2)); + name = replace; + + len -= 2; + + name[len] = '\0'; + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + + /* Translate the '..' ('..' -> '/') */ + if(strcmp(name,"..") == SAME) + { + name = "/"; + len = 1; + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + + /* Translate the '.' ('.' -> '') */ + if(strcmp(name,".") == SAME) + { + name = ""; + len = 0; + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + + /* Now put it all together again. */ + if(volume_name_len > 0) + { + memmove(&replace[volume_name_len],name,(size_t)len); + memmove(replace,volume_name,(size_t)volume_name_len); + + len += volume_name_len; + + name = replace; + + name[len] = '\0'; + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + + /* Reduce any "//" embedded in the name, if necessary. */ + have_double_slash = FALSE; + + for(i = 0 ; i < len-1 ; i++) + { + if(name[i] == '/' && name[i+1] == '/') + { + have_double_slash = TRUE; + break; + } + } + + if(have_double_slash) + { + if(name != replace) + { + strcpy(replace,name); + name = replace; + } + + __strip_double_slash(name,len); + + D(("name = '%s' (line %ld)",name,__LINE__)); + } + + /* The following is somewhat controversial. It assumes that what comes out + as a path name that ends with ":/" should translate into the root + directory. This would not be the case for the names of assignments, + though, for which the "/" suffix would actually do something useful. */ + len = strlen(name); /* ZZZ this should not be necessary! */ + if(len >= 2 && strncmp(&name[len-2],":/",2) == 0) + nti->is_root = TRUE; + + nti->original_name = (char *)(*name_ptr); + (*name_ptr) = name; + + D(("translated '%s' to '%s'",nti->original_name,name)); + + result = 0; + +out: + + /*POPDEBUGLEVEL();*/ + + return(result); +} diff --git a/library/unistd_truncate.c b/library/unistd_truncate.c new file mode 100644 index 0000000..6c15a84 --- /dev/null +++ b/library/unistd_truncate.c @@ -0,0 +1,101 @@ +/* + * $Id: unistd_truncate.c,v 1.1.1.1 2004-07-26 16:32:32 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +truncate(const char * path_name, off_t length) +{ + int result = -1; + int fd; + + ENTER(); + + SHOWSTRING(path_name); + SHOWVALUE(length); + + assert( path_name != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL) + { + SHOWMSG("invalid path name"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + if(length < 0) + { + SHOWMSG("invalid length"); + + errno = EINVAL; + goto out; + } + + fd = open(path_name,O_WRONLY); + if(fd < 0) + { + SHOWMSG("file didn't open"); + goto out; + } + + result = ftruncate(fd,length); + + close(fd); + + out: + + RETURN(result); + return(result); +} diff --git a/library/unistd_unix_path_semantics.c b/library/unistd_unix_path_semantics.c new file mode 100644 index 0000000..953ec61 --- /dev/null +++ b/library/unistd_unix_path_semantics.c @@ -0,0 +1,40 @@ +/* + * $Id: unistd_unix_path_semantics.c,v 1.1.1.1 2004-07-26 16:32:32 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +BOOL __unix_path_semantics = TRUE; diff --git a/library/unistd_unlink.c b/library/unistd_unlink.c new file mode 100644 index 0000000..99b1218 --- /dev/null +++ b/library/unistd_unlink.c @@ -0,0 +1,191 @@ +/* + * $Id: unistd_unlink.c,v 1.1.1.1 2004-07-26 16:32:33 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _UNISTD_HEADERS_H +#include "unistd_headers.h" +#endif /* _UNISTD_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +unlink(const char * path_name) +{ + #if defined(UNIX_PATH_SEMANTICS) + DECLARE_UTILITYBASE(); + struct name_translation_info path_name_nti; + #endif /* UNIX_PATH_SEMANTICS */ + BPTR current_dir = ZERO; + int result = -1; + LONG status; + + ENTER(); + + SHOWSTRING(path_name); + + assert( path_name != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL) + { + SHOWMSG("invalid path name"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + + if(path_name_nti.is_root) + { + errno = EACCES; + goto out; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + D(("trying to delete '%s'",path_name)); + + PROFILE_OFF(); + status = DeleteFile((STRPTR)path_name); + PROFILE_ON(); + + if(status == DOSFALSE) + { + #if defined(UNIX_PATH_SEMANTICS) + { + struct UnlinkNode * node; + struct UnlinkNode * uln; + BOOL found = FALSE; + + assert( UtilityBase != NULL ); + + if(IoErr() != ERROR_OBJECT_IN_USE) + { + __translate_access_io_error_to_errno(IoErr(),&errno); + goto out; + } + + SHOWMSG("will try to delete that file later"); + + /* ZZZ we should be locking the path's parent directory + and then just remember what the last part of the path + pointed to. */ + PROFILE_OFF(); + current_dir = Lock("",SHARED_LOCK); + PROFILE_ON(); + + if(current_dir == ZERO) + { + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + PROFILE_OFF(); + + assert( __unlink_list.mlh_Head != NULL ); + + for(node = (struct UnlinkNode *)__unlink_list.mlh_Head ; + node->uln_MinNode.mln_Succ != NULL ; + node = (struct UnlinkNode *)node->uln_MinNode.mln_Succ) + { + if(Stricmp(node->uln_Name,path_name) == SAME && SameLock(node->uln_Lock,current_dir) == LOCK_SAME) + { + found = TRUE; + break; + } + } + + PROFILE_ON(); + + if(NOT found) + { + uln = malloc(sizeof(*uln) + strlen(path_name) + 1); + if(uln == NULL) + goto out; + + uln->uln_Lock = current_dir; + uln->uln_Name = (char *)(uln + 1); + + strcpy(uln->uln_Name,path_name); + AddTail((struct List *)&__unlink_list,(struct Node *)uln); + + current_dir = ZERO; + } + } + #else + { + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + #endif /* UNIX_PATH_SEMANTICS */ + } + + result = 0; + + out: + + PROFILE_OFF(); + UnLock(current_dir); + PROFILE_ON(); + + RETURN(result); + return(result); +} diff --git a/library/unistd_wildcard_expand.c b/library/unistd_wildcard_expand.c new file mode 100644 index 0000000..c7a8907 --- /dev/null +++ b/library/unistd_wildcard_expand.c @@ -0,0 +1,381 @@ +/* + * $Id: unistd_wildcard_expand.c,v 1.1.1.1 2004-07-26 16:32:33 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_MEM_DEBUG_H +#include "stdlib_mem_debug.h" +#endif /* _STDLIB_MEM_DEBUG_H */ + +/****************************************************************************/ + +#ifndef _STDLIB_HEADERS_H +#include "stdlib_headers.h" +#endif /* _STDLIB_HEADERS_H */ + +/****************************************************************************/ + +#include "stdlib_protos.h" + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +UBYTE * +__allocate_quote_vector(int num_parameters) +{ + UBYTE * vector; + size_t num_bytes; + + assert( num_parameters > 0 ); + + num_bytes = (num_parameters + 7) / 8; + + vector = malloc(num_bytes); + if(vector != NULL) + memset(vector,0,num_bytes); + + return(vector); +} + +/****************************************************************************/ + +static struct AnchorPath * anchor; + +/****************************************************************************/ + +void +__wildcard_expand_exit(void) +{ + if(anchor != NULL) + { + MatchEnd(anchor); + + free(anchor); + anchor = NULL; + } +} + +/****************************************************************************/ + +struct name_node +{ + struct MinNode nn_min_node; + char * nn_name; + BOOL nn_wild; +}; + +/****************************************************************************/ + +static int +compare(const char **a,const char **b) +{ + DECLARE_UTILITYBASE(); + + assert( UtilityBase != NULL ); + + return(Stricmp((STRPTR)*a,(STRPTR)*b)); +} + +/****************************************************************************/ + +int +__wildcard_expand_init(void) +{ + struct AnchorPath * ap = NULL; + struct MinList argument_list; + size_t argument_list_size; + BOOL found_pattern = FALSE; + BOOL match_made; + struct name_node * node; + int argc; + char ** argv; + int error; + int i; + + PROFILE_OFF(); + + /* No work to be done? */ + if(__quote_vector == NULL || __argc == 0 || __argv == NULL) + { + error = OK; + goto out; + } + + argc = __argc; + argv = __argv; + + /* We need some extra room in this data structure as the buffer + * will be used to check if a string contains a pattern. + */ + ap = malloc(sizeof(*ap) + 2 * MAXPATHLEN); + if(ap == NULL) + { + error = ENOMEM; + goto out; + } + + /* This has to be long-word aligned. */ + assert( (((ULONG)ap) & 3) == 0 ); + + anchor = ap; + + memset(ap,0,sizeof(*ap)); + + /* The argument list will go in here. */ + NewList((struct List *)&argument_list); + argument_list_size = 0; + + for(i = 0 ; i < argc ; i++) + { + match_made = FALSE; + + /* Does this string contain a wildcard pattern? We also check if the + * string is quoted. Quoted strings are never expanded. + */ + if(i > 0 && (__quote_vector[i / 8] & (1 << (7 - (i & 7)))) == 0 && ParsePatternNoCase(argv[i],ap->ap_Buf,2 * MAXPATHLEN) > 0) + { + BOOL is_first = TRUE; + LONG rc; + + memset(ap,0,sizeof(*ap)); + + ap->ap_Strlen = MAXPATHLEN; + + if(__check_abort_enabled) + ap->ap_BreakBits = SIGBREAKF_CTRL_C; + + rc = MatchFirst(argv[i],ap); + + while(TRUE) + { + /* Got a break signal? */ + if(rc == ERROR_BREAK) + { + SetSignal(SIGBREAKF_CTRL_C,SIGBREAKF_CTRL_C); + __check_abort(); + + /* If we ever arrive here, retry the previous match. */ + if(is_first) + { + MatchEnd(ap); + + memset(ap,0,sizeof(*ap)); + + ap->ap_Strlen = MAXPATHLEN; + + if(__check_abort_enabled) + ap->ap_BreakBits = SIGBREAKF_CTRL_C; + + rc = MatchFirst(argv[i],ap); + } + else + { + rc = MatchNext(ap); + } + + continue; + } + else if (rc == ERROR_NO_MORE_ENTRIES) + { + /* End of the line. */ + break; + } + else if (rc != OK) + { + /* Some error occured. */ + error = EIO; + break; + } + + /* Allocate another node for the expanded parameter. */ + node = malloc(sizeof(*node) + strlen(ap->ap_Buf) + 1); + if(node == NULL) + { + error = ENOMEM; + goto out; + } + + /* Remember that this name ended up here due to pattern matching. */ + node->nn_name = (char *)(node + 1); + node->nn_wild = TRUE; + + strcpy(node->nn_name,ap->ap_Buf); + + AddTail((struct List *)&argument_list,(struct Node *)node); + argument_list_size++; + + rc = MatchNext(ap); + + is_first = FALSE; + + /* Remember that we found a wildcard pattern among the arguments. */ + match_made = found_pattern = TRUE; + } + + MatchEnd(ap); + } + + if(NOT match_made) + { + /* Just remember this argument as is. */ + node = malloc(sizeof(*node)); + if(node == NULL) + { + error = ENOMEM; + goto out; + } + + node->nn_name = argv[i]; + node->nn_wild = FALSE; + + AddTail((struct List *)&argument_list,(struct Node *)node); + argument_list_size++; + } + } + + /* If there were wildcard patterns among the command line parameters, + * work them into the argument vector. + */ + if(found_pattern) + { + size_t last_wild,position; + char ** table; + + /* This will hold the new arguments. */ + table = malloc(sizeof(*table) * (argument_list_size + 1)); + if(table == NULL) + { + error = ENOMEM; + goto out; + } + + __argc = argument_list_size; + __argv = table; + + /* Fill in the table, sorting the wildcard matches. */ + last_wild = 0; + + for(node = (struct name_node *)argument_list.mlh_Head, position = 0 ; + node->nn_min_node.mln_Succ != NULL ; + node = (struct name_node *)node->nn_min_node.mln_Succ, position++) + { + if(node->nn_wild) + { + /* Remember where we found the last parameter that was + * added due to pattern matching. + */ + if(last_wild == 0) + last_wild = position; + } + else + { + /* This is not a parameter which was added due to pattern + * matching. But if we added one before, we will want to + * sort all these parameters alphabetically. + */ + if(last_wild != 0) + { + size_t num_elements; + + assert( position > last_wild ); + assert( last_wild < argument_list_size ); + + /* How many parameters would have to be sorted? */ + num_elements = position - last_wild; + if(num_elements > 1) + qsort(&table[last_wild],num_elements,sizeof(*table),(int (*)(const void *,const void *))compare); + + last_wild = 0; + } + } + + assert( position < argument_list_size ); + + table[position] = node->nn_name; + } + + /* If necessary, take care of the last entries in the list. */ + if(last_wild != 0) + { + size_t num_elements; + + assert( position > last_wild ); + assert( last_wild < argument_list_size ); + + /* How many parameters would have to be sorted? */ + num_elements = position - last_wild; + if(num_elements > 1) + qsort(&table[last_wild],num_elements,sizeof(*table),(int (*)(const void *,const void *))compare); + } + + assert( position == argument_list_size ); + + /* This terminates the table. */ + table[position] = NULL; + } + else + { + /* Throw the contents of the list away. There is nothing worth keeping. */ + while((node = (struct name_node *)RemHead((struct List *)&argument_list)) != NULL) + free(node); + } + + error = OK; + + out: + + anchor = NULL; + + if(ap != NULL) + { + MatchEnd(ap); + + free(ap); + } + + if(error != OK) + { + errno = error; + + perror(__argv[0]); + abort(); + } + + free(__quote_vector); + __quote_vector = NULL; + + PROFILE_ON(); + + return(error); +} diff --git a/library/unix.lib_rev.c b/library/unix.lib_rev.c new file mode 100644 index 0000000..c746637 --- /dev/null +++ b/library/unix.lib_rev.c @@ -0,0 +1,38 @@ +/* + * $Id: unix.lib_rev.c,v 1.1.1.1 2004-07-26 16:32:33 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "unix.lib_rev.h" + +/****************************************************************************/ + +char __unix_lib_version[] = VERSTAG; diff --git a/library/unix.lib_rev.h b/library/unix.lib_rev.h new file mode 100644 index 0000000..304c582 --- /dev/null +++ b/library/unix.lib_rev.h @@ -0,0 +1,6 @@ +#define VERSION 1 +#define REVISION 165 +#define DATE "26.7.2004" +#define VERS "unix.lib 1.165" +#define VSTRING "unix.lib 1.165 (26.7.2004)\r\n" +#define VERSTAG "\0$VER: unix.lib 1.165 (26.7.2004)" diff --git a/library/unix.lib_rev.rev b/library/unix.lib_rev.rev new file mode 100644 index 0000000..9e42f3e --- /dev/null +++ b/library/unix.lib_rev.rev @@ -0,0 +1 @@ +165 diff --git a/library/usergroup_crypt.c b/library/usergroup_crypt.c new file mode 100644 index 0000000..287ee0b --- /dev/null +++ b/library/usergroup_crypt.c @@ -0,0 +1,97 @@ +/* + * $Id: usergroup_crypt.c,v 1.1.1.1 2004-07-26 16:32:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +#ifdef crypt +#undef crypt +#endif /* crypt */ + +/****************************************************************************/ + +char * +crypt(const char *key,const char *salt) +{ + char *result = NULL; + + ENTER(); + + SHOWSTRING(key); + SHOWSTRING(salt); + + assert(key != NULL && salt != NULL); + assert(__UserGroupBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(key == NULL || salt == NULL) + { + SHOWMSG("invalid parameters"); + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __crypt((STRPTR)key,(STRPTR)salt); + PROFILE_ON(); + + SHOWSTRING(result); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_data.c b/library/usergroup_data.c new file mode 100644 index 0000000..8b262a7 --- /dev/null +++ b/library/usergroup_data.c @@ -0,0 +1,63 @@ +/* + * $Id: usergroup_data.c,v 1.1.1.1 2004-07-26 16:32:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +struct Library * __UserGroupBase; + +/****************************************************************************/ + +#if defined(__amigaos4__) + +struct UserGroupIFace *__IUserGroup; + +#endif /* __amigaos4__ */ + +/****************************************************************************/ + +int __root_uid; +int __root_gid; +int __root_euid; +int __root_egid; + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_endgrent.c b/library/usergroup_endgrent.c new file mode 100644 index 0000000..e5302ed --- /dev/null +++ b/library/usergroup_endgrent.c @@ -0,0 +1,69 @@ +/* + * $Id: usergroup_endgrent.c,v 1.1.1.1 2004-07-26 16:32:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +#ifdef endgrent +#undef endgrent +#endif /* endgrent */ + +/****************************************************************************/ + +void +endgrent(void) +{ + ENTER(); + + assert(__UserGroupBase != NULL); + + PROFILE_OFF(); + __endgrent(); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + LEAVE(); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_endpwent.c b/library/usergroup_endpwent.c new file mode 100644 index 0000000..0ffff12 --- /dev/null +++ b/library/usergroup_endpwent.c @@ -0,0 +1,69 @@ +/* + * $Id: usergroup_endpwent.c,v 1.1.1.1 2004-07-26 16:32:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +#ifdef endpwent +#undef endpwent +#endif /* endpwent */ + +/****************************************************************************/ + +void +endpwent(void) +{ + ENTER(); + + assert(__UserGroupBase != NULL); + + PROFILE_OFF(); + __endpwent(); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + LEAVE(); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_getegid.c b/library/usergroup_getegid.c new file mode 100644 index 0000000..b958774 --- /dev/null +++ b/library/usergroup_getegid.c @@ -0,0 +1,79 @@ +/* + * $Id: usergroup_getegid.c,v 1.1.1.1 2004-07-26 16:32:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +#ifdef getegid +#undef getegid +#endif /* getegid */ + +/****************************************************************************/ + +gid_t +getegid(void) +{ + gid_t result; + + ENTER(); + + assert(__UserGroupBase != NULL); + + if(__root_mode) + { + result = __root_egid; + } + else + { + PROFILE_OFF(); + result = __getegid(); + PROFILE_ON(); + } + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_geteuid.c b/library/usergroup_geteuid.c new file mode 100644 index 0000000..895c6db --- /dev/null +++ b/library/usergroup_geteuid.c @@ -0,0 +1,79 @@ +/* + * $Id: usergroup_geteuid.c,v 1.1.1.1 2004-07-26 16:32:34 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +#ifdef geteuid +#undef geteuid +#endif /* geteuid */ + +/****************************************************************************/ + +uid_t +geteuid(void) +{ + uid_t result; + + ENTER(); + + assert(__UserGroupBase != NULL); + + if(__root_mode) + { + result = __root_euid; + } + else + { + PROFILE_OFF(); + result = __geteuid(); + PROFILE_ON(); + } + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_getgid.c b/library/usergroup_getgid.c new file mode 100644 index 0000000..b86e0a7 --- /dev/null +++ b/library/usergroup_getgid.c @@ -0,0 +1,79 @@ +/* + * $Id: usergroup_getgid.c,v 1.1.1.1 2004-07-26 16:32:35 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +#ifdef getgid +#undef getgid +#endif /* getgid */ + +/****************************************************************************/ + +gid_t +getgid(void) +{ + gid_t result; + + ENTER(); + + assert(__UserGroupBase != NULL); + + if(__root_mode) + { + result = __root_gid; + } + else + { + PROFILE_OFF(); + result = __getgid(); + PROFILE_ON(); + } + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_getgrent.c b/library/usergroup_getgrent.c new file mode 100644 index 0000000..ae6f37d --- /dev/null +++ b/library/usergroup_getgrent.c @@ -0,0 +1,72 @@ +/* + * $Id: usergroup_getgrent.c,v 1.1.1.1 2004-07-26 16:32:35 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +#ifdef getgrent +#undef getgrent +#endif /* getgrent */ + +/****************************************************************************/ + +struct group * +getgrent(void) +{ + struct group * result; + + ENTER(); + + assert(__UserGroupBase != NULL); + + PROFILE_OFF(); + result = __getgrent(); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_getgrgid.c b/library/usergroup_getgrgid.c new file mode 100644 index 0000000..617be4f --- /dev/null +++ b/library/usergroup_getgrgid.c @@ -0,0 +1,66 @@ +/* + * $Id: usergroup_getgrgid.c,v 1.1.1.1 2004-07-26 16:32:35 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +struct group * +getgrgid(gid_t gid) +{ + struct group *result; + + ENTER(); + + assert(__UserGroupBase != NULL); + + PROFILE_OFF(); + result = __getgrgid((LONG)gid); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_getgrnam.c b/library/usergroup_getgrnam.c new file mode 100644 index 0000000..64a42fe --- /dev/null +++ b/library/usergroup_getgrnam.c @@ -0,0 +1,89 @@ +/* + * $Id: usergroup_getgrnam.c,v 1.1.1.1 2004-07-26 16:32:35 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +struct group * +getgrnam(const char * name) +{ + struct group *result = NULL; + + ENTER(); + + SHOWSTRING(name); + + assert(name != NULL); + assert(__UserGroupBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name == NULL) + { + SHOWMSG("invalid name parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __getgrnam((STRPTR)name); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_getgroups.c b/library/usergroup_getgroups.c new file mode 100644 index 0000000..fc62d37 --- /dev/null +++ b/library/usergroup_getgroups.c @@ -0,0 +1,97 @@ +/* + * $Id: usergroup_getgroups.c,v 1.1.1.1 2004-07-26 16:32:35 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +int +getgroups(int ngroups, gid_t *groups) +{ + int result = -1; + + ENTER(); + + SHOWVALUE(ngroups); + SHOWPOINTER(groups); + + assert(ngroups == 0 || groups != NULL); + assert(__UserGroupBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(ngroups != 0 && groups == NULL) + { + SHOWMSG("invalid groups parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(ngroups > 0) + { + PROFILE_OFF(); + result = __getgroups(ngroups,(LONG *)groups); + PROFILE_ON(); + } + else + { + result = 0; + } + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_getpass.c b/library/usergroup_getpass.c new file mode 100644 index 0000000..c372cd7 --- /dev/null +++ b/library/usergroup_getpass.c @@ -0,0 +1,91 @@ +/* + * $Id: usergroup_getpass.c,v 1.1.1.1 2004-07-26 16:32:35 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +char * +getpass(const char *prompt) +{ + char *result = NULL; + + ENTER(); + + SHOWSTRING(prompt); + + assert( prompt != NULL ); + assert(__UserGroupBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(prompt == NULL) + { + SHOWMSG("invalid prompt"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __getpass((STRPTR)prompt); + PROFILE_ON(); + + SHOWSTRING(result); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_getpwent.c b/library/usergroup_getpwent.c new file mode 100644 index 0000000..4234320 --- /dev/null +++ b/library/usergroup_getpwent.c @@ -0,0 +1,66 @@ +/* + * $Id: usergroup_getpwent.c,v 1.1.1.1 2004-07-26 16:32:36 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +struct passwd * +getpwent(void) +{ + struct passwd * result; + + ENTER(); + + assert(__UserGroupBase != NULL); + + PROFILE_OFF(); + result = __getpwent(); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_getpwnam.c b/library/usergroup_getpwnam.c new file mode 100644 index 0000000..c2b2769 --- /dev/null +++ b/library/usergroup_getpwnam.c @@ -0,0 +1,89 @@ +/* + * $Id: usergroup_getpwnam.c,v 1.1.1.1 2004-07-26 16:32:36 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +struct passwd * +getpwnam(const char *name) +{ + struct passwd *result = NULL; + + ENTER(); + + SHOWSTRING(name); + + assert(name != NULL); + assert(__UserGroupBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name == NULL) + { + SHOWMSG("invalid name"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __getpwnam((STRPTR)name); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_getpwuid.c b/library/usergroup_getpwuid.c new file mode 100644 index 0000000..4709392 --- /dev/null +++ b/library/usergroup_getpwuid.c @@ -0,0 +1,68 @@ +/* + * $Id: usergroup_getpwuid.c,v 1.1.1.1 2004-07-26 16:32:36 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +struct passwd * +getpwuid(uid_t uid) +{ + struct passwd *result; + + ENTER(); + + assert(__UserGroupBase != NULL); + + SHOWVALUE(uid); + + PROFILE_OFF(); + result = __getpwuid((LONG)uid); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_getuid.c b/library/usergroup_getuid.c new file mode 100644 index 0000000..83b9118 --- /dev/null +++ b/library/usergroup_getuid.c @@ -0,0 +1,73 @@ +/* + * $Id: usergroup_getuid.c,v 1.1.1.1 2004-07-26 16:32:36 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +uid_t +getuid(void) +{ + uid_t result; + + ENTER(); + + assert(__UserGroupBase != NULL); + + if(__root_mode) + { + result = __root_uid; + } + else + { + PROFILE_OFF(); + result = __getuid(); + PROFILE_ON(); + } + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_headers.h b/library/usergroup_headers.h new file mode 100644 index 0000000..104ce85 --- /dev/null +++ b/library/usergroup_headers.h @@ -0,0 +1,778 @@ +/* + * $Id: usergroup_headers.h,v 1.1.1.1 2004-07-26 16:32:38 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _USERGROUP_HEADERS_H +#define _USERGROUP_HEADERS_H + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +extern struct Library * __UserGroupBase; + +/****************************************************************************/ + +#if defined(__amigaos4__) + +extern struct UserGroupIFace *__IUserGroup; + +#endif /* __amigaos4__ */ + +/****************************************************************************/ + +extern BOOL __root_mode; + +/****************************************************************************/ + +extern int __root_uid; +extern int __root_gid; +extern int __root_euid; +extern int __root_egid; + +/****************************************************************************/ + +#if defined(__GNUC__) + +#if defined(__amigaos4__) + +#include + +#define __ug_SetupContextTagList(name, tags) __IUserGroup->ug_SetupContextTagList(name, tags) +#define __ug_GetErr() __IUserGroup->ug_GetErr() +#define __ug_StrError(err) __IUserGroup->ug_StrError(err) +#define __getuid() __IUserGroup->getuid() +#define __geteuid() __IUserGroup->geteuid() +#define __setreuid(real, effective) __IUserGroup->setreuid(real, effective) +#define __setuid(uid) __IUserGroup->setuid(uid) +#define __getgid() __IUserGroup->getgid() +#define __getegid() __IUserGroup->getegid() +#define __setregid(real, effective) __IUserGroup->setregid(real, effective) +#define __setgid(gid) __IUserGroup->setgid(gid) +#define __getgroups(gidsetlen, gidset) __IUserGroup->getgroups(gidsetlen, gidset) +#define __setgroups(gidsetlen, gidset) __IUserGroup->setgroups(gidsetlen, gidset) +#define __initgroups(name, basegid) __IUserGroup->initgroups(name, basegid) +#define __getpwnam(login) __IUserGroup->getpwnam(login) +#define __getpwuid(uid) __IUserGroup->getpwuid(uid) +#define __setpwent() __IUserGroup->setpwent() +#define __getpwent() __IUserGroup->getpwent() +#define __endpwent() __IUserGroup->endpwent() +#define __getgrnam(name) __IUserGroup->getgrnam(name) +#define __getgrgid(gid) __IUserGroup->getgrgid(gid) +#define __setgrent() __IUserGroup->setgrent() +#define __getgrent() __IUserGroup->getgrent() +#define __endgrent() __IUserGroup->endgrent() +#define __crypt(key, set) __IUserGroup->crypt(key, set) +#define __ug_GetSalt(user, buf, size) __IUserGroup->ug_GetSalt(user, buf, size) +#define __getpass(prompt) __IUserGroup->getpass(prompt) +#define __umask(mask) __IUserGroup->umask(mask) +#define __getumask() __IUserGroup->getumask() +#define __setsid() __IUserGroup->setsid() +#define __getpgrp() __IUserGroup->getpgrp() +#define __getlogin() __IUserGroup->getlogin() +#define __setlogin(name) __IUserGroup->setlogin(name) +#define __setutent() __IUserGroup->setutent() +#define __getutent() __IUserGroup->getutent() +#define __endutent() __IUserGroup->endutent() +#define __getlastlog(uid) __IUserGroup->getlastlog(uid) +#define __setlastlog(uid, name, host) __IUserGroup->setlastlog(uid, name, host) +#define __getcredentials(task) __IUserGroup->getcredentials(task) + +#else + +#define __ug_SetupContextTagList(name, tags) ({ \ + UBYTE * _ug_SetupContextTagList_name = (name); \ + struct TagItem * _ug_SetupContextTagList_tags = (tags); \ + LONG _ug_SetupContextTagList__re = \ + ({ \ + register struct Library * const __ug_SetupContextTagList__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __ug_SetupContextTagList__re __asm("d0"); \ + register UBYTE * __ug_SetupContextTagList_name __asm("a0") = (_ug_SetupContextTagList_name); \ + register struct TagItem * __ug_SetupContextTagList_tags __asm("a1") = (_ug_SetupContextTagList_tags); \ + __asm volatile ("jsr a6@(-30:W)" \ + : "=r"(__ug_SetupContextTagList__re) \ + : "r"(__ug_SetupContextTagList__bn), "r"(__ug_SetupContextTagList_name), "r"(__ug_SetupContextTagList_tags) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __ug_SetupContextTagList__re; \ + }); \ + _ug_SetupContextTagList__re; \ +}) + +#define __ug_GetErr() ({ \ + LONG _ug_GetErr__re = \ + ({ \ + register struct Library * const __ug_GetErr__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __ug_GetErr__re __asm("d0"); \ + __asm volatile ("jsr a6@(-36:W)" \ + : "=r"(__ug_GetErr__re) \ + : "r"(__ug_GetErr__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __ug_GetErr__re; \ + }); \ + _ug_GetErr__re; \ +}) + +#define __ug_StrError(err) ({ \ + LONG _ug_StrError_err = (err); \ + UBYTE * _ug_StrError__re = \ + ({ \ + register struct Library * const __ug_StrError__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register UBYTE * __ug_StrError__re __asm("d0"); \ + register LONG __ug_StrError_err __asm("d1") = (_ug_StrError_err); \ + __asm volatile ("jsr a6@(-42:W)" \ + : "=r"(__ug_StrError__re) \ + : "r"(__ug_StrError__bn), "r"(__ug_StrError_err) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __ug_StrError__re; \ + }); \ + _ug_StrError__re; \ +}) + +#define __getuid() ({ \ + LONG _getuid__re = \ + ({ \ + register struct Library * const __getuid__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __getuid__re __asm("d0"); \ + __asm volatile ("jsr a6@(-48:W)" \ + : "=r"(__getuid__re) \ + : "r"(__getuid__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getuid__re; \ + }); \ + _getuid__re; \ +}) + +#define __geteuid() ({ \ + LONG _geteuid__re = \ + ({ \ + register struct Library * const __geteuid__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __geteuid__re __asm("d0"); \ + __asm volatile ("jsr a6@(-54:W)" \ + : "=r"(__geteuid__re) \ + : "r"(__geteuid__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __geteuid__re; \ + }); \ + _geteuid__re; \ +}) + +#define __setreuid(real, effective) ({ \ + LONG _setreuid_real = (real); \ + LONG _setreuid_effective = (effective); \ + LONG _setreuid__re = \ + ({ \ + register struct Library * const __setreuid__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __setreuid__re __asm("d0"); \ + register LONG __setreuid_real __asm("d0") = (_setreuid_real); \ + register LONG __setreuid_effective __asm("d1") = (_setreuid_effective); \ + __asm volatile ("jsr a6@(-60:W)" \ + : "=r"(__setreuid__re) \ + : "r"(__setreuid__bn), "r"(__setreuid_real), "r"(__setreuid_effective) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __setreuid__re; \ + }); \ + _setreuid__re; \ +}) + +#define __setuid(uid) ({ \ + LONG _setuid_uid = (uid); \ + LONG _setuid__re = \ + ({ \ + register struct Library * const __setuid__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __setuid__re __asm("d0"); \ + register LONG __setuid_uid __asm("d0") = (_setuid_uid); \ + __asm volatile ("jsr a6@(-66:W)" \ + : "=r"(__setuid__re) \ + : "r"(__setuid__bn), "r"(__setuid_uid) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __setuid__re; \ + }); \ + _setuid__re; \ +}) + +#define __getgid() ({ \ + LONG _getgid__re = \ + ({ \ + register struct Library * const __getgid__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __getgid__re __asm("d0"); \ + __asm volatile ("jsr a6@(-72:W)" \ + : "=r"(__getgid__re) \ + : "r"(__getgid__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getgid__re; \ + }); \ + _getgid__re; \ +}) + +#define __getegid() ({ \ + LONG _getegid__re = \ + ({ \ + register struct Library * const __getegid__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __getegid__re __asm("d0"); \ + __asm volatile ("jsr a6@(-78:W)" \ + : "=r"(__getegid__re) \ + : "r"(__getegid__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getegid__re; \ + }); \ + _getegid__re; \ +}) + +#define __setregid(real, effective) ({ \ + LONG _setregid_real = (real); \ + LONG _setregid_effective = (effective); \ + LONG _setregid__re = \ + ({ \ + register struct Library * const __setregid__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __setregid__re __asm("d0"); \ + register LONG __setregid_real __asm("d0") = (_setregid_real); \ + register LONG __setregid_effective __asm("d1") = (_setregid_effective); \ + __asm volatile ("jsr a6@(-84:W)" \ + : "=r"(__setregid__re) \ + : "r"(__setregid__bn), "r"(__setregid_real), "r"(__setregid_effective) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __setregid__re; \ + }); \ + _setregid__re; \ +}) + +#define __setgid(gid) ({ \ + LONG _setgid_gid = (gid); \ + LONG _setgid__re = \ + ({ \ + register struct Library * const __setgid__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __setgid__re __asm("d0"); \ + register LONG __setgid_gid __asm("d0") = (_setgid_gid); \ + __asm volatile ("jsr a6@(-90:W)" \ + : "=r"(__setgid__re) \ + : "r"(__setgid__bn), "r"(__setgid_gid) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __setgid__re; \ + }); \ + _setgid__re; \ +}) + +#define __getgroups(gidsetlen, gidset) ({ \ + LONG _getgroups_gidsetlen = (gidsetlen); \ + LONG * _getgroups_gidset = (gidset); \ + LONG _getgroups__re = \ + ({ \ + register struct Library * const __getgroups__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __getgroups__re __asm("d0"); \ + register LONG __getgroups_gidsetlen __asm("d0") = (_getgroups_gidsetlen); \ + register LONG * __getgroups_gidset __asm("a1") = (_getgroups_gidset); \ + __asm volatile ("jsr a6@(-96:W)" \ + : "=r"(__getgroups__re) \ + : "r"(__getgroups__bn), "r"(__getgroups_gidsetlen), "r"(__getgroups_gidset) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getgroups__re; \ + }); \ + _getgroups__re; \ +}) + +#define __setgroups(gidsetlen, gidset) ({ \ + LONG _setgroups_gidsetlen = (gidsetlen); \ + LONG * _setgroups_gidset = (gidset); \ + LONG _setgroups__re = \ + ({ \ + register struct Library * const __setgroups__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __setgroups__re __asm("d0"); \ + register LONG __setgroups_gidsetlen __asm("d0") = (_setgroups_gidsetlen); \ + register LONG * __setgroups_gidset __asm("a1") = (_setgroups_gidset); \ + __asm volatile ("jsr a6@(-102:W)" \ + : "=r"(__setgroups__re) \ + : "r"(__setgroups__bn), "r"(__setgroups_gidsetlen), "r"(__setgroups_gidset) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __setgroups__re; \ + }); \ + _setgroups__re; \ +}) + +#define __initgroups(name, basegid) ({ \ + UBYTE * _initgroups_name = (name); \ + LONG _initgroups_basegid = (basegid); \ + LONG _initgroups__re = \ + ({ \ + register struct Library * const __initgroups__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __initgroups__re __asm("d0"); \ + register UBYTE * __initgroups_name __asm("a1") = (_initgroups_name); \ + register LONG __initgroups_basegid __asm("d0") = (_initgroups_basegid); \ + __asm volatile ("jsr a6@(-108:W)" \ + : "=r"(__initgroups__re) \ + : "r"(__initgroups__bn), "r"(__initgroups_name), "r"(__initgroups_basegid) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __initgroups__re; \ + }); \ + _initgroups__re; \ +}) + +#define __getpwnam(login) ({ \ + UBYTE * _getpwnam_login = (login); \ + struct passwd * _getpwnam__re = \ + ({ \ + register struct Library * const __getpwnam__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register struct passwd * __getpwnam__re __asm("d0"); \ + register UBYTE * __getpwnam_login __asm("a1") = (_getpwnam_login); \ + __asm volatile ("jsr a6@(-114:W)" \ + : "=r"(__getpwnam__re) \ + : "r"(__getpwnam__bn), "r"(__getpwnam_login) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getpwnam__re; \ + }); \ + _getpwnam__re; \ +}) + +#define __getpwuid(uid) ({ \ + LONG _getpwuid_uid = (uid); \ + struct passwd * _getpwuid__re = \ + ({ \ + register struct Library * const __getpwuid__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register struct passwd * __getpwuid__re __asm("d0"); \ + register LONG __getpwuid_uid __asm("d0") = (_getpwuid_uid); \ + __asm volatile ("jsr a6@(-120:W)" \ + : "=r"(__getpwuid__re) \ + : "r"(__getpwuid__bn), "r"(__getpwuid_uid) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getpwuid__re; \ + }); \ + _getpwuid__re; \ +}) + +#define __setpwent() ({ \ + register struct Library * const __setpwent__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + __asm volatile ("jsr a6@(-126:W)" \ + : \ + : "r"(__setpwent__bn) \ + : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ +}) + +#define __getpwent() ({ \ + struct passwd * _getpwent__re = \ + ({ \ + register struct Library * const __getpwent__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register struct passwd * __getpwent__re __asm("d0"); \ + __asm volatile ("jsr a6@(-132:W)" \ + : "=r"(__getpwent__re) \ + : "r"(__getpwent__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getpwent__re; \ + }); \ + _getpwent__re; \ +}) + +#define __endpwent() ({ \ + register struct Library * const __endpwent__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + __asm volatile ("jsr a6@(-138:W)" \ + : \ + : "r"(__endpwent__bn) \ + : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ +}) + +#define __getgrnam(name) ({ \ + UBYTE * _getgrnam_name = (name); \ + struct group * _getgrnam__re = \ + ({ \ + register struct Library * const __getgrnam__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register struct group * __getgrnam__re __asm("d0"); \ + register UBYTE * __getgrnam_name __asm("a1") = (_getgrnam_name); \ + __asm volatile ("jsr a6@(-144:W)" \ + : "=r"(__getgrnam__re) \ + : "r"(__getgrnam__bn), "r"(__getgrnam_name) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getgrnam__re; \ + }); \ + _getgrnam__re; \ +}) + +#define __getgrgid(gid) ({ \ + LONG _getgrgid_gid = (gid); \ + struct group * _getgrgid__re = \ + ({ \ + register struct Library * const __getgrgid__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register struct group * __getgrgid__re __asm("d0"); \ + register LONG __getgrgid_gid __asm("d0") = (_getgrgid_gid); \ + __asm volatile ("jsr a6@(-150:W)" \ + : "=r"(__getgrgid__re) \ + : "r"(__getgrgid__bn), "r"(__getgrgid_gid) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getgrgid__re; \ + }); \ + _getgrgid__re; \ +}) + +#define __setgrent() ({ \ + register struct Library * const __setgrent__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + __asm volatile ("jsr a6@(-156:W)" \ + : \ + : "r"(__setgrent__bn) \ + : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ +}) + +#define __getgrent() ({ \ + struct group * _getgrent__re = \ + ({ \ + register struct Library * const __getgrent__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register struct group * __getgrent__re __asm("d0"); \ + __asm volatile ("jsr a6@(-162:W)" \ + : "=r"(__getgrent__re) \ + : "r"(__getgrent__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getgrent__re; \ + }); \ + _getgrent__re; \ +}) + +#define __endgrent() ({ \ + register struct Library * const __endgrent__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + __asm volatile ("jsr a6@(-168:W)" \ + : \ + : "r"(__endgrent__bn) \ + : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ +}) + +#define __crypt(key, set) ({ \ + UBYTE * _crypt_key = (key); \ + UBYTE * _crypt_set = (set); \ + UBYTE * _crypt__re = \ + ({ \ + register struct Library * const __crypt__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register UBYTE * __crypt__re __asm("d0"); \ + register UBYTE * __crypt_key __asm("a0") = (_crypt_key); \ + register UBYTE * __crypt_set __asm("a1") = (_crypt_set); \ + __asm volatile ("jsr a6@(-174:W)" \ + : "=r"(__crypt__re) \ + : "r"(__crypt__bn), "r"(__crypt_key), "r"(__crypt_set) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __crypt__re; \ + }); \ + _crypt__re; \ +}) + +#define __ug_GetSalt(user, buf, size) ({ \ + struct passwd * _ug_GetSalt_user = (user); \ + UBYTE * _ug_GetSalt_buf = (buf); \ + ULONG _ug_GetSalt_size = (size); \ + UBYTE * _ug_GetSalt__re = \ + ({ \ + register struct Library * const __ug_GetSalt__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register UBYTE * __ug_GetSalt__re __asm("d0"); \ + register struct passwd * __ug_GetSalt_user __asm("a0") = (_ug_GetSalt_user); \ + register UBYTE * __ug_GetSalt_buf __asm("a1") = (_ug_GetSalt_buf); \ + register ULONG __ug_GetSalt_size __asm("d0") = (_ug_GetSalt_size); \ + __asm volatile ("jsr a6@(-180:W)" \ + : "=r"(__ug_GetSalt__re) \ + : "r"(__ug_GetSalt__bn), "r"(__ug_GetSalt_user), "r"(__ug_GetSalt_buf), "r"(__ug_GetSalt_size) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __ug_GetSalt__re; \ + }); \ + _ug_GetSalt__re; \ +}) + +#define __getpass(prompt) ({ \ + UBYTE * _getpass_prompt = (prompt); \ + UBYTE * _getpass__re = \ + ({ \ + register struct Library * const __getpass__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register UBYTE * __getpass__re __asm("d0"); \ + register UBYTE * __getpass_prompt __asm("a1") = (_getpass_prompt); \ + __asm volatile ("jsr a6@(-186:W)" \ + : "=r"(__getpass__re) \ + : "r"(__getpass__bn), "r"(__getpass_prompt) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getpass__re; \ + }); \ + _getpass__re; \ +}) + +#define __umask(mask) ({ \ + ULONG _umask_mask = (mask); \ + { \ + register struct Library * const __umask__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register ULONG __umask_mask __asm("d0") = (_umask_mask); \ + __asm volatile ("jsr a6@(-192:W)" \ + : \ + : "r"(__umask__bn), "r"(__umask_mask) \ + : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + } \ +}) + +#define __getumask() ({ \ + UWORD _getumask__re = \ + ({ \ + register struct Library * const __getumask__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register UWORD __getumask__re __asm("d0"); \ + __asm volatile ("jsr a6@(-198:W)" \ + : "=r"(__getumask__re) \ + : "r"(__getumask__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getumask__re; \ + }); \ + _getumask__re; \ +}) + +#define __setsid() ({ \ + LONG _setsid__re = \ + ({ \ + register struct Library * const __setsid__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __setsid__re __asm("d0"); \ + __asm volatile ("jsr a6@(-204:W)" \ + : "=r"(__setsid__re) \ + : "r"(__setsid__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __setsid__re; \ + }); \ + _setsid__re; \ +}) + +#define __getpgrp() ({ \ + LONG _getpgrp__re = \ + ({ \ + register struct Library * const __getpgrp__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __getpgrp__re __asm("d0"); \ + __asm volatile ("jsr a6@(-210:W)" \ + : "=r"(__getpgrp__re) \ + : "r"(__getpgrp__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getpgrp__re; \ + }); \ + _getpgrp__re; \ +}) + +#define __getlogin() ({ \ + UBYTE * _getlogin__re = \ + ({ \ + register struct Library * const __getlogin__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register UBYTE * __getlogin__re __asm("d0"); \ + __asm volatile ("jsr a6@(-216:W)" \ + : "=r"(__getlogin__re) \ + : "r"(__getlogin__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getlogin__re; \ + }); \ + _getlogin__re; \ +}) + +#define __setlogin(name) ({ \ + UBYTE * _setlogin_name = (name); \ + LONG _setlogin__re = \ + ({ \ + register struct Library * const __setlogin__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __setlogin__re __asm("d0"); \ + register UBYTE * __setlogin_name __asm("a1") = (_setlogin_name); \ + __asm volatile ("jsr a6@(-222:W)" \ + : "=r"(__setlogin__re) \ + : "r"(__setlogin__bn), "r"(__setlogin_name) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __setlogin__re; \ + }); \ + _setlogin__re; \ +}) + +#define __setutent() ({ \ + register struct Library * const __setutent__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + __asm volatile ("jsr a6@(-228:W)" \ + : \ + : "r"(__setutent__bn) \ + : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ +}) + +#define __getutent() ({ \ + struct utmp * _getutent__re = \ + ({ \ + register struct Library * const __getutent__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register struct utmp * __getutent__re __asm("d0"); \ + __asm volatile ("jsr a6@(-234:W)" \ + : "=r"(__getutent__re) \ + : "r"(__getutent__bn) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getutent__re; \ + }); \ + _getutent__re; \ +}) + +#define __endutent() ({ \ + register struct Library * const __endutent__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + __asm volatile ("jsr a6@(-240:W)" \ + : \ + : "r"(__endutent__bn) \ + : "d0", "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ +}) + +#define __getlastlog(uid) ({ \ + LONG _getlastlog_uid = (uid); \ + struct lastlog * _getlastlog__re = \ + ({ \ + register struct Library * const __getlastlog__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register struct lastlog * __getlastlog__re __asm("d0"); \ + register LONG __getlastlog_uid __asm("d0") = (_getlastlog_uid); \ + __asm volatile ("jsr a6@(-246:W)" \ + : "=r"(__getlastlog__re) \ + : "r"(__getlastlog__bn), "r"(__getlastlog_uid) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getlastlog__re; \ + }); \ + _getlastlog__re; \ +}) + +#define __setlastlog(uid, name, host) ({ \ + LONG _setlastlog_uid = (uid); \ + UBYTE * _setlastlog_name = (name); \ + UBYTE * _setlastlog_host = (host); \ + LONG _setlastlog__re = \ + ({ \ + register struct Library * const __setlastlog__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register LONG __setlastlog__re __asm("d0"); \ + register LONG __setlastlog_uid __asm("d0") = (_setlastlog_uid); \ + register UBYTE * __setlastlog_name __asm("a0") = (_setlastlog_name); \ + register UBYTE * __setlastlog_host __asm("a1") = (_setlastlog_host); \ + __asm volatile ("jsr a6@(-252:W)" \ + : "=r"(__setlastlog__re) \ + : "r"(__setlastlog__bn), "r"(__setlastlog_uid), "r"(__setlastlog_name), "r"(__setlastlog_host) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __setlastlog__re; \ + }); \ + _setlastlog__re; \ +}) + +#define __getcredentials(task) ({ \ + struct Task * _getcredentials_task = (task); \ + struct UserGroupCredentials * _getcredentials__re = \ + ({ \ + register struct Library * const __getcredentials__bn __asm("a6") = (struct Library *) (__UserGroupBase);\ + register struct UserGroupCredentials * __getcredentials__re __asm("d0"); \ + register struct Task * __getcredentials_task __asm("a0") = (_getcredentials_task); \ + __asm volatile ("jsr a6@(-258:W)" \ + : "=r"(__getcredentials__re) \ + : "r"(__getcredentials__bn), "r"(__getcredentials_task) \ + : "d1", "a0", "a1", "fp0", "fp1", "cc", "memory"); \ + __getcredentials__re; \ + }); \ + _getcredentials__re; \ +}) + +#endif /* __amigaos4__ */ + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +#if defined(__SASC) + +LONG __ug_SetupContextTagList(UBYTE *name,struct TagItem *tags); +LONG __ug_GetErr(VOID); +UBYTE *__ug_StrError(LONG err); +LONG __getuid(VOID); +LONG __geteuid(VOID); +LONG __setreuid(LONG real,LONG effective); +LONG __setuid(LONG uid); +LONG __getgid(VOID); +LONG __getegid(VOID); +LONG __setregid(LONG real,LONG effective); +LONG __setgid(LONG gid); +LONG __getgroups(LONG gidsetlen,LONG *gidset); +LONG __setgroups(LONG gidsetlen,LONG *gidset); +LONG __initgroups(UBYTE *name,LONG basegid); +struct passwd *__getpwnam(UBYTE *login); +struct passwd *__getpwuid(LONG uid); +VOID __setpwent(VOID); +struct passwd *__getpwent(VOID); +VOID __endpwent(VOID); +struct group *__getgrnam(UBYTE *name); +struct group *__getgrgid(LONG gid); +VOID __setgrent(VOID); +struct group *__getgrent(VOID); +VOID __endgrent(VOID); +UBYTE *__crypt(UBYTE *key,UBYTE *set); +UBYTE *__ug_GetSalt(struct passwd *user,UBYTE *buf,ULONG size); +UBYTE *__getpass(UBYTE *prompt); +VOID __umask(ULONG mask); +UWORD __getumask(VOID); +LONG __setsid(VOID); +LONG __getpgrp(VOID); +UBYTE *__getlogin(VOID); +LONG __setlogin(UBYTE *name); +VOID __setutent(VOID); +struct utmp *__getutent(VOID); +VOID __endutent(VOID); +struct lastlog *__getlastlog(LONG uid); +LONG __setlastlog(LONG uid,UBYTE *name,UBYTE *host); +struct UserGroupCredentials *__getcredentials(struct Task *task); + +#pragma libcall __UserGroupBase __ug_SetupContextTagList 1e 9802 +#pragma libcall __UserGroupBase __ug_GetErr 24 00 +#pragma libcall __UserGroupBase __ug_StrError 2a 101 +#pragma libcall __UserGroupBase __getuid 30 00 +#pragma libcall __UserGroupBase __geteuid 36 00 +#pragma libcall __UserGroupBase __setreuid 3c 1002 +#pragma libcall __UserGroupBase __setuid 42 001 +#pragma libcall __UserGroupBase __getgid 48 00 +#pragma libcall __UserGroupBase __getegid 4e 00 +#pragma libcall __UserGroupBase __setregid 54 1002 +#pragma libcall __UserGroupBase __setgid 5a 001 +#pragma libcall __UserGroupBase __getgroups 60 9002 +#pragma libcall __UserGroupBase __setgroups 66 9002 +#pragma libcall __UserGroupBase __initgroups 6c 0902 +#pragma libcall __UserGroupBase __getpwnam 72 901 +#pragma libcall __UserGroupBase __getpwuid 78 001 +#pragma libcall __UserGroupBase __setpwent 7e 00 +#pragma libcall __UserGroupBase __getpwent 84 00 +#pragma libcall __UserGroupBase __endpwent 8a 00 +#pragma libcall __UserGroupBase __getgrnam 90 901 +#pragma libcall __UserGroupBase __getgrgid 96 001 +#pragma libcall __UserGroupBase __setgrent 9c 00 +#pragma libcall __UserGroupBase __getgrent a2 00 +#pragma libcall __UserGroupBase __endgrent a8 00 +#pragma libcall __UserGroupBase __crypt ae 9802 +#pragma libcall __UserGroupBase __ug_GetSalt b4 09803 +#pragma libcall __UserGroupBase __getpass ba 901 +#pragma libcall __UserGroupBase __umask c0 001 +#pragma libcall __UserGroupBase __getumask c6 00 +#pragma libcall __UserGroupBase __setsid cc 00 +#pragma libcall __UserGroupBase __getpgrp d2 00 +#pragma libcall __UserGroupBase __getlogin d8 00 +#pragma libcall __UserGroupBase __setlogin de 901 +#pragma libcall __UserGroupBase __setutent e4 00 +#pragma libcall __UserGroupBase __getutent ea 00 +#pragma libcall __UserGroupBase __endutent f0 00 +#pragma libcall __UserGroupBase __getlastlog f6 001 +#pragma libcall __UserGroupBase __setlastlog fc 98003 +#pragma libcall __UserGroupBase __getcredentials 102 801 + +#endif /* __SASC */ + +/****************************************************************************/ + +#endif /* _USERGROUP_HEADERS_H */ diff --git a/library/usergroup_init_exit.c b/library/usergroup_init_exit.c new file mode 100644 index 0000000..513e278 --- /dev/null +++ b/library/usergroup_init_exit.c @@ -0,0 +1,147 @@ +/* + * $Id: usergroup_init_exit.c,v 1.1.1.1 2004-07-26 16:32:38 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +#include "stdlib_protos.h" + +/****************************************************************************/ + +/* Pointer to errno, length == sizeof(errno) */ +#define UGT_ERRNOLPTR 0x80000004 + +/****************************************************************************/ + +extern char * __program_name; + +/****************************************************************************/ + +extern void __show_error(const char * message); + +/****************************************************************************/ + +void +__usergroup_exit(void) +{ + ENTER(); + + #if defined(__amigaos4__) + { + if(__IUserGroup != NULL) + { + DropInterface((struct Interface *)__IUserGroup); + __IUserGroup = NULL; + } + } + #endif /* __amigaos4__ */ + + if(__UserGroupBase != NULL) + { + CloseLibrary(__UserGroupBase); + __UserGroupBase = NULL; + } + + LEAVE(); +} + +/****************************************************************************/ + +int +__usergroup_init(void) +{ + struct TagItem tags[2]; + int result = ERROR; + + ENTER(); + + PROFILE_OFF(); + + __UserGroupBase = OpenLibrary("usergroup.library",0); + + #if defined(__amigaos4__) + { + if(__UserGroupBase != NULL) + { + __IUserGroup = (struct UserGroupIFace *)GetInterface(__UserGroupBase, "main", 1, 0); + if (__IUserGroup == NULL) + { + CloseLibrary(__UserGroupBase); + __UserGroupBase = NULL; + } + } + } + #endif /* __amigaos4__ */ + + if(__UserGroupBase == NULL) + { + SHOWMSG("usergroup.library did not open"); + + __show_error("\"usergroup.library\" could not be opened."); + goto out; + } + + /* Wire the library's errno variable to our local errno. */ + tags[0].ti_Tag = UGT_ERRNOLPTR; + tags[0].ti_Data = (ULONG)&errno; + + tags[1].ti_Tag = TAG_END; + + if(__ug_SetupContextTagList(__program_name,tags) != 0) + { + SHOWMSG("could not initialize usergroup.library"); + + __show_error("\"usergroup.library\" could not be initialized."); + goto out; + } + + result = OK; + + out: + + PROFILE_ON(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_initgroups.c b/library/usergroup_initgroups.c new file mode 100644 index 0000000..f1b1994 --- /dev/null +++ b/library/usergroup_initgroups.c @@ -0,0 +1,90 @@ +/* + * $Id: usergroup_initgroups.c,v 1.1.1.1 2004-07-26 16:32:39 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +int +initgroups(const char *name, gid_t basegroup) +{ + int result = -1; + + ENTER(); + + SHOWSTRING(name); + SHOWVALUE(basegroup); + + assert(name != NULL); + assert(__UserGroupBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(name == NULL) + { + SHOWMSG("invalid name"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + PROFILE_OFF(); + result = __initgroups((STRPTR)name,(LONG)basegroup); + PROFILE_ON(); + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_rootmode.c b/library/usergroup_rootmode.c new file mode 100644 index 0000000..83a188c --- /dev/null +++ b/library/usergroup_rootmode.c @@ -0,0 +1,48 @@ +/* + * $Id: usergroup_rootmode.c,v 1.1.1.1 2004-07-26 16:32:39 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +BOOL __root_mode; + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_setegid.c b/library/usergroup_setegid.c new file mode 100644 index 0000000..5da039f --- /dev/null +++ b/library/usergroup_setegid.c @@ -0,0 +1,66 @@ +/* + * $Id: usergroup_setegid.c,v 1.1.1.1 2004-07-26 16:32:39 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +int +setegid(gid_t g) +{ + int result; + + ENTER(); + + SHOWVALUE(g); + + assert(__UserGroupBase != NULL); + + result = setregid((ULONG)-1,(ULONG)g); + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_seteuid.c b/library/usergroup_seteuid.c new file mode 100644 index 0000000..4f69818 --- /dev/null +++ b/library/usergroup_seteuid.c @@ -0,0 +1,66 @@ +/* + * $Id: usergroup_seteuid.c,v 1.1.1.1 2004-07-26 16:32:39 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +int +seteuid(uid_t u) +{ + int result; + + ENTER(); + + SHOWVALUE(u); + + assert(__UserGroupBase != NULL); + + result = setreuid((ULONG)-1,(ULONG)u); + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_setgid.c b/library/usergroup_setgid.c new file mode 100644 index 0000000..0af244f --- /dev/null +++ b/library/usergroup_setgid.c @@ -0,0 +1,77 @@ +/* + * $Id: usergroup_setgid.c,v 1.1.1.1 2004-07-26 16:32:39 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +int +setgid(gid_t id) +{ + int result; + + ENTER(); + + SHOWVALUE(id); + + assert(__UserGroupBase != NULL); + + if(__root_mode) + { + __root_gid = id; + + result = 0; + } + else + { + PROFILE_OFF(); + result = __setgid((LONG)id); + PROFILE_ON(); + } + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_setgrent.c b/library/usergroup_setgrent.c new file mode 100644 index 0000000..36c23c6 --- /dev/null +++ b/library/usergroup_setgrent.c @@ -0,0 +1,63 @@ +/* + * $Id: usergroup_setgrent.c,v 1.1.1.1 2004-07-26 16:32:39 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +void +setgrent(void) +{ + ENTER(); + + assert(__UserGroupBase != NULL); + + PROFILE_OFF(); + __setgrent(); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + LEAVE(); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_setgroups.c b/library/usergroup_setgroups.c new file mode 100644 index 0000000..807332b --- /dev/null +++ b/library/usergroup_setgroups.c @@ -0,0 +1,97 @@ +/* + * $Id: usergroup_setgroups.c,v 1.1.1.1 2004-07-26 16:32:39 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +int +setgroups(int ngroups,const gid_t *groups) +{ + int result = -1; + + ENTER(); + + SHOWVALUE(ngroups); + SHOWPOINTER(groups); + + assert(ngroups == 0 || groups != NULL); + assert(__UserGroupBase != NULL); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(ngroups != 0 && groups == NULL) + { + SHOWMSG("invalid groups parameter"); + + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(ngroups > 0) + { + PROFILE_OFF(); + result = __setgroups(ngroups,(LONG *)groups); + PROFILE_ON(); + } + else + { + result = 0; + } + + out: + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_setpwent.c b/library/usergroup_setpwent.c new file mode 100644 index 0000000..ed615c8 --- /dev/null +++ b/library/usergroup_setpwent.c @@ -0,0 +1,63 @@ +/* + * $Id: usergroup_setpwent.c,v 1.1.1.1 2004-07-26 16:32:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +void +setpwent(void) +{ + ENTER(); + + assert(__UserGroupBase != NULL); + + PROFILE_OFF(); + __setpwent(); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + LEAVE(); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_setregid.c b/library/usergroup_setregid.c new file mode 100644 index 0000000..9211f09 --- /dev/null +++ b/library/usergroup_setregid.c @@ -0,0 +1,82 @@ +/* + * $Id: usergroup_setregid.c,v 1.1.1.1 2004-07-26 16:32:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +int +setregid(gid_t real, gid_t eff) +{ + int result; + + ENTER(); + + SHOWVALUE(real); + SHOWVALUE(eff); + + assert(__UserGroupBase != NULL); + + if(__root_mode) + { + if(real != (gid_t)-1) + __root_gid = real; + + if(eff != (gid_t)-1) + __root_egid = eff; + + result = 0; + } + else + { + PROFILE_OFF(); + result = __setregid((LONG)real,(LONG)eff); + PROFILE_ON(); + } + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_setreuid.c b/library/usergroup_setreuid.c new file mode 100644 index 0000000..ee8504f --- /dev/null +++ b/library/usergroup_setreuid.c @@ -0,0 +1,82 @@ +/* + * $Id: usergroup_setreuid.c,v 1.1.1.1 2004-07-26 16:32:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +int +setreuid(uid_t real, uid_t eff) +{ + int result; + + ENTER(); + + SHOWVALUE(real); + SHOWVALUE(eff); + + assert(__UserGroupBase != NULL); + + if(__root_mode) + { + if(real != (uid_t)-1) + __root_uid = real; + + if(eff != (uid_t)-1) + __root_euid = eff; + + result = 0; + } + else + { + PROFILE_OFF(); + result = __setreuid((LONG)real,(LONG)eff); + PROFILE_ON(); + } + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_setsid.c b/library/usergroup_setsid.c new file mode 100644 index 0000000..a694697 --- /dev/null +++ b/library/usergroup_setsid.c @@ -0,0 +1,66 @@ +/* + * $Id: usergroup_setsid.c,v 1.1.1.1 2004-07-26 16:32:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +long +setsid(void) +{ + long result; + + ENTER(); + + assert(__UserGroupBase != NULL); + + PROFILE_OFF(); + result = (long)__setsid(); + PROFILE_ON(); + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/usergroup_setuid.c b/library/usergroup_setuid.c new file mode 100644 index 0000000..4af5b4f --- /dev/null +++ b/library/usergroup_setuid.c @@ -0,0 +1,77 @@ +/* + * $Id: usergroup_setuid.c,v 1.1.1.1 2004-07-26 16:32:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(USERGROUP_SUPPORT) + +/****************************************************************************/ + +#ifndef _USERGROUP_HEADERS_H +#include "usergroup_headers.h" +#endif /* _USERGROUP_HEADERS_H */ + +/****************************************************************************/ + +int +setuid(uid_t id) +{ + int result; + + ENTER(); + + SHOWVALUE(id); + + assert(__UserGroupBase != NULL); + + if(__root_mode) + { + __root_uid = id; + + result = 0; + } + else + { + PROFILE_OFF(); + result = __setuid((LONG)id); + PROFILE_ON(); + } + + if(__check_abort_enabled) + __check_abort(); + + RETURN(result); + return(result); +} + +/****************************************************************************/ + +#endif /* USERGROUP_SUPPORT */ diff --git a/library/utime_headers.h b/library/utime_headers.h new file mode 100644 index 0000000..67b2cf7 --- /dev/null +++ b/library/utime_headers.h @@ -0,0 +1,45 @@ +/* + * $Id: utime_headers.h,v 1.1.1.1 2004-07-26 16:32:40 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _UTIME_HEADERS_H +#define _UTIME_HEADERS_H + +/****************************************************************************/ + +#ifndef _STDIO_HEADERS_H +#include "stdio_headers.h" +#endif /* _STDIO_HEADERS_H */ + +/****************************************************************************/ + +#endif /* _UTIME_HEADERS_H */ diff --git a/library/utime_utime.c b/library/utime_utime.c new file mode 100644 index 0000000..1f8ce28 --- /dev/null +++ b/library/utime_utime.c @@ -0,0 +1,136 @@ +/* + * $Id: utime_utime.c,v 1.1.1.1 2004-07-26 16:32:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _STDLIB_NULL_POINTER_CHECK_H +#include "stdlib_null_pointer_check.h" +#endif /* _STDLIB_NULL_POINTER_CHECK_H */ + +/****************************************************************************/ + +#ifndef _UTIME_HEADERS_H +#include "utime_headers.h" +#endif /* _UTIME_HEADERS_H */ + +#ifndef _LOCALE_HEADERS_H +#include "locale_headers.h" +#endif /* _LOCALE_HEADERS_H */ + +/****************************************************************************/ + +/* The following is not part of the ISO 'C' standard. */ + +/****************************************************************************/ + +int +utime(const char * path_name,const struct utimbuf * times) +{ + #if defined(UNIX_PATH_SEMANTICS) + struct name_translation_info path_name_nti; + #endif /* UNIX_PATH_SEMANTICS */ + struct DateStamp ds; + int result = -1; + LONG status; + + assert( path_name != NULL ); + + #if defined(CHECK_FOR_NULL_POINTERS) + { + if(path_name == NULL) + { + errno = EFAULT; + goto out; + } + } + #endif /* CHECK_FOR_NULL_POINTERS */ + + if(__check_abort_enabled) + __check_abort(); + + if(times != NULL) + { + time_t seconds; + + seconds = times->modtime; + + if(seconds < UNIX_TIME_OFFSET) + { + errno = EINVAL; + goto out; + } + + seconds -= UNIX_TIME_OFFSET; + + if(__default_locale != NULL) + seconds -= 60 * __default_locale->loc_GMTOffset; + + ds.ds_Days = (seconds / (24 * 60 * 60)); + ds.ds_Minute = (seconds % (24 * 60 * 60)) / 60; + ds.ds_Tick = (seconds % 60) * TICKS_PER_SECOND; + } + else + { + DateStamp(&ds); + } + + #if defined(UNIX_PATH_SEMANTICS) + { + if(__unix_path_semantics) + { + if(__translate_unix_to_amiga_path_name(&path_name,&path_name_nti) != 0) + goto out; + + if(path_name_nti.is_root) + { + errno = EACCES; + goto out; + } + } + } + #endif /* UNIX_PATH_SEMANTICS */ + + PROFILE_OFF(); + status = SetFileDate((STRPTR)path_name,&ds); + PROFILE_ON(); + + if(status == DOSFALSE) + { + __translate_io_error_to_errno(IoErr(),&errno); + goto out; + } + + result = 0; + + out: + + return(result); +} diff --git a/library/wchar_btowc.c b/library/wchar_btowc.c new file mode 100644 index 0000000..bce4c5c --- /dev/null +++ b/library/wchar_btowc.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_btowc.c,v 1.1.1.1 2004-07-26 16:32:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wint_t +btowc(int c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_fgetwc.c b/library/wchar_fgetwc.c new file mode 100644 index 0000000..ec2a355 --- /dev/null +++ b/library/wchar_fgetwc.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_fgetwc.c,v 1.1.1.1 2004-07-26 16:32:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wint_t +fgetwc(FILE *stream) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_fgetws.c b/library/wchar_fgetws.c new file mode 100644 index 0000000..97b9e7a --- /dev/null +++ b/library/wchar_fgetws.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_fgetws.c,v 1.1.1.1 2004-07-26 16:32:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wchar_t * +fgetws(wchar_t *s, int n, FILE *stream) +{ + /* ZZZ unimplemented */ + return(NULL); +} diff --git a/library/wchar_fputwc.c b/library/wchar_fputwc.c new file mode 100644 index 0000000..e816c0a --- /dev/null +++ b/library/wchar_fputwc.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_fputwc.c,v 1.1.1.1 2004-07-26 16:32:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wint_t +fputwc(wchar_t c,FILE *stream) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_fputws.c b/library/wchar_fputws.c new file mode 100644 index 0000000..8ee44fc --- /dev/null +++ b/library/wchar_fputws.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_fputws.c,v 1.1.1.1 2004-07-26 16:32:41 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wint_t +fputws(const wchar_t *s, FILE *stream) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_fwide.c b/library/wchar_fwide.c new file mode 100644 index 0000000..c19ec17 --- /dev/null +++ b/library/wchar_fwide.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_fwide.c,v 1.1.1.1 2004-07-26 16:32:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +fwide(FILE *stream, int orient) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_fwprintf.c b/library/wchar_fwprintf.c new file mode 100644 index 0000000..01e7212 --- /dev/null +++ b/library/wchar_fwprintf.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_fwprintf.c,v 1.1.1.1 2004-07-26 16:32:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +fwprintf(FILE *stream,const wchar_t *format,...) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_fwscanf.c b/library/wchar_fwscanf.c new file mode 100644 index 0000000..a00970e --- /dev/null +++ b/library/wchar_fwscanf.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_fwscanf.c,v 1.1.1.1 2004-07-26 16:32:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +fwscanf(FILE *stream, const wchar_t *format, ...) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_getwc.c b/library/wchar_getwc.c new file mode 100644 index 0000000..374e54d --- /dev/null +++ b/library/wchar_getwc.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_getwc.c,v 1.1.1.1 2004-07-26 16:32:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wint_t +getwc(FILE *stream) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_getwchar.c b/library/wchar_getwchar.c new file mode 100644 index 0000000..f3b2af4 --- /dev/null +++ b/library/wchar_getwchar.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_getwchar.c,v 1.1.1.1 2004-07-26 16:32:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wint_t +getwchar(void) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_headers.h b/library/wchar_headers.h new file mode 100644 index 0000000..e7c8614 --- /dev/null +++ b/library/wchar_headers.h @@ -0,0 +1,49 @@ +/* + * $Id: wchar_headers.h,v 1.1.1.1 2004-07-26 16:32:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#define _WCHAR_HEADERS_H + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#ifndef _MATH_FP_SUPPORT_H +#include "math_fp_support.h" +#endif /* _MATH_FP_SUPPORT_H */ + +/****************************************************************************/ + +#endif /* _WCHAR_HEADERS_H */ diff --git a/library/wchar_mbrlen.c b/library/wchar_mbrlen.c new file mode 100644 index 0000000..5bddf10 --- /dev/null +++ b/library/wchar_mbrlen.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_mbrlen.c,v 1.1.1.1 2004-07-26 16:32:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +size_t +mbrlen(wchar_t *pwc, const char * s, size_t n, mbstate_t *ps) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_mbsinit.c b/library/wchar_mbsinit.c new file mode 100644 index 0000000..63c054e --- /dev/null +++ b/library/wchar_mbsinit.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_mbsinit.c,v 1.1.1.1 2004-07-26 16:32:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +mbsinit(const mbstate_t *ps) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_mbsrtowcs.c b/library/wchar_mbsrtowcs.c new file mode 100644 index 0000000..b37c834 --- /dev/null +++ b/library/wchar_mbsrtowcs.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_mbsrtowcs.c,v 1.1.1.1 2004-07-26 16:32:42 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +size_t +mbsrtowcs(wchar_t *pwcs, const char **src, size_t n, mbstate_t *ps) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_putwc.c b/library/wchar_putwc.c new file mode 100644 index 0000000..95c2f63 --- /dev/null +++ b/library/wchar_putwc.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_putwc.c,v 1.1.1.1 2004-07-26 16:32:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wint_t +putwc(wchar_t c,FILE *stream) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_putwchar.c b/library/wchar_putwchar.c new file mode 100644 index 0000000..1bdd54f --- /dev/null +++ b/library/wchar_putwchar.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_putwchar.c,v 1.1.1.1 2004-07-26 16:32:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wint_t +putwchar(wchar_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_swprintf.c b/library/wchar_swprintf.c new file mode 100644 index 0000000..2f326b0 --- /dev/null +++ b/library/wchar_swprintf.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_swprintf.c,v 1.1.1.1 2004-07-26 16:32:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +swprintf(wchar_t *s, const wchar_t *format, ...) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_swscanf.c b/library/wchar_swscanf.c new file mode 100644 index 0000000..647ce8d --- /dev/null +++ b/library/wchar_swscanf.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_swscanf.c,v 1.1.1.1 2004-07-26 16:32:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +swscanf(wchar_t *s,const wchar_t *format, ...) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_ungetwc.c b/library/wchar_ungetwc.c new file mode 100644 index 0000000..a0c1802 --- /dev/null +++ b/library/wchar_ungetwc.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_ungetwc.c,v 1.1.1.1 2004-07-26 16:32:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wint_t +ungetwc(wint_t c,FILE *stream) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_vfwprintf.c b/library/wchar_vfwprintf.c new file mode 100644 index 0000000..586970e --- /dev/null +++ b/library/wchar_vfwprintf.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_vfwprintf.c,v 1.1.1.1 2004-07-26 16:32:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +vfwprintf(FILE *stream,const wchar_t *format,va_list arg) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_vswprintf.c b/library/wchar_vswprintf.c new file mode 100644 index 0000000..2e8783c --- /dev/null +++ b/library/wchar_vswprintf.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_vswprintf.c,v 1.1.1.1 2004-07-26 16:32:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +vswprintf(char *s, const wchar_t *format,va_list arg) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_vwprintf.c b/library/wchar_vwprintf.c new file mode 100644 index 0000000..ad883ca --- /dev/null +++ b/library/wchar_vwprintf.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_vwprintf.c,v 1.1.1.1 2004-07-26 16:32:43 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +vwprintf(const wchar_t *format,va_list arg) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wcrtomb.c b/library/wchar_wcrtomb.c new file mode 100644 index 0000000..ebb0854 --- /dev/null +++ b/library/wchar_wcrtomb.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcrtomb.c,v 1.1.1.1 2004-07-26 16:32:44 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +size_t +wcrtomb(char *s, wchar_t wc, mbstate_t *ps) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wcscat.c b/library/wchar_wcscat.c new file mode 100644 index 0000000..64b047d --- /dev/null +++ b/library/wchar_wcscat.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcscat.c,v 1.1.1.1 2004-07-26 16:32:44 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wchar_t * +wcscat(wchar_t *dest, const wchar_t *src) +{ + /* ZZZ unimplemented */ + return(NULL); +} diff --git a/library/wchar_wcschr.c b/library/wchar_wcschr.c new file mode 100644 index 0000000..536a8ae --- /dev/null +++ b/library/wchar_wcschr.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcschr.c,v 1.1.1.1 2004-07-26 16:32:44 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wchar_t * +wcschr(const wchar_t *s, wchar_t c) +{ + /* ZZZ unimplemented */ + return(NULL); +} diff --git a/library/wchar_wcscmp.c b/library/wchar_wcscmp.c new file mode 100644 index 0000000..5185a77 --- /dev/null +++ b/library/wchar_wcscmp.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcscmp.c,v 1.1.1.1 2004-07-26 16:32:44 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +wcscmp(const wchar_t *s1, const wchar_t * s2) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wcscpy.c b/library/wchar_wcscpy.c new file mode 100644 index 0000000..5063aa2 --- /dev/null +++ b/library/wchar_wcscpy.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcscpy.c,v 1.1.1.1 2004-07-26 16:32:44 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wchar_t * +wcscpy(wchar_t *dest, const wchar_t *src) +{ + /* ZZZ unimplemented */ + return(NULL); +} diff --git a/library/wchar_wcsftime.c b/library/wchar_wcsftime.c new file mode 100644 index 0000000..3c3b763 --- /dev/null +++ b/library/wchar_wcsftime.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcsftime.c,v 1.1.1.1 2004-07-26 16:32:44 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +size_t +wcsftime(wchar_t *s, size_t maxsize, const wchar_t *format, const struct tm *timeptr) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wcslen.c b/library/wchar_wcslen.c new file mode 100644 index 0000000..0982717 --- /dev/null +++ b/library/wchar_wcslen.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcslen.c,v 1.1.1.1 2004-07-26 16:32:44 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +size_t +wcslen(const wchar_t *s) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wcsncat.c b/library/wchar_wcsncat.c new file mode 100644 index 0000000..5503a60 --- /dev/null +++ b/library/wchar_wcsncat.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcsncat.c,v 1.1.1.1 2004-07-26 16:32:44 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wchar_t * +wcsncat(wchar_t *dest, const wchar_t *src, size_t n) +{ + /* ZZZ unimplemented */ + return(NULL); +} diff --git a/library/wchar_wcsncmp.c b/library/wchar_wcsncmp.c new file mode 100644 index 0000000..d57406f --- /dev/null +++ b/library/wchar_wcsncmp.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcsncmp.c,v 1.1.1.1 2004-07-26 16:32:45 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wcsncpy.c b/library/wchar_wcsncpy.c new file mode 100644 index 0000000..74752cf --- /dev/null +++ b/library/wchar_wcsncpy.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcsncpy.c,v 1.1.1.1 2004-07-26 16:32:45 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wchar_t * +wcsncpy(wchar_t *dest, const wchar_t *src, size_t n) +{ + /* ZZZ unimplemented */ + return(NULL); +} diff --git a/library/wchar_wcspbrk.c b/library/wchar_wcspbrk.c new file mode 100644 index 0000000..4f57af5 --- /dev/null +++ b/library/wchar_wcspbrk.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcspbrk.c,v 1.1.1.1 2004-07-26 16:32:45 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wchar_t +wcspbrk(const wchar_t *s, const wchar_t *set) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wcsrtombs.c b/library/wchar_wcsrtombs.c new file mode 100644 index 0000000..44e582f --- /dev/null +++ b/library/wchar_wcsrtombs.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcsrtombs.c,v 1.1.1.1 2004-07-26 16:32:45 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +size_t +wcsrtombs(char *s, const wchar_t **src, size_t n, mbstate_t *ps) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wcsspn.c b/library/wchar_wcsspn.c new file mode 100644 index 0000000..49e1fb2 --- /dev/null +++ b/library/wchar_wcsspn.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcsspn.c,v 1.1.1.1 2004-07-26 16:32:45 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +size_t +wcsspn(const wchar_t *s, const wchar_t *set) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wcstod.c b/library/wchar_wcstod.c new file mode 100644 index 0000000..868bbea --- /dev/null +++ b/library/wchar_wcstod.c @@ -0,0 +1,49 @@ +/* + * $Id: wchar_wcstod.c,v 1.1.1.1 2004-07-26 16:32:45 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +double +wcstod(const wchar_t *str, wchar_t **ptr) +{ + /* ZZZ unimplemented */ + return(0); +} + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/wchar_wcstok.c b/library/wchar_wcstok.c new file mode 100644 index 0000000..2fe1bdd --- /dev/null +++ b/library/wchar_wcstok.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcstok.c,v 1.1.1.1 2004-07-26 16:32:45 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wchar_t * +wcstok(wchar_t *str, const wchar_t *set) +{ + /* ZZZ unimplemented */ + return(NULL); +} diff --git a/library/wchar_wcstol.c b/library/wchar_wcstol.c new file mode 100644 index 0000000..89d7ba6 --- /dev/null +++ b/library/wchar_wcstol.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcstol.c,v 1.1.1.1 2004-07-26 16:32:46 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +long +wcstol(const wchar_t *str, wchar_t **ptr, int base) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wcstoul.c b/library/wchar_wcstoul.c new file mode 100644 index 0000000..115fa42 --- /dev/null +++ b/library/wchar_wcstoul.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcstoul.c,v 1.1.1.1 2004-07-26 16:32:46 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +unsigned long +wcstoul(const wchar_t *str, wchar_t **ptr, int base) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wcsxfrm.c b/library/wchar_wcsxfrm.c new file mode 100644 index 0000000..5a21ef0 --- /dev/null +++ b/library/wchar_wcsxfrm.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wcsxfrm.c,v 1.1.1.1 2004-07-26 16:32:46 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +size_t +wcsxfrm(wchar_t *dest, const wchar_t *src, size_t len) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wmemchr.c b/library/wchar_wmemchr.c new file mode 100644 index 0000000..1de967c --- /dev/null +++ b/library/wchar_wmemchr.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wmemchr.c,v 1.1.1.1 2004-07-26 16:32:46 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wchar_t * +wmemchr(const wchar_t *ptr, wchar_t val, size_t len) +{ + /* ZZZ unimplemented */ + return(NULL); +} diff --git a/library/wchar_wmemcmp.c b/library/wchar_wmemcmp.c new file mode 100644 index 0000000..895ce3f --- /dev/null +++ b/library/wchar_wmemcmp.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wmemcmp.c,v 1.1.1.1 2004-07-26 16:32:46 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +wmemcmp(const wchar_t *ptr1, const wchar_t *ptr2, size_t len) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wmemcpy.c b/library/wchar_wmemcpy.c new file mode 100644 index 0000000..014e125 --- /dev/null +++ b/library/wchar_wmemcpy.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wmemcpy.c,v 1.1.1.1 2004-07-26 16:32:46 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wchar_t * +wmemcpy(wchar_t *dest, const wchar_t *src, size_t len) +{ + /* ZZZ unimplemented */ + return(NULL); +} diff --git a/library/wchar_wmemmove.c b/library/wchar_wmemmove.c new file mode 100644 index 0000000..1856d98 --- /dev/null +++ b/library/wchar_wmemmove.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wmemmove.c,v 1.1.1.1 2004-07-26 16:32:46 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wchar_t * +wmemmove(wchar_t *dest, const wchar_t * src, size_t len) +{ + /* ZZZ unimplemented */ + return(NULL); +} diff --git a/library/wchar_wmemset.c b/library/wchar_wmemset.c new file mode 100644 index 0000000..5c5e311 --- /dev/null +++ b/library/wchar_wmemset.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wmemset.c,v 1.1.1.1 2004-07-26 16:32:46 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +wchar_t * +wmemset(wchar_t *ptr, int val, size_t len) +{ + /* ZZZ unimplemented */ + return(NULL); +} diff --git a/library/wchar_wprintf.c b/library/wchar_wprintf.c new file mode 100644 index 0000000..901fa75 --- /dev/null +++ b/library/wchar_wprintf.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wprintf.c,v 1.1.1.1 2004-07-26 16:32:47 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +wprintf(const wchar_t *format, ...) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wscanf.c b/library/wchar_wscanf.c new file mode 100644 index 0000000..b5c0647 --- /dev/null +++ b/library/wchar_wscanf.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wscanf.c,v 1.1.1.1 2004-07-26 16:32:47 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +wscanf(const wchar_t *format, ...) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wchar_wscoll.c b/library/wchar_wscoll.c new file mode 100644 index 0000000..1b8ce78 --- /dev/null +++ b/library/wchar_wscoll.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wscoll.c,v 1.1.1.1 2004-07-26 16:32:47 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +wscoll(const wchar_t *s1, const wchar_t *s2) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_headers.h b/library/wctype_headers.h new file mode 100644 index 0000000..ca07e90 --- /dev/null +++ b/library/wctype_headers.h @@ -0,0 +1,43 @@ +/* + * $Id: wctype_headers.h,v 1.1.1.1 2004-07-26 16:32:47 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#define _WCTYPE_HEADERS_H + +/****************************************************************************/ + +#include + +/****************************************************************************/ + +#endif /* _WCTYPE_HEADERS_H */ diff --git a/library/wctype_iswalnum.c b/library/wctype_iswalnum.c new file mode 100644 index 0000000..95c73a6 --- /dev/null +++ b/library/wctype_iswalnum.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_iswalnum.c,v 1.1.1.1 2004-07-26 16:32:47 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +iswalnum(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_iswalpha.c b/library/wctype_iswalpha.c new file mode 100644 index 0000000..72514e5 --- /dev/null +++ b/library/wctype_iswalpha.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_iswalpha.c,v 1.1.1.1 2004-07-26 16:32:47 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +iswalpha(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_iswcntrl.c b/library/wctype_iswcntrl.c new file mode 100644 index 0000000..f8f1c89 --- /dev/null +++ b/library/wctype_iswcntrl.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_iswcntrl.c,v 1.1.1.1 2004-07-26 16:32:47 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +iswcntrl(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_iswctype.c b/library/wctype_iswctype.c new file mode 100644 index 0000000..39e988b --- /dev/null +++ b/library/wctype_iswctype.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_iswctype.c,v 1.1.1.1 2004-07-26 16:32:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +iswctype(wint_t c, wctype_t desc) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_iswdigit.c b/library/wctype_iswdigit.c new file mode 100644 index 0000000..4cd2faa --- /dev/null +++ b/library/wctype_iswdigit.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_iswdigit.c,v 1.1.1.1 2004-07-26 16:32:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +iswdigit(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_iswgraph.c b/library/wctype_iswgraph.c new file mode 100644 index 0000000..7412b1f --- /dev/null +++ b/library/wctype_iswgraph.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_iswgraph.c,v 1.1.1.1 2004-07-26 16:32:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +iswgraph(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_iswlower.c b/library/wctype_iswlower.c new file mode 100644 index 0000000..0c01844 --- /dev/null +++ b/library/wctype_iswlower.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_iswlower.c,v 1.1.1.1 2004-07-26 16:32:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +iswlower(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_iswprint.c b/library/wctype_iswprint.c new file mode 100644 index 0000000..9f70d43 --- /dev/null +++ b/library/wctype_iswprint.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_iswprint.c,v 1.1.1.1 2004-07-26 16:32:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +iswprint(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_iswpunc.c b/library/wctype_iswpunc.c new file mode 100644 index 0000000..04cd1bc --- /dev/null +++ b/library/wctype_iswpunc.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_iswpunc.c,v 1.1.1.1 2004-07-26 16:32:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +iswpunc(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_iswspace.c b/library/wctype_iswspace.c new file mode 100644 index 0000000..a00e0a1 --- /dev/null +++ b/library/wctype_iswspace.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_iswspace.c,v 1.1.1.1 2004-07-26 16:32:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +iswspace(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_iswupper.c b/library/wctype_iswupper.c new file mode 100644 index 0000000..637b183 --- /dev/null +++ b/library/wctype_iswupper.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_iswupper.c,v 1.1.1.1 2004-07-26 16:32:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +iswupper(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_iswxdigit.c b/library/wctype_iswxdigit.c new file mode 100644 index 0000000..26c763a --- /dev/null +++ b/library/wctype_iswxdigit.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_iswxdigit.c,v 1.1.1.1 2004-07-26 16:32:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +int +iswxdigit(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_towctrans.c b/library/wctype_towctrans.c new file mode 100644 index 0000000..a1a85fb --- /dev/null +++ b/library/wctype_towctrans.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_towctrans.c,v 1.1.1.1 2004-07-26 16:32:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +wint_t +towctrans(wint_t c, wctrans_t desc) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_towlower.c b/library/wctype_towlower.c new file mode 100644 index 0000000..0190160 --- /dev/null +++ b/library/wctype_towlower.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_towlower.c,v 1.1.1.1 2004-07-26 16:32:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +wint_t +towlower(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_towupper.c b/library/wctype_towupper.c new file mode 100644 index 0000000..3bfff3c --- /dev/null +++ b/library/wctype_towupper.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_towupper.c,v 1.1.1.1 2004-07-26 16:32:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +wint_t +towupper(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_wctrans.c b/library/wctype_wctrans.c new file mode 100644 index 0000000..421cd0a --- /dev/null +++ b/library/wctype_wctrans.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_wctrans.c,v 1.1.1.1 2004-07-26 16:32:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +wctrans_t +wctrans(const char *property) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/library/wctype_wctype.c b/library/wctype_wctype.c new file mode 100644 index 0000000..20adc8e --- /dev/null +++ b/library/wctype_wctype.c @@ -0,0 +1,45 @@ +/* + * $Id: wctype_wctype.c,v 1.1.1.1 2004-07-26 16:32:49 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCTYPE_HEADERS_H +#include +#endif /* _WCTYPE_HEADERS_H */ + +/****************************************************************************/ + +wctype_t +wctype(const char *property) +{ + /* ZZZ unimplemented */ + return(0); +} diff --git a/test_programs/clib-bug.c b/test_programs/clib-bug.c new file mode 100644 index 0000000..c3a554d --- /dev/null +++ b/test_programs/clib-bug.c @@ -0,0 +1,74 @@ +#include +#include + +#define LINEBUFLENGTH 180 + +#define STRIP_LF(str) (str[strlen(str)-1]=0) +void invert_str(char * in) +{ +char t; +while(t=*in) + { + *in++=~t; + } +} + +int main(int i, char *c[]) +{ +char dest_fname[80], in_linebuffer[LINEBUFLENGTH]; +FILE * fileout, * filein; + +if(i>1) + { + sprintf(dest_fname, "%s.c", c[1]); + + fileout=fopen(dest_fname, "w"); + filein =fopen(c[1], "r"); + + if(fileout && filein) + { + fgets(in_linebuffer, LINEBUFLENGTH, filein); + STRIP_LF(in_linebuffer); + invert_str(in_linebuffer); + fputs("char *s_leading=\"", fileout); + fputs(in_linebuffer, fileout); + fputs("\";\n", fileout); + + fputs("char *s_messages[]={\n", fileout); + + while(fgets(in_linebuffer, LINEBUFLENGTH, filein)) + { + STRIP_LF(in_linebuffer); + invert_str(in_linebuffer); + + fputs("\"", fileout); + fputs(in_linebuffer, fileout); + fputs("\",\n", fileout); + } + fputs("};\n", fileout); + fputs("unsigned s_mess_num = sizeof(s_messages)/sizeof(char *);\n", fileout); + fclose(filein); + fclose(fileout); + } + } +return 0; +} + +/* +What's this stuff for ? I use it in SP_Engine to hide the usual bunch of "secret +messages". As you can see, the strings are simply not'ed . +This source shows both flaws: fgets() and the missing buffer flush. You can +change the while() statement with + +while(!feof(filein)) + { + fgets(in_linebuffer, LINEBUFLENGTH, filein); +.... + +This way you'll workaround the first problem. +The second issue manifests itself this way: the last two fputs() followed by the +fclose() don't do anything: no "};\n" and no "unsigned....." lines are output to +'fileout'. With SAS, it works perfectly. Converting the source to dos.library +calls also works perfectly. I wonder if there's some kind of strange interaction +with the dos/shell updates. +*/ diff --git a/test_programs/fgets_test.c b/test_programs/fgets_test.c new file mode 100644 index 0000000..7190b8d --- /dev/null +++ b/test_programs/fgets_test.c @@ -0,0 +1,41 @@ +/* + * $Id: fgets_test.c,v 1.1.1.1 2004-07-26 16:36:07 obarthel Exp $ + * + * :ts=4 + */ + +/****************************************************************************/ + +#include +#include + +/****************************************************************************/ + +int +main(int argc,char ** argv) +{ + char line[256]; + size_t len; + FILE * in; + int i; + + for(i = 1 ; i < argc ; i++) + { + in = fopen(argv[i],"rb"); + if(in != NULL) + { + while(fgets(line,sizeof(line),in) != NULL) + { + len = strlen(line); + while(len > 0 && (line[len-1] == '\n' || line[len-1] == '\r')) + line[--len] = '\0'; + + printf("%s\n",line); + } + + fclose(in); + } + } + + return(0); +} diff --git a/test_programs/iotest.c b/test_programs/iotest.c new file mode 100644 index 0000000..8f5c269 --- /dev/null +++ b/test_programs/iotest.c @@ -0,0 +1,44 @@ +#include +#include +#include + +#define FILE_SIZE 2048 +#define WRITE_SIZE 32 + +char FileData[FILE_SIZE]; + +void CreateFile(char *filename) +{ + FILE *file; + + if (file = fopen(filename,"w")) { + memset(FileData,'0',FILE_SIZE); + memset(FileData,'-',WRITE_SIZE); + fwrite(FileData,1,FILE_SIZE,file); + fclose(file); + } +} + +void ReadWriteFile(char *filename) +{ + FILE *file; + + if (file = fopen(filename,"r+")) { + fseek(file,0,SEEK_SET); + fread(FileData,1,FILE_SIZE,file); + fseek(file,0,SEEK_SET); + memset(FileData,'1',WRITE_SIZE); + fwrite(FileData,1,WRITE_SIZE,file); + fclose(file); + } +} + +int main(int argc, char **argv) +{ + if (argc > 1) { + CreateFile(argv[1]); + ReadWriteFile(argv[1]); + } + + return 0; +} diff --git a/test_programs/printf_g_test.c b/test_programs/printf_g_test.c new file mode 100644 index 0000000..0a9edcb --- /dev/null +++ b/test_programs/printf_g_test.c @@ -0,0 +1,12 @@ +#include + +int __debug_level = 2; + +int main(void) +{ + double val = 0.0001; + + printf("%g\n", val); + + return(0); +} diff --git a/test_programs/printf_test.c b/test_programs/printf_test.c new file mode 100644 index 0000000..ddab456 --- /dev/null +++ b/test_programs/printf_test.c @@ -0,0 +1,195 @@ +#include +#include + +double x; + +void +print_format_int(const char * format_string,int parameter1,int parameter2) +{ + printf("\""); + printf(format_string,parameter1); + printf("\"\t"); + + printf("Value = % d, Format = \"%s\"\n",parameter1,format_string); + + printf("\""); + printf(format_string,parameter2); + printf("\"\t"); + + printf("Value = % d, Format = \"%s\"\n",parameter2,format_string); +} + +void +print_format_char(const char * format_string,char parameter) +{ + printf("\""); + printf(format_string,parameter); + printf("\"\t"); + + printf("Value = '%c', Format = \"%s\"\n",parameter,format_string); +} + +void +print_format_string(const char * format_string,const char *parameter1,const char *parameter2) +{ + printf("\""); + printf(format_string,parameter1); + printf("\"\t"); + + printf("Value = \"%s\", Format = \"%s\"\n",parameter1,format_string); + + printf("\""); + printf(format_string,parameter2); + printf("\"\t"); + + printf("Value = \"%s\", Format = \"%s\"\n",parameter2,format_string); +} + +void +print_format_float(const char * format_string,double parameter1,double parameter2) +{ + printf("\""); + printf(format_string,parameter1); + printf("\"\t"); + + printf("Value = % f, Format = \"%s\"\n",parameter1,format_string); + + printf("\""); + printf(format_string,parameter2); + printf("\"\t"); + + printf("Value = % f, Format = \"%s\"\n",parameter2,format_string); +} + +int +main(void) +{ + /* + unsigned long foo[2] = { 0x41f00000, 0 }; + + memcpy(&x,foo,sizeof(x)); + + printf("%.20g\n",x); + */ + + print_format_int("%12d",45,-45); + print_format_int("%012d",45,-45); + print_format_int("% 012d",45,-45); + print_format_int("%+12d",45,-45); + print_format_int("%+012d",45,-45); + print_format_int("%-12d",45,-45); + print_format_int("%- 12d",45,-45); + print_format_int("%-+12d",45,-45); + print_format_int("%12.4d",45,-45); + print_format_int("%-12.4d",45,-45); + print_format_int("%12.0d",45,-45); + + printf("\n"); + + print_format_int("%14u",45,-45); + print_format_int("%014u",45,-45); + print_format_int("%#14u",45,-45); + print_format_int("%#014u",45,-45); + print_format_int("%-14u",45,-45); + print_format_int("%-#14u",45,-45); + print_format_int("%14.4u",45,-45); + print_format_int("%-14.4u",45,-45); + print_format_int("%14.0u",45,-45); + + printf("\n"); + + print_format_int("%14o",45,-45); + print_format_int("%014o",45,-45); + print_format_int("%#14o",45,-45); + print_format_int("%#014o",45,-45); + print_format_int("%-14o",45,-45); + print_format_int("%-#14o",45,-45); + print_format_int("%14.4o",45,-45); + print_format_int("%-14.4o",45,-45); + print_format_int("%14.0o",45,-45); + + printf("\n"); + + print_format_int("%12x",45,-45); + print_format_int("%012x",45,-45); + print_format_int("%#12X",45,-45); + print_format_int("%#012X",45,-45); + print_format_int("%-12x",45,-45); + print_format_int("%-#12x",45,-45); + print_format_int("%12.4x",45,-45); + print_format_int("%-12.4x",45,-45); + print_format_int("%12.0x",45,-45); + + printf("\n"); + + print_format_char("%12c",'*'); + print_format_char("%012c",'*'); + print_format_char("%-12c",'*'); + print_format_char("%12.0c",'*'); + + printf("\n"); + + print_format_string("%12s","zap","longish"); + print_format_string("%12.5s","zap","longish"); + print_format_string("%012s","zap","longish"); + print_format_string("%-12s","zap","longish"); + print_format_string("%12.0s","zap","longish"); + + printf("\n"); + + print_format_float("%10.2f",12.678,-12.678); + print_format_float("%010.2f",12.678,-12.678); + print_format_float("% 010.2f",12.678,-12.678); + print_format_float("%+10.2f",12.678,-12.678); + print_format_float("%+010.2f",12.678,-12.678); + print_format_float("%-10.2f",12.678,-12.678); + print_format_float("%- 10.2f",12.678,-12.678); + print_format_float("%-+10.4f",12.678,-12.678); + print_format_float("%f",12.678,-12.678); + print_format_float("%10f",12.678,-12.678); + print_format_float("%10.0f",12.678,-12.678); + + printf("\n"); + + print_format_float("%10.2e",12.678,-12.678); + print_format_float("%010.2e",12.678,-12.678); + print_format_float("% 010.2e",12.678,-12.678); + print_format_float("%+10.2E",12.678,-12.678); + print_format_float("%+010.2E",12.678,-12.678); + print_format_float("%-10.2e",12.678,-12.678); + print_format_float("%- 10.2e",12.678,-12.678); + print_format_float("%-+10.2e",12.678,-12.678); + print_format_float("%e",12.678,-12.678); + print_format_float("%10e",12.678,-12.678); + print_format_float("%10.0e",12.678,-12.678); + + printf("\n"); + + print_format_float("%10.2g",12.678,-12.678); + print_format_float("%010.2g",12.678,-12.678); + print_format_float("% 010.2g",12.678,-12.678); + print_format_float("%+10.2G",12.678,-12.678); + print_format_float("%+010.2G",12.678,-12.678); + print_format_float("%-10.2g",12.678,-12.678); + print_format_float("%- 10.2g",12.678,-12.678); + print_format_float("%-+10.2g",12.678,-12.678); + print_format_float("%g",12.678,-12.678); + print_format_float("%10g",12.678,-12.678); + print_format_float("%10.0g",12.678,-12.678); + + printf("\n"); + + print_format_float("%10.2g",0.678,-0.678); + print_format_float("%010.2g",0.678,-0.678); + print_format_float("% 010.2g",0.678,-0.678); + print_format_float("%+10.2G",0.678,-0.678); + print_format_float("%+010.2G",0.678,-0.678); + print_format_float("%-10.2g",0.678,-0.678); + print_format_float("%- 10.2g",0.678,-0.678); + print_format_float("%-+10.2g",0.678,-0.678); + print_format_float("%g",0.678,-0.678); + print_format_float("%10g",0.678,-0.678); + print_format_float("%10.0g",0.678,-0.678); + + return(0); +} diff --git a/test_programs/sscanf_test.c b/test_programs/sscanf_test.c new file mode 100644 index 0000000..cb9abb0 --- /dev/null +++ b/test_programs/sscanf_test.c @@ -0,0 +1,84 @@ +#include +#include + +int +main(void) +{ + int first, second, num; + int n,a,b,c; + char str[4]; + + num = sscanf("6", "%d %d", &first, &second); + + printf("%d %d\n", num, first); + + a = b = c = 0; + n = sscanf("","%*d,%d,%d",&a,&b,&c); + printf("n = %d, a = %d, b = %d, c = %d\n",n,a,b,c); + + a = b = c = 0; + n = sscanf("1,2,3","%*d,%d,%d",&a,&b,&c); + printf("n = %d, a = %d, b = %d, c = %d\n",n,a,b,c); + + a = b = c = 0; + n = sscanf("1,2","%*d,%d,%d",&a,&b,&c); + printf("n = %d, a = %d, b = %d, c = %d\n",n,a,b,c); + + a = b = c = 0; + n = sscanf("asdf","*d,d,d",&a,&b,&c); + printf("n = %d, a = %d, b = %d, c = %d\n",n,a,b,c); + + memset(str,0,sizeof(str)); + n = sscanf("asdf","%[abc]",str); + printf("n = %d, str = '%s'\n",n,str); + + memset(str,0,sizeof(str)); + n = sscanf("asdbbfc","%[abc]",str); + printf("n = %d, str = '%s'\n",n,str); + + memset(str,0,sizeof(str)); + n = sscanf("","%[abc]",str); + printf("n = %d, str = '%s'\n",n,str); + + memset(str,0,sizeof(str)); + n = sscanf("abcdef","%[abc]",str); + printf("n = %d, str = '%s'\n",n,str); + + a = b = c = 0; + n = sscanf("-","%d",&a); + printf("n = %d, a = %d\n",n,a); + + a = b = c = 0; + n = sscanf("-4,-","%d,%d",&a,&b); + printf("n = %d, a = %d, b = %d\n",n,a,b); + + memset(str,0,sizeof(str)); + n = sscanf("1 abc","%d %4c",&a,str); + printf("n = %d, a = %d, str = '%s'\n",n,a,str); + + memset(str,0,sizeof(str)); + n = sscanf("abc","%4c",&a,str); + printf("n = %d, str = '%s'\n",n,str); + + a = 0; + n = sscanf("17","%i",&a); + printf("n = %d, a = %d\n",n,a); + + a = 0; + n = sscanf("017","%i",&a); + printf("n = %d, a = %d\n",n,a); + + a = 0; + n = sscanf("0x17","%i",&a); + printf("n = %d, a = %d\n",n,a); + + a = 0; + n = sscanf("0x80000000","%i",&a); + printf("n = %d, a = %u\n",n,a); + + memset(str,0,sizeof(str)); + n = sscanf("1,e","%*d,%[abc]",str); + printf("n = %d, str = '%s'\n",n,str); + + return(0); +} diff --git a/test_programs/stack_extension_test.c b/test_programs/stack_extension_test.c new file mode 100644 index 0000000..589dbb2 --- /dev/null +++ b/test_programs/stack_extension_test.c @@ -0,0 +1,31 @@ +/* gcc -mstackextend -o stack_extension_test stack_extension_test.c */ + +#include +#include + +void +recursive_function(char *data,int data_size,int level) +{ + char local_data[10000]; + char line[10]; + int c; + + data_size += sizeof(local_data); + level++; + + printf("recursion level=%d, size=%d; continue? ",level,data_size); + + fgets(line,sizeof(line),stdin); + c = toupper(line[0]); + + if(c == 'Y') + recursive_function(local_data,data_size,level); +} + +int +main(int argc,char ** argv) +{ + recursive_function(NULL,0,0); + + return(0); +} diff --git a/test_programs/stack_size_test.c b/test_programs/stack_size_test.c new file mode 100644 index 0000000..eac5df5 --- /dev/null +++ b/test_programs/stack_size_test.c @@ -0,0 +1,15 @@ +#include + +int __stack_size = 60000; + +int +main(void) +{ + int first, second, num; + + num = sscanf("6", "%d %d", &first, &second); + + printf("%d %d\n", num, first); + + return(0); +} diff --git a/test_programs/test.c b/test_programs/test.c new file mode 100644 index 0000000..174916d --- /dev/null +++ b/test_programs/test.c @@ -0,0 +1,241 @@ +/* + * $Id: test.c,v 1.1.1.1 2004-07-26 16:36:08 obarthel Exp $ + * + * :ts=4 + */ + +/****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +/****************************************************************************/ + +/*int __stack_size = 20000;*/ + +/****************************************************************************/ + +#if defined(__GNUC__) + +void __attribute__ ((constructor)) +constructor_test1(void) +{ + fprintf(stderr,"constructor #1 called\n"); +} + +void __attribute__ ((constructor)) +constructor_test2(void) +{ + fprintf(stderr,"constructor #2 called\n"); +} + +void __attribute__ ((destructor)) +destructor_test1(void) +{ + fprintf(stderr,"destructor #1 called\n"); +} + +void __attribute__ ((destructor)) +destructor_test2(void) +{ + fprintf(stderr,"destructor #2 called\n"); +} + +void __attribute__ ((destructor)) +destructor_test3(void) +{ + fprintf(stderr,"destructor #3 called\n"); +} + +#endif /* __GNUC__ */ + +/****************************************************************************/ + +int foo = 3; +int bar = 9; + +/****************************************************************************/ + +#if 1 +int +main(int argc,char ** argv) +{ + time_t now; + int i,j,k; + long n,r; + + for(i = 0 ; i < argc ; i++) + printf("%2d) \"%s\"\n",i,argv[i]); + + printf("div %d mod %d\n",foo / 2,bar % 4); + + time(&now); + printf("%s",ctime(&now)); + + #if defined(IEEE_FLOATING_POINT_SUPPORT) || defined(M68881_FLOATING_POINT_SUPPORT) + { + const double pi = 3.14159265358979323846; + const double ten = 10.0; + const double quarter = 0.25; + const double thousand = 1000.0; + const double foo = 4 * atan((double)1); + float f1; + double d1; + + printf("pi=%3.1f (float)\n",pi); + printf("pi=%.21e (exponential)\n",pi); + printf("pi=%g (float/exponential)\n",pi); + + printf("ten=%f (float)\n",ten); + printf("ten=%.21e (exponential)\n",ten); + printf("ten=%g (float/exponential)\n",ten); + + printf("thousand=%f (float)\n",thousand); + printf("thousand=%.21e (exponential)\n",thousand); + printf("thousand=%g (float/exponential)\n",thousand); + + printf("quarter=%f (float)\n",quarter); + printf("quarter=%.21e (exponential)\n",quarter); + printf("quarter=%g (float/exponential)\n",quarter); + + printf("foo=%f (float)\n",foo); + printf("foo=%.21e (exponential)\n",foo); + printf("foo=%g (float/exponential)\n",foo); + + printf("32 bit float = %f\n",4294967295.0); + printf("32+1 bit float = %f\n",-4294967295.0); + printf("big float on the edge = %f\n",4294967296.0); + printf("big float = %f\n",429496729654321.0); + printf("small float = %f\n",-429496729654321.0); + + f1 = d1 = 9; + + r = sscanf("13.24 1.324","%f %lf",&f1,&d1); + printf("r = %ld, f1 = %f, d1 = %f\n",r,f1,d1); + } + #endif + + #ifndef NDEBUG + { + char * allocation; + + allocation = malloc(4); + if(allocation != NULL) + { + strcpy(allocation,"....FOO"); + strcpy(allocation-3,"bar"); + } + } + #endif /* NDEBUG */ + + printf("hex 0x%08x\n",1); + printf("hex 0x%08x\n",1); + printf("hex 0x%08x\n",2); + printf("big int %d\n",0x80000000L); + printf("converted big int %d\n",atoi("-2147483648")); + + r = sscanf("1324","%lx",&n); + printf("r = %ld, n = %ld\n",r,n); + + r = sscanf("1234567890","%4d%3d%3d",&i,&j,&k); + printf("r = %ld, i = %d, j = %d, k = %d\n",r,i,j,k); + + /*#if defined(IEEE_FLOATING_POINT_SUPPORT) || defined(M68881_FLOATING_POINT_SUPPORT) + { + const char *arg = "100x100"; + float xres = 0, yres = 0; + + printf("%d: ", sscanf(arg, "%fx%f", &xres, &yres)); + printf("%.02fx%.02f\n", xres, yres); + } + #endif*/ + + if(argc > 1) + { + DIR * dir; + + dir = opendir(argv[1]); + if(dir != NULL) + { + struct dirent *d; + struct stat st; + + chdir(argv[1]); + + while((d = readdir(dir)) != NULL) + { + if(stat(d->d_name,&st) == 0) + printf("%s%s\n",d->d_name,S_ISDIR(st.st_mode) ? " (dir)" : ""); + } + + closedir(dir); + } + } + + return(0); +} +#endif + +/****************************************************************************/ + +#if 0 + +#define LINEBUFLENGTH 180 + +#define STRIP_LF(str) (str[strlen(str)-1]=0) +void invert_str(char * in) +{ +char t; +while(t=*in) + { + *in++=~t; + } +} + +int main(int i, char *c[]) +{ +char dest_fname[80], in_linebuffer[LINEBUFLENGTH]; +FILE * fileout, * filein; + +if(i>1) + { + sprintf(dest_fname, "%s.c", c[1]); + + fileout=fopen(dest_fname, "w"); + filein =fopen(c[1], "r"); + + if(fileout && filein) + { + fgets(in_linebuffer, LINEBUFLENGTH, filein); + STRIP_LF(in_linebuffer); + invert_str(in_linebuffer); + fputs("char *s_leading=\"", fileout); + fputs(in_linebuffer, fileout); + fputs("\";\n", fileout); + + fputs("char *s_messages[]={\n", fileout); + + while(fgets(in_linebuffer, LINEBUFLENGTH, filein)) + { + STRIP_LF(in_linebuffer); + invert_str(in_linebuffer); + + fputs("\"", fileout); + fputs(in_linebuffer, fileout); + fputs("\",\n", fileout); + } + fputs("};\n", fileout); + fputs("unsigned s_mess_num = sizeof(s_messages)/sizeof(char *);\n", fileout); + fclose(filein); + fclose(fileout); + } + } +return 0; +} + +#endif diff --git a/test_programs/translate_test.c b/test_programs/translate_test.c new file mode 100644 index 0000000..9bf7c7e --- /dev/null +++ b/test_programs/translate_test.c @@ -0,0 +1,39 @@ +/* + * $Id: translate_test.c,v 1.1.1.1 2004-07-26 16:36:08 obarthel Exp $ + * + * :ts=4 + */ + +#include +#include +#include +#include + +extern char __current_path_name[]; + +int +main(int argc,char ** argv) +{ + struct name_translation_info nti; + char * name; + int error; + int i; + + /*strcpy(__current_path_name,"/absolute_path_name/whatever");*/ + + for(i = 1 ; i < argc ; i++) + { + name = argv[i]; + + printf("'%s' -> ",name); + + error = __translate_unix_to_amiga_path_name(&name,&nti); + /*error = __translate_amiga_to_unix_path_name(&name,&nti);*/ + if(error == 0) + printf("'%s'\n",name); + else + printf("%s\n",strerror(error)); + } + + return(0); +}