├── .gitignore ├── .travis.yml ├── LICENSE ├── LICENSE.mit ├── README.md ├── amd64 └── include │ ├── atomic.h │ ├── crt_arch.h │ ├── float.h │ ├── stdarg.h │ └── ureg.h ├── external_example ├── Makefile.ape └── hiape.c ├── include ├── Plan9libnet.h ├── alloca.h ├── ar.h ├── arpa │ └── inet.h ├── assert.h ├── complex.h ├── ctype.h ├── cursor.h ├── dirent.h ├── draw.h ├── endian.h ├── errno.h ├── error.h ├── event.h ├── fcntl.h ├── features.h ├── fmt.h ├── fnmatch.h ├── getopt.h ├── glob.h ├── grp.h ├── inttypes.h ├── iso646.h ├── keyboard.h ├── lib9.h ├── libgen.h ├── libintl.h ├── libl.h ├── libnet.h ├── libsec.h ├── libv.h ├── limits.h ├── locale.h ├── lock.h ├── math.h ├── mouse.h ├── mp.h ├── netdb.h ├── netinet │ ├── in.h │ └── tcp.h ├── pwd.h ├── qlock.h ├── regex.h ├── regexp.h ├── setjmp.h ├── signal.h ├── stdbool.h ├── stddef.h ├── stdint.h ├── stdio.h ├── stdio_ext.h ├── stdlib.h ├── string.h ├── strings.h ├── sys │ ├── errno.h │ ├── ioctl.h │ ├── limits.h │ ├── param.h │ ├── pty.h │ ├── resource.h │ ├── select.h │ ├── socket.h │ ├── stat.h │ ├── time.h │ ├── times.h │ ├── types.h │ ├── uio.h │ ├── un.h │ ├── utsname.h │ └── wait.h ├── termios.h ├── time.h ├── u.h ├── unistd.h ├── utf.h ├── utime.h ├── wchar.h └── wctype.h ├── rc └── bin │ ├── ar89 │ ├── c89 │ ├── cat │ ├── chown │ ├── dircp │ ├── egrep │ ├── env │ ├── false │ ├── fgrep │ ├── grep │ ├── install │ ├── ln │ ├── ls │ ├── printf │ ├── psh │ ├── ranlib │ ├── rmdir │ ├── true │ ├── umask │ └── yacc └── src ├── 9src ├── mkfile ├── stty.c ├── tar.c └── tty.h ├── Makefile ├── ap ├── 386 │ ├── atom.s │ ├── cycles.s │ ├── lock.c │ ├── main9.s │ ├── main9p.s │ ├── memchr.s │ ├── memcmp.s │ ├── memcpy.s │ ├── memmove.s │ ├── memset.s │ ├── mkfile │ ├── notetramp.c │ ├── setjmp.s │ ├── strcat.s │ ├── strchr.s │ ├── strcpy.s │ ├── strlen.s │ ├── tas.s │ ├── vlop.s │ └── vlrt.c ├── Makefile ├── amd64 │ ├── Makefile │ ├── atom.s │ ├── cycles.s │ ├── lock.c │ ├── main9.s │ ├── main9p.s │ ├── notetramp.c │ ├── setjmp.s │ ├── sigsetjmp.s │ ├── strchr.s │ ├── strlen.s │ └── tas.s ├── arm │ ├── atom.s │ ├── cycles.c │ ├── div.s │ ├── getfcr.s │ ├── lock.c │ ├── main9.s │ ├── main9p.s │ ├── memmove.s │ ├── memset.s │ ├── mkfile │ ├── notetramp.c │ ├── setjmp.s │ ├── strchr.s │ ├── strcmp.s │ ├── strcpy.s │ ├── tas.s │ ├── vlop.s │ └── vlrt.c ├── bsd │ ├── Makefile │ ├── _sock_ingetaddr.c │ ├── _sock_ipattr.c │ ├── _sock_srv.c │ ├── accept.c │ ├── basename.c │ ├── bcopy.c │ ├── bind.c │ ├── connect.c │ ├── dirname.c │ ├── endhostent.c │ ├── ffs.c │ ├── getaddrinfo.c │ ├── getdtablesize.c │ ├── gethostbyaddr.c │ ├── gethostbyname.c │ ├── gethostname.c │ ├── getopt.c │ ├── getopt_long.c │ ├── getpeername.c │ ├── getprotobyname.c │ ├── getservbyaddr.c │ ├── getservbyname.c │ ├── getsockname.c │ ├── gettimeofday.c │ ├── h_errno.c │ ├── inet_addr.c │ ├── inet_ntoa.c │ ├── ioctl.c │ ├── listen.c │ ├── lstat.c │ ├── mktemp.c │ ├── nptohl.c │ ├── ntohl.c │ ├── popen.c │ ├── pty.c │ ├── putenv.c │ ├── rresvport.c │ ├── send.c │ ├── sendto.c │ ├── sethostent.c │ ├── setlinebuf.c │ ├── shutdown.c │ ├── socket.c │ ├── socketpair.c │ ├── strcasecmp.c │ └── strncasecmp.c ├── crt │ ├── Makefile │ ├── crt0.c │ ├── crti.s │ └── crtn.s ├── dirent │ ├── Makefile │ ├── alphasort.c │ ├── dirfd.c │ ├── fdopendir.c │ ├── readdir_r.c │ ├── scandir.c │ ├── seekdir.c │ ├── telldir.c │ └── versionsort.c ├── extraobjs ├── gen │ ├── Makefile │ ├── __ctype_b_loc.c │ ├── __ctype_get_mb_cur_max.c │ ├── __ctype_tolower_loc.c │ ├── __ctype_toupper_loc.c │ ├── _assert.c │ ├── abort.c │ ├── atof.c │ ├── bsearch.c │ ├── calloc.c │ ├── clock.c │ ├── ctype.c │ ├── difftime.c │ ├── div.c │ ├── getenv.c │ ├── isalnum.c │ ├── isascii.c │ ├── isblank.c │ ├── iswalnum.c │ ├── iswalpha.c │ ├── iswblank.c │ ├── iswcntrl.c │ ├── iswctype.c │ ├── iswdigit.c │ ├── iswgraph.c │ ├── iswlower.c │ ├── iswprint.c │ ├── iswpunct.c │ ├── iswspace.c │ ├── iswupper.c │ ├── iswxdigit.c │ ├── itoa.c │ ├── itol.c │ ├── ldiv.c │ ├── mktime.c │ ├── qsort.c │ ├── raise.c │ ├── rand.c │ ├── reduce │ ├── strcoll.c │ ├── strftime.c │ ├── strxfrm.c │ ├── toascii.c │ ├── toupper.c │ ├── towctrans.c │ ├── wcswidth.c │ ├── wctrans.c │ └── wcwidth.c ├── internal │ ├── alpha.h │ ├── dir.h │ ├── fcall.h │ ├── fconv.h │ ├── floatscan.h │ ├── internal.h │ ├── intscan.h │ ├── lib.h │ ├── libc.h │ ├── libm.h │ ├── locale_impl.h │ ├── lookup.h │ ├── nonspacing.h │ ├── priv.h │ ├── punct.h │ ├── shgetc.h │ ├── stdio_impl.h │ ├── sys9.h │ ├── tos.h │ └── wide.h ├── locale │ ├── Makefile │ ├── __lctrans.c │ ├── __mo_lookup.c │ ├── c_locale.c │ ├── dcngettext.c │ ├── locale_map.c │ ├── localeconv.c │ ├── setlocale.c │ ├── wcscoll.c │ └── wcsxfrm.c ├── math │ ├── Makefile │ ├── __fpclassifyl.c │ ├── __signbit.c │ ├── __signbitl.c │ ├── asin.c │ ├── atan.c │ ├── atan2.c │ ├── copysignl.c │ ├── erf.c │ ├── exp.c │ ├── fabs.c │ ├── floatscan.c │ ├── floor.c │ ├── fmod.c │ ├── fmodl.c │ ├── frexpl.c │ ├── gamma.c │ ├── hypot.c │ ├── j0.c │ ├── j1.c │ ├── jn.c │ ├── log.c │ ├── pow.c │ ├── scalbn.c │ ├── scalbnl.c │ ├── sin.c │ ├── sinh.c │ ├── tan.c │ └── tanh.c ├── mips │ ├── atom.s │ ├── c_fcr0.s │ ├── cycles.c │ ├── getfcr.s │ ├── lock.c │ ├── lock.pre-sema.c │ ├── main9.s │ ├── main9p.s │ ├── memchr.s │ ├── memcmp.s │ ├── memmove.s │ ├── memset.s │ ├── mkfile │ ├── notetramp.c │ ├── setjmp.s │ ├── strchr.s │ ├── strcmp.s │ ├── strcpy.s │ ├── tas.s │ ├── vlop.s │ └── vlrt.c ├── multibyte │ ├── Makefile │ ├── btowc.c │ ├── internal.c │ ├── mblen.c │ ├── mbrlen.c │ ├── mbrtowc.c │ ├── mbsinit.c │ ├── mbsrtowcs.c │ ├── mbstowcs.c │ ├── mbtowc.c │ ├── wcrtomb.c │ ├── wcsrtombs.c │ ├── wcstombs.c │ ├── wctob.c │ └── wctomb.c ├── plan9 │ ├── 9iounit.c │ ├── 9mallocz.c │ ├── 9wait.c │ ├── Makefile │ ├── __environ.c │ ├── __libc_start_main.c │ ├── __sys_alarm.c │ ├── __sys_chdir.c │ ├── __sys_close.c │ ├── __sys_dup.c │ ├── __sys_open.c │ ├── __sys_pipe.c │ ├── __sys_read.c │ ├── __sys_remove.c │ ├── __sys_sleep.c │ ├── __sys_stat.c │ ├── __sys_write.c │ ├── _alarm.c │ ├── _chdir.c │ ├── _close.c │ ├── _envsetup.c │ ├── _errno.c │ ├── _exit.c │ ├── _fcall.c │ ├── _fdinfo.c │ ├── _getpw.c │ ├── _nap.c │ ├── _open.c │ ├── _pipe.c │ ├── _read.c │ ├── _sleep.c │ ├── _write.c │ ├── access.c │ ├── buf.prom │ ├── cfgetospeed.c │ ├── chmod.c │ ├── chown.c │ ├── creat.c │ ├── ctermid.c │ ├── ctime.c │ ├── cuserid.c │ ├── dirread.c │ ├── dirstat.c │ ├── dirtostat.c │ ├── dup.c │ ├── execl.c │ ├── execle.c │ ├── execlp.c │ ├── execv.c │ ├── execve.c │ ├── execvp.c │ ├── fcntl.c │ ├── fork.c │ ├── frexp.c │ ├── fstat.c │ ├── fsync.c │ ├── ftruncate.c │ ├── getcwd.c │ ├── getgid.c │ ├── getgrgid.c │ ├── getgrnam.c │ ├── getgroups.c │ ├── getlogin.c │ ├── getpgrp.c │ ├── getpid.c │ ├── getppid.c │ ├── getpwnam.c │ ├── getpwuid.c │ ├── getuid.c │ ├── isatty.c │ ├── kill.c │ ├── link.c │ ├── lseek.c │ ├── malloc.c │ ├── mkdir.c │ ├── nan.c │ ├── opendir.c │ ├── panic.c │ ├── pause.c │ ├── profile.c │ ├── rename.c │ ├── rmdir.c │ ├── setgid.c │ ├── setpgid.c │ ├── setsid.c │ ├── setuid.c │ ├── signal.c │ ├── sigpending.c │ ├── sigprocmask.c │ ├── sigsuspend.c │ ├── stat.c │ ├── system.c │ ├── tcgetattr.c │ ├── time.c │ ├── times.c │ ├── tmpfile.c │ ├── ttyname.c │ ├── umask.c │ ├── uname.c │ ├── unlink.c │ ├── utime.c │ └── wait.c ├── posix │ ├── Makefile │ ├── getgrent.c │ ├── getpwent.c │ ├── mkfifo.c │ ├── pathconf.c │ ├── sigset.c │ ├── sysconf.c │ └── tzset.c ├── power │ ├── atom.s │ ├── cycles.s │ ├── getfcr.s │ ├── lock.c │ ├── main9.s │ ├── main9p.s │ ├── memcmp.s │ ├── memmove.s │ ├── memset.s │ ├── mkfile │ ├── notetramp.c │ ├── setjmp.s │ ├── strcmp.s │ ├── tas.s │ ├── vlop.s │ └── vlrt.c ├── regex │ ├── Makefile │ ├── fnmatch.c │ ├── glob.c │ ├── regcomp.c │ ├── regerror.c │ ├── regexec.c │ ├── tre-mem.c │ └── tre.h ├── sparc │ ├── cycles.c │ ├── lock.c │ ├── main9.s │ ├── main9p.s │ ├── memchr.s │ ├── memcmp.s │ ├── memmove.s │ ├── memset.s │ ├── mkfile │ ├── muldiv.s │ ├── notetramp.c │ ├── setjmp.s │ ├── strchr.s │ ├── strcmp.s │ ├── strcpy.s │ ├── tas.s │ ├── vlop.s │ └── vlrt.c ├── stdio │ ├── Makefile │ ├── __fmodeflags.c │ ├── __lockfile.c │ ├── __overflow.c │ ├── __stdio_close.c │ ├── __stdio_exit.c │ ├── __stdio_read.c │ ├── __stdio_seek.c │ ├── __stdio_write.c │ ├── __stdout_write.c │ ├── __string_read.c │ ├── __toread.c │ ├── __towrite.c │ ├── __uflow.c │ ├── _atexit.c │ ├── _dtoa.c │ ├── _fconv.c │ ├── _progname.c │ ├── _remove.c │ ├── asprintf.c │ ├── clearerr.c │ ├── exit.c │ ├── ext.c │ ├── ext2.c │ ├── fclose.c │ ├── fdopen.c │ ├── feof.c │ ├── ferror.c │ ├── fflush.c │ ├── fgetc.c │ ├── fgetpos.c │ ├── fgets.c │ ├── fgetwc.c │ ├── fgetws.c │ ├── fileno.c │ ├── fopen.c │ ├── fprintf.c │ ├── fputc.c │ ├── fputs.c │ ├── fputwc.c │ ├── fputws.c │ ├── fread.c │ ├── freopen.c │ ├── fscanf.c │ ├── fseek.c │ ├── fsetpos.c │ ├── ftell.c │ ├── ftoa.c │ ├── fwide.c │ ├── fwprintf.c │ ├── fwrite.c │ ├── fwscanf.c │ ├── getc.c │ ├── getc_unlocked.c │ ├── getchar.c │ ├── gets.c │ ├── getwc.c │ ├── getwchar.c │ ├── ofl.c │ ├── ofl_add.c │ ├── perror.c │ ├── pow10.c │ ├── printf.c │ ├── putc.c │ ├── putc_unlocked.c │ ├── putchar.c │ ├── puts.c │ ├── putwc.c │ ├── putwchar.c │ ├── rewind.c │ ├── scanf.c │ ├── setbuf.c │ ├── setvbuf.c │ ├── snprintf.c │ ├── sprintf.c │ ├── sscanf.c │ ├── stderr.c │ ├── stdin.c │ ├── stdout.c │ ├── strerror.c │ ├── swprintf.c │ ├── swscanf.c │ ├── tmpnam.c │ ├── ungetc.c │ ├── ungetwc.c │ ├── vasprintf.c │ ├── vfprintf.c │ ├── vfscanf.c │ ├── vfwprintf.c │ ├── vfwscanf.c │ ├── vprintf.c │ ├── vscanf.c │ ├── vsnprintf.c │ ├── vsprintf.c │ ├── vsscanf.c │ ├── vswprintf.c │ ├── vswscanf.c │ ├── vwprintf.c │ ├── vwscanf.c │ ├── wcsftime.c │ ├── wprintf.c │ └── wscanf.c ├── stdlib │ ├── Makefile │ ├── intscan.c │ ├── shgetc.c │ ├── wcstod.c │ └── wcstol.c ├── string │ ├── Makefile │ ├── mempcpy.c │ ├── strchrnul.c │ ├── strdup.c │ ├── strndup.c │ ├── strnlen.c │ ├── strverscmp.c │ ├── wcscat.c │ ├── wcschr.c │ ├── wcscmp.c │ ├── wcscpy.c │ ├── wcscspn.c │ ├── wcslen.c │ ├── wcsncat.c │ ├── wcsncmp.c │ ├── wcsncpy.c │ ├── wcspbrk.c │ ├── wcsrchr.c │ ├── wcsspn.c │ ├── wcsstr.c │ ├── wcstok.c │ ├── wmemchr.c │ ├── wmemcmp.c │ ├── wmemcpy.c │ ├── wmemmove.c │ └── wmemset.c └── syscall │ ├── genall │ └── mkfile ├── cmd ├── Makefile ├── README ├── apextest │ ├── .gitignore │ ├── Makefile │ └── test.c ├── awk │ ├── .gitignore │ ├── FIXES │ ├── Makefile │ ├── README │ ├── awk.1 │ ├── awk.h │ ├── awkgram.y │ ├── b.c │ ├── lex.c │ ├── lib.c │ ├── main.c │ ├── maketab.c │ ├── parse.c │ ├── proto.h │ ├── run.c │ └── tran.c ├── basename.c ├── bzip2recover.c ├── cc.c ├── compress.c ├── cp.c ├── diff │ ├── COPYING │ ├── ChangeLog │ ├── FREEBSD-upgrade │ ├── NEWS │ ├── README │ ├── analyze.c │ ├── cmpbuf.c │ ├── cmpbuf.h │ ├── config.h │ ├── context.c │ ├── diagmeet.note │ ├── diff.c │ ├── diff.h │ ├── diff.texi │ ├── diff3.c │ ├── dir.c │ ├── ed.c │ ├── fnmatch.c │ ├── fnmatch.h │ ├── getopt.c │ ├── getopt.h │ ├── getopt1.c │ ├── ifdef.c │ ├── install-sh │ ├── io.c │ ├── mkfile │ ├── normal.c │ ├── prepend_args.c │ ├── prepend_args.h │ ├── regex.c │ ├── regex.h │ ├── sdiff.c │ ├── side.c │ ├── system.h │ ├── util.c │ ├── version.c │ └── xmalloc.c ├── dirname.c ├── eqn │ ├── diacrit.c │ ├── e.h │ ├── eqn.c │ ├── eqn.y │ ├── eqnbox.c │ ├── font.c │ ├── fromto.c │ ├── funny.c │ ├── glob.c │ ├── input.c │ ├── integral.c │ ├── lex.c │ ├── lookup.c │ ├── main.c │ ├── mark.c │ ├── matrix.c │ ├── mkfile │ ├── move.c │ ├── over.c │ ├── paren.c │ ├── pile.c │ ├── prevy.tab.h │ ├── shift.c │ ├── size.c │ ├── sqrt.c │ ├── text.c │ └── tuning.c ├── expr.c ├── grap │ ├── coord.c │ ├── for.c │ ├── frame.c │ ├── grap.h │ ├── grap.y │ ├── grapl.lx │ ├── input.c │ ├── label.c │ ├── main.c │ ├── misc.c │ ├── mkfile │ ├── plot.c │ ├── print.c │ └── ticks.c ├── kill.c ├── lp │ ├── LOCK.c │ ├── ipcopen.c │ ├── lp.rc │ ├── lpdaemon.c │ ├── lpdsend.c │ ├── lpsend.c │ ├── lpsend.rc │ ├── mkfile │ └── tonet.c ├── make │ ├── defs.h │ ├── doname.c │ ├── dosys.c │ ├── files.c │ ├── gram.y │ ├── ident.c │ ├── main.c │ ├── misc.c │ └── mkfile ├── mkfile ├── mv.c ├── patch │ ├── COPYING │ ├── ChangeLog │ ├── FREEBSD-upgrade │ ├── INSTALL │ ├── Makefile.in │ ├── NEWS │ ├── README │ ├── acconfig.h │ ├── addext.c │ ├── argmatch.c │ ├── argmatch.h │ ├── backupfile.c │ ├── backupfile.h │ ├── basename.c │ ├── common.h │ ├── config.h │ ├── config.hin │ ├── configure │ ├── configure.in │ ├── getopt.c │ ├── getopt.h │ ├── getopt1.c │ ├── inp.c │ ├── inp.h │ ├── install-sh │ ├── maketime.c │ ├── maketime.h │ ├── mkfile │ ├── partime.c │ ├── partime.h │ ├── patch.1 │ ├── patch.c │ ├── patchlevel.h │ ├── pch.c │ ├── pch.h │ ├── quotearg.c │ ├── quotearg.h │ ├── util.c │ ├── util.h │ ├── version.c │ └── version.h ├── pax │ ├── Makefile │ ├── PATCHLEVEL │ ├── README │ ├── append.c │ ├── buffer.c │ ├── config.h │ ├── cpio.1 │ ├── cpio.c │ ├── create.c │ ├── extract.c │ ├── fileio.c │ ├── func.h │ ├── limits.h │ ├── link.c │ ├── list.c │ ├── mem.c │ ├── mkfile │ ├── namelist.c │ ├── names.c │ ├── pass.c │ ├── pathname.c │ ├── pax.1 │ ├── pax.c │ ├── pax.h │ ├── paxdir.c │ ├── paxdir.h │ ├── port.c │ ├── port.h │ ├── regexp.c │ ├── regexp.h │ ├── replace.c │ ├── tar.1 │ ├── tar.c │ ├── ttyio.c │ ├── warn.c │ └── wildmat.c ├── pdksh │ ├── Makefile │ ├── README │ ├── README.Plan9 │ ├── alloc.c │ ├── c_ksh.c │ ├── c_sh.c │ ├── c_test.c │ ├── c_test.h │ ├── c_ulimit.c │ ├── conf-end.h │ ├── config.h │ ├── eval.c │ ├── exec.c │ ├── expand.h │ ├── expr.c │ ├── history.c │ ├── io.c │ ├── jobs.c │ ├── ksh_dir.h │ ├── ksh_limval.h │ ├── ksh_stat.h │ ├── ksh_time.h │ ├── ksh_times.h │ ├── ksh_wait.h │ ├── lex.c │ ├── lex.h │ ├── mail.c │ ├── main.c │ ├── misc.c │ ├── mkfile │ ├── path.c │ ├── proto.h │ ├── sh.h │ ├── shf.c │ ├── shf.h │ ├── syn.c │ ├── table.c │ ├── table.h │ ├── trap.c │ ├── tree.c │ ├── tree.h │ ├── tty.c │ ├── tty.h │ ├── var.c │ └── version.c ├── pic │ ├── arcgen.c │ ├── blockgen.c │ ├── boxgen.c │ ├── circgen.c │ ├── for.c │ ├── input.c │ ├── linegen.c │ ├── main.c │ ├── makefile │ ├── misc.c │ ├── mkfile │ ├── movegen.c │ ├── pic.h │ ├── picl.lx │ ├── picy.y │ ├── pltroff.c │ ├── prevy.tab.h │ ├── print.c │ ├── symtab.c │ └── textgen.c ├── psh.rc ├── sed │ ├── Makefile │ ├── mkfile │ ├── sed.h │ ├── sed0.c │ └── sed1.c ├── troff │ ├── BUILDME │ ├── FIXES │ ├── Makefile │ ├── README │ ├── cvt │ ├── dwbinit.c │ ├── dwbinit.h │ ├── ext.h │ ├── fns.h │ ├── hytab.c │ ├── mkfile │ ├── n1.c │ ├── n10.c │ ├── n2.c │ ├── n3.c │ ├── n4.c │ ├── n5.c │ ├── n6.c │ ├── n7.c │ ├── n8.c │ ├── n9.c │ ├── ni.c │ ├── suftab.c │ ├── t10.c │ ├── t11.c │ ├── t6.c │ ├── tdef.h │ ├── unansi │ └── y.tab.c └── uname.c ├── linux.inc └── travis.inc /.gitignore: -------------------------------------------------------------------------------- 1 | /386/* 2 | 3 | /amd64/bin 4 | /amd64/lib 5 | 6 | 7 | *.orig 8 | *_orig 9 | *.rej 10 | *~ 11 | *.o 12 | o.* 13 | *.a 14 | *.ao 15 | *.out 16 | tests/*.err 17 | 18 | -------------------------------------------------------------------------------- /amd64/include/crt_arch.h: -------------------------------------------------------------------------------- 1 | __asm__( 2 | ".text \n" 3 | ".global " START " \n" 4 | START ": \n" 5 | " xor %rbp,%rbp \n" 6 | " mov %rsp,%rdi \n" 7 | ".weak _DYNAMIC \n" 8 | ".hidden _DYNAMIC \n" 9 | " lea _DYNAMIC(%rip),%rsi \n" 10 | " andq $-16,%rsp \n" 11 | " call " START "_c \n" 12 | ); 13 | -------------------------------------------------------------------------------- /external_example/Makefile.ape: -------------------------------------------------------------------------------- 1 | APE_PATH = path where you have ape repo cloned 2 | ARCH = your arch 3 | HARVEY = path where you have Harvey repo cloned 4 | 5 | CFLAGS=-nostdinc \ 6 | -O0 \ 7 | -mno-red-zone \ 8 | -ffreestanding \ 9 | -fno-builtin \ 10 | -trigraphs \ 11 | -Wall \ 12 | -Wno-missing-braces \ 13 | -Wno-parentheses \ 14 | -Wno-unknown-pragmas \ 15 | -Wuninitialized \ 16 | -Wmaybe-uninitialized \ 17 | -I $(APE_PATH)/$(ARCH)/include \ 18 | -I$(APE_PATH)/sys/include 19 | 20 | LDFLAGS=-nostdlib \ 21 | $(APE_PATH)/$(ARCH)/lib/crt1.o \ 22 | $(APE_PATH)/$(ARCH)/lib/crti.o \ 23 | $(APE_PATH)/$(ARCH)/lib/crtn.o \ 24 | -L $(APE_PATH)/$(ARCH)/lib \ 25 | -L $(HARVEY)/$(ARCH)/lib \ 26 | -lbsd -lap -lc 27 | 28 | hi: hi.o 29 | ld -o hiape hiape.o $(LDFLAGS) 30 | hi.o: hi.c 31 | cc $(CFLAGS) -c hi.c 32 | 33 | -------------------------------------------------------------------------------- /external_example/hiape.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main () { 4 | printf("Hello World!\n"); 5 | return 0; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /include/alloca.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 Álvaro Jurado et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #ifndef _ALLOCA_H 10 | #define _ALLOCA_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | 18 | extern void *alloca(size_t); 19 | 20 | #ifdef __GNUC__ 21 | #define alloca __builtin_alloca 22 | #endif 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | 11 | #undef assert 12 | #ifdef NDEBUG 13 | #define assert(ignore) ((void)0) 14 | #else 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | extern void _assert(char *, unsigned); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | #define assert(e) {if(!(e))_assert(__FILE__, __LINE__);} 25 | #endif /* NDEBUG */ 26 | -------------------------------------------------------------------------------- /include/cursor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #ifndef _PLAN9_SOURCE 11 | This header file is an extension to ANSI/POSIX 12 | #endif 13 | 14 | #ifndef __CURSOR_H_ 15 | #define __CURSOR_H_ 16 | #include_next 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /include/endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 Álvaro Jurado et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #define __BYTE_ORDER __LITTLE_ENDIAN 10 | -------------------------------------------------------------------------------- /include/errno.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 Álvaro Jurado et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #ifndef _ERRNO_H 10 | #define _ERRNO_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include 17 | 18 | extern int errno; 19 | 20 | #define EPLAN9 1002 21 | #define EGREG 1003 /* Old joke */ 22 | 23 | #include 24 | 25 | #ifdef _GNU_SOURCE 26 | extern char *program_invocation_short_name, *program_invocation_name; 27 | #endif 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #ifndef __ERROR_H 11 | #define __ERROR_H 12 | #ifndef _RESEARCH_SOURCE 13 | This header file is not defined in pure ANSI or POSIX 14 | #endif 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | extern char *_progname; /* program name */ 21 | extern void _perror(char *); /* perror but with _progname */ 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif /* _ERROR_H */ 28 | -------------------------------------------------------------------------------- /include/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #ifndef _PLAN9_SOURCE 11 | This header file is an extension to ANSI/POSIX 12 | #endif 13 | 14 | #ifndef __EVENT_H_ 15 | #define __EVENT_H_ 16 | #include_next 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /include/fnmatch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 Álvaro Jurado et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #ifndef _FNMATCH_H 10 | #define _FNMATCH_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #define FNM_PATHNAME 0x1 17 | #define FNM_NOESCAPE 0x2 18 | #define FNM_PERIOD 0x4 19 | #define FNM_LEADING_DIR 0x8 20 | #define FNM_CASEFOLD 0x10 21 | #define FNM_FILE_NAME FNM_PATHNAME 22 | 23 | #define FNM_NOMATCH 1 24 | #define FNM_NOSYS (-1) 25 | 26 | int fnmatch(const char *, const char *, int); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/inttypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #ifndef _SUSV2_SOURCE 11 | #error "inttypes.h is SUSV2" 12 | #endif 13 | 14 | #ifndef _INTTYPES_H_ 15 | #define _INTTYPES_H_ 1 16 | 17 | typedef long _intptr_t; 18 | typedef unsigned long _uintptr_t; 19 | 20 | typedef _intptr_t intptr_t; 21 | typedef _uintptr_t uintptr_t; 22 | typedef long intmax_t; 23 | typedef unsigned long uintmax_t; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/iso646.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 Álvaro Jurado et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #ifndef _ISO646_H 10 | #define _ISO646_H 11 | 12 | #ifndef __cplusplus 13 | 14 | #define and && 15 | #define and_eq &= 16 | #define bitand & 17 | #define bitor | 18 | #define compl ~ 19 | #define not ! 20 | #define not_eq != 21 | #define or || 22 | #define or_eq |= 23 | #define xor ^ 24 | #define xor_eq ^= 25 | 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/keyboard.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #ifndef _PLAN9_SOURCE 11 | This header file is an extension to ANSI/POSIX 12 | #endif 13 | 14 | #include "/sys/include/keyboard.h" 15 | 16 | -------------------------------------------------------------------------------- /include/libgen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 Álvaro Jurado et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #ifndef _LIBGEN_H 10 | #define _LIBGEN_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | char *dirname(char *); 17 | char *basename(char *); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /include/libl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #ifndef __LIBL_H 11 | #define __LIBL_H 12 | #ifndef _RESEARCH_SOURCE 13 | This header file is not defined in ANSI or POSIX 14 | #endif 15 | 16 | extern int printable(int); 17 | extern void allprint(int8_t); 18 | extern int yyracc(int); 19 | extern int yyreject(void); 20 | extern void yyless(int); 21 | extern int yywrap(void); 22 | 23 | #endif /* __LIBV_L */ 24 | -------------------------------------------------------------------------------- /include/mouse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #ifndef _PLAN9_SOURCE 11 | This header file is an extension to ANSI/POSIX 12 | #endif 13 | 14 | #include "/sys/include/mouse.h" 15 | 16 | -------------------------------------------------------------------------------- /include/netinet/tcp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | -------------------------------------------------------------------------------- /include/stdbool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 Álvaro Jurado et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #ifndef _STDBOOL_H 10 | #define _STDBOOL_H 11 | 12 | #ifndef __cplusplus 13 | 14 | #define true 1 15 | #define false 0 16 | #define bool _Bool 17 | 18 | #endif 19 | 20 | #define __bool_true_false_are_defined 1 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /include/sys/param.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #ifndef __PARAM_H__ 11 | #define __PARAM_H__ 12 | 13 | #ifndef _BSD_EXTENSION 14 | This header file is an extension to ANSI/POSIX 15 | #endif 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #define NOFILES_MAX 100 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif /* !__PARAM_H__ */ 28 | -------------------------------------------------------------------------------- /include/sys/pty.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | /* 11 | * Pty support 12 | */ 13 | #ifndef __SYS_PTY_H__ 14 | #define __SYS_PTY_H__ 15 | 16 | #ifndef _BSD_EXTENSION 17 | This header file is an extension to ANSI/POSIX 18 | #endif 19 | 20 | 21 | char* ptsname(int); 22 | char* ptmname(int); 23 | 24 | int _getpty(void); 25 | 26 | #endif /* !__SYS_UIO_H__ */ 27 | -------------------------------------------------------------------------------- /include/sys/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #ifndef __SYSTIME_H 11 | #define __SYSTIME_H 12 | 13 | #include 14 | 15 | extern int gettimeofday(struct timeval *, struct timezone *); 16 | 17 | #endif /* __SYSTIME_H */ 18 | -------------------------------------------------------------------------------- /include/sys/times.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #ifndef __TIMES_H 11 | #define __TIMES_H 12 | 13 | struct tms { 14 | clock_t tms_utime; 15 | clock_t tms_stime; 16 | clock_t tms_cutime; 17 | clock_t tms_cstime; 18 | }; 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | clock_t times(struct tms *); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/sys/utsname.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #ifndef __UTSNAME 11 | #define __UTSNAME 12 | 13 | struct utsname { 14 | char *sysname; 15 | char *nodename; 16 | char *release; 17 | char *version; 18 | char *machine; 19 | }; 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | int uname(struct utsname *); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/utime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #ifndef __UTIME_H 11 | #define __UTIME_H 12 | 13 | 14 | struct utimbuf 15 | { 16 | time_t actime; 17 | time_t modtime; 18 | }; 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | extern int utime(const char *, const struct utimbuf *); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /rc/bin/ar89: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | flagfmt='c,d,p,r,t,u,v,x' 4 | args='archive [files ...]' 5 | 6 | if(! ifs=() eval `{aux/getflags $*} || ~ $#* 0) { 7 | aux/usage 8 | exit usage 9 | } 10 | 11 | key='' 12 | for(i in c d p r t x u v) 13 | if(f=flag$i ~ $#$f 1) 14 | key=$key$i 15 | exec /$cputype/bin/ar $key $* 16 | -------------------------------------------------------------------------------- /rc/bin/c89: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | exec /$cputype/bin/ape/cc $* 3 | -------------------------------------------------------------------------------- /rc/bin/cat: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | rfork e 4 | 5 | files=() 6 | while(! ~ $#* 0){ 7 | switch($1){ 8 | case - 9 | files=($files /fd/0) 10 | case -* 11 | ; 12 | case * 13 | files=($files $1) 14 | } 15 | shift 16 | } 17 | 18 | exec /$cputype/bin/cat $files 19 | -------------------------------------------------------------------------------- /rc/bin/chown: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | echo 'Permission denied' 4 | exit 1 5 | -------------------------------------------------------------------------------- /rc/bin/dircp: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | # dircp src dest - copy a tree with ape's tar 3 | switch($#*){ 4 | case 2 5 | @{cd $1 && tar cf /fd/1 .} | @{cd $2 && tar xf /fd/0} 6 | case * 7 | echo usage: dircp from to >[1=2] 8 | exit usage 9 | } 10 | -------------------------------------------------------------------------------- /rc/bin/egrep: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | exec /rc/bin/ape/grep $* 3 | -------------------------------------------------------------------------------- /rc/bin/env: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | sh -c $"* 4 | -------------------------------------------------------------------------------- /rc/bin/false: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | exit 1 3 | -------------------------------------------------------------------------------- /rc/bin/fgrep: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | exec /rc/bin/ape/grep $* 3 | -------------------------------------------------------------------------------- /rc/bin/grep: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | rfork e 4 | 5 | opts=() 6 | files=() 7 | argv0=$0 8 | while(! ~ $#* 0){ 9 | switch($1){ 10 | case -e 11 | opts=($opts $1 $2) 12 | shift 13 | case -[cfinsv] 14 | opts=($opts $1) 15 | case -q 16 | opts=($opts -s) 17 | case -* 18 | echo $argv0 $1 not supported >[2=1] 19 | exit 'not supported' 20 | case * 21 | files=($files $1) 22 | } 23 | shift 24 | } 25 | exec /$cputype/bin/grep $opts $files 26 | -------------------------------------------------------------------------------- /rc/bin/install: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | # Usage: install [options] srcfile dstfile 3 | # Usage: install srcfile dstfile owner group mode 4 | 5 | fn usage { 6 | echo 'usage: install [-c|-m mode] srcfile dstfile' >[1=2] 7 | exit 1 8 | } 9 | 10 | mode=775 11 | while(! ~ $#* 0){ 12 | switch($1){ 13 | case -c 14 | ; 15 | case -m 16 | mode=$2 17 | shift 18 | case -* 19 | usage 20 | case * 21 | switch($#*) { 22 | case 2 23 | ; 24 | case 5 25 | mode=$5 # backward compatibility 26 | case * 27 | usage 28 | } 29 | srcfile=$1 30 | dstfile=$2 31 | if (! test -f $dstfile || ! cmp -s $srcfile $dstfile) { 32 | cp $srcfile $dstfile 33 | chmod $mode $dstfile 34 | chmod g+w $dstfile 35 | } 36 | exit 0 37 | } 38 | shift 39 | } 40 | usage 41 | -------------------------------------------------------------------------------- /rc/bin/ln: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | argv0=$0 4 | force=n 5 | while(! ~ $#* 0 && ~ $1 -*){ 6 | switch($1){ 7 | case -f 8 | force=y 9 | case -s 10 | ; 11 | case * 12 | echo 'usage: ln [-s] [-f] source destination' >[2=1] 13 | exit 'usage' 14 | } 15 | shift 16 | } 17 | 18 | 19 | if(~ $force n && test -e $2 && ! test -d $2){ 20 | echo ln: $2 destination exists >[2=1] 21 | exit 'usage' 22 | } 23 | 24 | exec cp -gux $1 $2 25 | -------------------------------------------------------------------------------- /rc/bin/printf: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | # Here only for autoconf and friends. 4 | echo -n $1 5 | -------------------------------------------------------------------------------- /rc/bin/psh: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | # set up a shell running in an approximate POSIX 1003.2 environment 3 | rfork en 4 | fn sigterm{} 5 | HOME=$home 6 | bind -b /rc/bin/ape /bin 7 | bind -b /$cputype/bin/ape /bin 8 | if(test -d /$cputype/bin/pub) 9 | bind -a /$cputype/bin/pub /bin 10 | if(test -d /$cputype/bin/X11){ 11 | bind -a /$cputype/bin/X11 /bin 12 | if(test ! -e /env/DISPLAY) 13 | DISPLAY=:0.0 14 | } 15 | 16 | /bin/sh $* 17 | -------------------------------------------------------------------------------- /rc/bin/ranlib: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | exit 0 4 | -------------------------------------------------------------------------------- /rc/bin/rmdir: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | rm $* 3 | -------------------------------------------------------------------------------- /rc/bin/true: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | exit 0 3 | -------------------------------------------------------------------------------- /rc/bin/umask: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | echo no umask in Plan 9 3 | -------------------------------------------------------------------------------- /rc/bin/yacc: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | 3 | flagfmt='d,l,t,v,b stem' 4 | args='grammar' 5 | 6 | if(! ifs=() eval `{aux/getflags $*} || ! ~ $#* 1){ 7 | aux/usage 8 | exit usage 9 | } 10 | 11 | y=-S 12 | if (~ $#flagb 1) y=($y -s $flagb) 13 | if (~ $#flagd 1) y=($y -d) 14 | if (~ $#flagt 1) y=($y -D2) 15 | if (~ $#flagv 1) y=($y -v) 16 | exec /$cputype/bin/yacc $y $* 17 | -------------------------------------------------------------------------------- /src/9src/mkfile: -------------------------------------------------------------------------------- 1 | longjmp(1)" */ 5 | MOVL $1, AX /* bless their pointed heads */ 6 | ok: MOVL l+0(FP), BX 7 | MOVL 0(BX), SP /* restore sp */ 8 | MOVL 4(BX), BX /* put return pc on the stack */ 9 | MOVL BX, 0(SP) 10 | RET 11 | 12 | TEXT setjmp(SB), $0 13 | MOVL l+0(FP), AX 14 | MOVL SP, 0(AX) /* store sp */ 15 | MOVL 0(SP), BX /* store return pc */ 16 | MOVL BX, 4(AX) 17 | MOVL $0, AX /* return 0 */ 18 | RET 19 | 20 | TEXT sigsetjmp(SB), $0 21 | MOVL buf+0(FP), AX 22 | MOVL savemask+4(FP),BX 23 | MOVL BX,0(AX) 24 | MOVL $_psigblocked(SB),4(AX) 25 | MOVL SP, 8(AX) /* store sp */ 26 | MOVL 0(SP), BX /* store return pc */ 27 | MOVL BX, 12(AX) 28 | MOVL $0, AX /* return 0 */ 29 | RET 30 | -------------------------------------------------------------------------------- /src/ap/386/strcat.s: -------------------------------------------------------------------------------- 1 | TEXT strcat(SB),$0 2 | 3 | MOVL $0, AX 4 | MOVL $-1, CX 5 | CLD 6 | 7 | /* 8 | * find length of second string 9 | */ 10 | 11 | MOVL p2+4(FP), DI 12 | REPN; SCASB 13 | 14 | MOVL DI, BX 15 | SUBL p2+4(FP), BX 16 | 17 | /* 18 | * find end of first string 19 | */ 20 | 21 | MOVL p1+0(FP), DI 22 | REPN; SCASB 23 | 24 | /* 25 | * copy the memory 26 | */ 27 | SUBL $1, DI 28 | MOVL p2+4(FP), SI 29 | /* 30 | * copy whole longs 31 | */ 32 | MOVL BX, CX 33 | SHRL $2, CX 34 | REP; MOVSL 35 | /* 36 | * copy the rest, by bytes 37 | */ 38 | ANDL $3, BX 39 | MOVL BX, CX 40 | REP; MOVSB 41 | 42 | MOVL p1+0(FP), AX 43 | RET 44 | -------------------------------------------------------------------------------- /src/ap/386/strchr.s: -------------------------------------------------------------------------------- 1 | TEXT strchr(SB), $0 2 | 3 | MOVL s+0(FP), DI 4 | MOVB c+4(FP), AX 5 | CMPB AX, $0 6 | JEQ l2 /**/ 7 | 8 | /* 9 | * char is not null 10 | */ 11 | l1: 12 | MOVB (DI), BX 13 | CMPB BX, $0 14 | JEQ ret0 15 | ADDL $1, DI 16 | CMPB AX, BX 17 | JNE l1 18 | 19 | MOVL DI, AX 20 | SUBL $1, AX 21 | RET 22 | 23 | /* 24 | * char is null 25 | */ 26 | l2: 27 | MOVL $-1, CX 28 | CLD 29 | 30 | REPN; SCASB 31 | 32 | MOVL DI, AX 33 | SUBL $1, AX 34 | RET 35 | 36 | ret0: 37 | MOVL $0, AX 38 | RET 39 | -------------------------------------------------------------------------------- /src/ap/386/strcpy.s: -------------------------------------------------------------------------------- 1 | TEXT strcpy(SB),$0 2 | 3 | MOVL $0, AX 4 | MOVL $-1, CX 5 | CLD 6 | /* 7 | * find end of second string 8 | */ 9 | 10 | MOVL p2+4(FP), DI 11 | REPN; SCASB 12 | 13 | MOVL DI, BX 14 | SUBL p2+4(FP), BX 15 | 16 | /* 17 | * copy the memory 18 | */ 19 | MOVL p1+0(FP), DI 20 | MOVL p2+4(FP), SI 21 | /* 22 | * copy whole longs 23 | */ 24 | MOVL BX, CX 25 | SHRL $2, CX 26 | REP; MOVSL 27 | /* 28 | * copy the rest, by bytes 29 | */ 30 | ANDL $3, BX 31 | MOVL BX, CX 32 | REP; MOVSB 33 | 34 | MOVL p1+0(FP), AX 35 | RET 36 | -------------------------------------------------------------------------------- /src/ap/386/strlen.s: -------------------------------------------------------------------------------- 1 | TEXT strlen(SB),$0 2 | 3 | MOVL $0, AX 4 | MOVL $-1, CX 5 | CLD 6 | /* 7 | * look for end of string 8 | */ 9 | 10 | MOVL p+0(FP), DI 11 | REPN; SCASB 12 | 13 | MOVL DI, AX 14 | SUBL p+0(FP), AX 15 | SUBL $1, AX 16 | RET 17 | -------------------------------------------------------------------------------- /src/ap/386/tas.s: -------------------------------------------------------------------------------- 1 | TEXT tas(SB),$0 2 | 3 | MOVL $0xdeadead,AX 4 | MOVL l+0(FP),BX 5 | XCHGL AX,(BX) 6 | RET 7 | -------------------------------------------------------------------------------- /src/ap/Makefile: -------------------------------------------------------------------------------- 1 | 2 | TARGET = libap.a 3 | DIRS = $(ARCH) bsd crt gen locale math multibyte plan9 posix stdio stdlib string 4 | 5 | .PHONY: all 6 | 7 | all: $(TARGET) $(DIRS) 8 | 9 | $(TARGET): 10 | cd $(ARCH); $(MAKE) $(MFLAGS) 11 | cd bsd; $(MAKE) $(MFLAGS) 12 | cd crt; $(MAKE) $(MFLAGS) 13 | cd dirent; $(MAKE) $(MFLAGS) 14 | cd gen; $(MAKE) $(MFLAGS) 15 | cd locale; $(MAKE) $(MFLAGS) 16 | cd math; $(MAKE) $(MFLAGS) 17 | cd multibyte; $(MAKE) $(MFLAGS) 18 | cd plan9; $(MAKE) $(MFLAGS) 19 | cd posix; $(MAKE) $(MFLAGS) 20 | cd regex; $(MAKE) $(MFLAGS) 21 | cd stdio; $(MAKE) $(MFLAGS) 22 | cd stdlib; $(MAKE) $(MFLAGS) 23 | cd string; $(MAKE) $(MFLAGS) 24 | -------------------------------------------------------------------------------- /src/ap/amd64/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = libap.a 4 | SRCS =\ 5 | notetramp.c \ 6 | 7 | SRC =\ 8 | sigsetjmp.s \ 9 | 10 | OBJS = ${SRC:.s=.o} 11 | OBJ = ${SRCS:.c=.o} 12 | 13 | CFLAGS += -I../internal -D_PLAN9_SOURCE -D_POSIX_SOURCE 14 | 15 | .PHONY: all clean 16 | 17 | all: $(TARGET) clean 18 | 19 | %.o: 20 | $(CC) $(CFLAGS) -c $(SRCS) || exit 1 21 | $(CC) $(CFLAGS) -c $(SRC) || exit 1 22 | 23 | $(TARGET): $(OBJ) $(OBJS) 24 | ar rcs ${APEXLIB}/$@ $^ 25 | 26 | clean: 27 | rm -f *.o 28 | -------------------------------------------------------------------------------- /src/ap/amd64/cycles.s: -------------------------------------------------------------------------------- 1 | TEXT _cycles(SB),1,$0 /* time stamp counter; cycles since power up */ 2 | RDTSC 3 | MOVL AX, 0(RARG) /* lo */ 4 | MOVL DX, 4(RARG) /* hi */ 5 | RET 6 | -------------------------------------------------------------------------------- /src/ap/amd64/lock.c: -------------------------------------------------------------------------------- 1 | #include "../plan9/lib.h" 2 | #include "../plan9/sys9.h" 3 | #define _LOCK_EXTENSION 4 | #include 5 | //#include 6 | 7 | void 8 | lock(Lock *l) 9 | { 10 | if(ainc(&l->key) == 1) 11 | return; /* changed from 0 -> 1: we hold lock */ 12 | /* otherwise wait in kernel */ 13 | while(_SEMACQUIRE(&l->sem, 1) < 0){ 14 | /* interrupted; try again */ 15 | } 16 | } 17 | 18 | void 19 | unlock(Lock *l) 20 | { 21 | if(adec(&l->key) == 0) 22 | return; /* changed from 1 -> 0: no contention */ 23 | _SEMRELEASE(&l->sem, 1); 24 | } 25 | 26 | int 27 | canlock(Lock *l) 28 | { 29 | if(ainc(&l->key) == 1) 30 | return 1; /* changed from 0 -> 1: success */ 31 | /* Undo increment (but don't miss wakeup) */ 32 | if(adec(&l->key) == 0) 33 | return 0; /* changed from 1 -> 0: no contention */ 34 | _SEMRELEASE(&l->sem, 1); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /src/ap/amd64/main9.s: -------------------------------------------------------------------------------- 1 | TEXT _main(SB), 1, $(3*8) 2 | 3 | CALL _envsetup(SB) 4 | MOVL inargc-8(FP), RARG 5 | LEAQ inargv+0(FP), AX 6 | MOVQ AX, 8(SP) 7 | MOVQ environ(SB), AX 8 | MOVQ AX, 16(SP) 9 | CALL main(SB) 10 | MOVQ AX, RARG 11 | CALL exit(SB) 12 | RET 13 | -------------------------------------------------------------------------------- /src/ap/amd64/setjmp.s: -------------------------------------------------------------------------------- 1 | TEXT longjmp(SB), $0 2 | MOVL r+8(FP), AX 3 | CMPL AX, $0 4 | JNE ok /* ansi: "longjmp(0) => longjmp(1)" */ 5 | MOVL $1, AX /* bless their pointed heads */ 6 | ok: 7 | MOVQ 0(RARG), SP /* restore sp */ 8 | MOVQ 8(RARG), BX /* put return pc on the stack */ 9 | MOVQ BX, 0(SP) 10 | RET 11 | 12 | TEXT setjmp(SB), $0 13 | MOVQ SP, 0(RARG) /* store sp */ 14 | MOVQ 0(SP), BX /* store return pc */ 15 | MOVQ BX, 8(RARG) 16 | MOVL $0, AX /* return 0 */ 17 | RET 18 | 19 | TEXT sigsetjmp(SB), $0 20 | MOVL savemask+8(FP), BX 21 | MOVL BX, 0(RARG) 22 | MOVL $_psigblocked(SB), 4(RARG) 23 | MOVQ SP, 8(RARG) /* store sp */ 24 | MOVQ 0(SP), BX /* store return pc */ 25 | MOVQ BX, 16(RARG) 26 | MOVL $0, AX /* return 0 */ 27 | RET 28 | -------------------------------------------------------------------------------- /src/ap/amd64/strchr.s: -------------------------------------------------------------------------------- 1 | TEXT strchr(SB), $0 2 | 3 | MOVQ RARG, DI 4 | MOVB c+8(FP), AX 5 | CMPB AX, $0 6 | JEQ l2 /**/ 7 | 8 | /* 9 | * char is not null 10 | */ 11 | l1: 12 | MOVB (DI), BX 13 | CMPB BX, $0 14 | JEQ ret0 15 | ADDQ $1, DI 16 | CMPB AX, BX 17 | JNE l1 18 | 19 | MOVQ DI, AX 20 | SUBQ $1, AX 21 | RET 22 | 23 | /* 24 | * char is null 25 | */ 26 | l2: 27 | MOVQ $-1, CX 28 | CLD 29 | 30 | REPN; SCASB 31 | 32 | MOVQ DI, AX 33 | SUBQ $1, AX 34 | RET 35 | 36 | ret0: 37 | MOVQ $0, AX 38 | RET 39 | -------------------------------------------------------------------------------- /src/ap/amd64/strlen.s: -------------------------------------------------------------------------------- 1 | TEXT strlen(SB),$0 2 | 3 | MOVL $0, AX 4 | MOVQ $-1, CX 5 | CLD 6 | /* 7 | * look for end of string 8 | */ 9 | 10 | MOVQ RARG, DI 11 | REPN; SCASB 12 | 13 | MOVQ DI, AX 14 | SUBQ RARG, AX 15 | SUBQ $1, AX 16 | RET 17 | -------------------------------------------------------------------------------- /src/ap/amd64/tas.s: -------------------------------------------------------------------------------- 1 | TEXT tas(SB),$0 2 | 3 | MOVL $0xdeadead,AX 4 | XCHGL AX,(RARG) 5 | RET 6 | -------------------------------------------------------------------------------- /src/ap/arm/cycles.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | void 11 | _cycles(unsigned long long *u) 12 | { 13 | *u = 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/ap/arm/getfcr.s: -------------------------------------------------------------------------------- 1 | 2 | TEXT setfcr(SB), $4 3 | MOVW R0, FPCR 4 | RET 5 | 6 | TEXT getfcr(SB), $4 7 | MOVW FPCR, R0 8 | RET 9 | 10 | TEXT getfsr(SB), $0 11 | MOVW FPSR, R0 12 | RET 13 | 14 | TEXT setfsr(SB), $0 15 | MOVW R0, FPSR 16 | RET 17 | -------------------------------------------------------------------------------- /src/ap/arm/main9.s: -------------------------------------------------------------------------------- 1 | arg=0 2 | sp=13 3 | sb=12 4 | 5 | TEXT _main(SB), 1, $16 6 | MOVW $setR12(SB), R(sb) 7 | BL _envsetup(SB) 8 | MOVW $inargv+0(FP), R(arg) 9 | MOVW R(arg), 8(R(sp)) 10 | MOVW inargc-4(FP), R(arg) 11 | MOVW R(arg), 4(R(sp)) 12 | BL main(SB) 13 | loop: 14 | MOVW R(arg), 4(R(sp)) 15 | BL exit(SB) 16 | BL _div(SB) 17 | B loop 18 | -------------------------------------------------------------------------------- /src/ap/arm/mkfile: -------------------------------------------------------------------------------- 1 | APE=/sys/src/ape 2 | <$APE/config 3 | LIB=/$objtype/lib/ape/libap.a 4 | OFILES=\ 5 | atom.$O\ 6 | cycles.$O\ 7 | div.$O\ 8 | getfcr.$O\ 9 | lock.$O\ 10 | main9.$O\ 11 | main9p.$O\ 12 | memmove.$O\ 13 | memset.$O\ 14 | notetramp.$O\ 15 | setjmp.$O\ 16 | strchr.$O\ 17 | strcmp.$O\ 18 | strcpy.$O\ 19 | tas.$O\ 20 | vlop.$O\ 21 | vlrt.$O\ 22 | 23 | longjmp(1)" */ 25 | MOVW $1, R(arg+2) /* bless their pointed heads */ 26 | ok: MOVW (R(arg+0)), R(sp) 27 | MOVW 4(R(arg+0)), R(link) 28 | MOVW R(arg+2), R(arg+0) 29 | RET 30 | -------------------------------------------------------------------------------- /src/ap/arm/tas.s: -------------------------------------------------------------------------------- 1 | TEXT tas(SB), $-4 2 | MOVW R0,R1 3 | MOVW $1,R0 4 | SWPW R0,(R1) 5 | RET 6 | -------------------------------------------------------------------------------- /src/ap/arm/vlop.s: -------------------------------------------------------------------------------- 1 | TEXT _mulv(SB), $0 2 | MOVW 4(FP),R8 /* l0 */ 3 | MOVW 8(FP),R11 /* h0 */ 4 | MOVW 12(FP),R4 /* l1 */ 5 | MOVW 16(FP),R5 /* h1 */ 6 | MULLU R8,R4,(R6, R7) /* l0*l1 */ 7 | MUL R8,R5,R5 /* l0*h1 */ 8 | MUL R11,R4,R4 /* h0*l1 */ 9 | ADD R4,R6 10 | ADD R5,R6 11 | MOVW R6,4(R0) 12 | MOVW R7,0(R0) 13 | RET 14 | -------------------------------------------------------------------------------- /src/ap/bsd/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = libap.a 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | CFLAGS += -I../internal -D_BSD_EXTENSION -D_BSD_EXTENSION -D_PLAN9_SOURCE 7 | 8 | .PHONY: clean all 9 | 10 | all: $(TARGET) clean 11 | 12 | %.o: %.c 13 | $(CC) $(CFLAGS) -c $(SRCS) || exit 1 14 | 15 | $(TARGET): $(OBJ) 16 | ar rcs ${APEXLIB}/$@ $^ 17 | 18 | clean: 19 | rm -f $(OBJ) 20 | -------------------------------------------------------------------------------- /src/ap/bsd/basename.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include "libc.h" 12 | 13 | char *basename(char *s) 14 | { 15 | size_t i; 16 | if (!s || !*s) return "."; 17 | i = strlen(s)-1; 18 | for (; i&&s[i]=='/'; i--) s[i] = 0; 19 | for (; i&&s[i-1]!='/'; i--); 20 | return s+i; 21 | } 22 | 23 | weak_alias(basename, __xpg_basename); 24 | -------------------------------------------------------------------------------- /src/ap/bsd/bcopy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | void 15 | bcopy(const void *f, void *t, size_t n) 16 | { 17 | memmove(t, f, n); 18 | } 19 | 20 | int 21 | bcmp(const void *a, const void *b, size_t n) 22 | { 23 | return memcmp(a, b, n); 24 | } 25 | 26 | void 27 | bzero(void *a, size_t n) 28 | { 29 | memset(a, 0, n); 30 | } 31 | -------------------------------------------------------------------------------- /src/ap/bsd/dirname.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | char *dirname(char *s) 13 | { 14 | size_t i; 15 | if (!s || !*s) return "."; 16 | i = strlen(s)-1; 17 | for (; s[i]=='/'; i--) if (!i) return "/"; 18 | for (; s[i]!='/'; i--) if (!i) return "."; 19 | for (; s[i]=='/'; i--) if (!i) return "/"; 20 | s[i+1] = 0; 21 | return s; 22 | } 23 | -------------------------------------------------------------------------------- /src/ap/bsd/endhostent.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | void 11 | endhostent(void) 12 | { 13 | } 14 | -------------------------------------------------------------------------------- /src/ap/bsd/ffs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | /* Find the first set bit 11 | * i.e. least signifigant 1 bit: 12 | * 0 => 0 13 | * 1 => 1 14 | * 2 => 2 15 | * 3 => 1 16 | * 4 => 3 17 | */ 18 | 19 | int 20 | ffs(unsigned int mask) 21 | { 22 | int i; 23 | 24 | if (!mask) 25 | return 0; 26 | i = 1; 27 | while (!(mask & 1)){ 28 | i++; 29 | mask = mask >> 1; 30 | } 31 | return i; 32 | } 33 | -------------------------------------------------------------------------------- /src/ap/bsd/getdtablesize.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | /* posix */ 11 | #include 12 | 13 | int 14 | getdtablesize(void) 15 | { 16 | return OPEN_MAX; 17 | } 18 | -------------------------------------------------------------------------------- /src/ap/bsd/getservbyaddr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | /* bsd extensions */ 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | struct servent* 21 | getservbyport(int port, const char *proto) 22 | { 23 | char buf[32]; 24 | 25 | snprintf(buf, sizeof buf, "%d", port); 26 | return getservbyname(buf, proto); 27 | } 28 | -------------------------------------------------------------------------------- /src/ap/bsd/h_errno.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #undef h_errno 4 | int h_errno; 5 | 6 | int *__h_errno_location(void) 7 | { 8 | return &h_errno; 9 | } 10 | -------------------------------------------------------------------------------- /src/ap/bsd/lstat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int 15 | lstat(const char *name, struct stat *ans) 16 | { 17 | return stat(name, ans); 18 | } 19 | 20 | int 21 | symlink(const char *c, const char *d) 22 | { 23 | errno = EPERM; 24 | return -1; 25 | } 26 | 27 | ssize_t 28 | readlink(const char *c, char *d, size_t i) 29 | { 30 | errno = EIO; 31 | return -1; 32 | } 33 | -------------------------------------------------------------------------------- /src/ap/bsd/nptohl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | unsigned long 11 | nptohl(void *p) 12 | { 13 | unsigned char *up; 14 | unsigned long x; 15 | 16 | up = p; 17 | x = (up[0]<<24)|(up[1]<<16)|(up[2]<<8)|up[3]; 18 | return x; 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/bsd/sethostent.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | int 11 | sethostent(int i) 12 | { 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/ap/bsd/setlinebuf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | void 13 | setlinebuf(FILE *f) 14 | { 15 | static char buf[BUFSIZ]; 16 | 17 | setvbuf (f, buf, _IOLBF, BUFSIZ); 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/bsd/shutdown.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | int 14 | shutdown(int fd, int how) 15 | { 16 | if(how == 2) 17 | close(fd); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/ap/bsd/socketpair.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | /* posix */ 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /* bsd extensions */ 17 | #include 18 | #include 19 | 20 | int 21 | socketpair(int domain, int i, int n, int *sv) 22 | { 23 | switch(domain){ 24 | case PF_UNIX: 25 | return pipe(sv); 26 | default: 27 | errno = EOPNOTSUPP; 28 | return -1; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/ap/crt/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | CFLAGS += -I../internal 4 | CP = cp 5 | 6 | .PHONY: all 7 | 8 | all: crt0.o crti.o crtn.o clean 9 | 10 | crt0.o: crt0.c 11 | $(CC) $(CFLAGS) -c crt0.c 12 | $(CP) crt0.o $(APEXLIB)/ 13 | 14 | crti.o: crti.s 15 | $(CC) $(CFLAGS) -c crti.s 16 | $(CP) crti.o $(APEXLIB)/ 17 | 18 | crtn.o: crtn.s 19 | $(CC) $(CFLAGS) -c crtn.s 20 | $(CP) crtn.o $(APEXLIB)/ 21 | 22 | clean: 23 | rm -f *.o 24 | -------------------------------------------------------------------------------- /src/ap/crt/crt0.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2018 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #define START "_start" 10 | 11 | #include "crt_arch.h" 12 | 13 | int main(); 14 | void _init() __attribute__((weak)); 15 | void _fini() __attribute__((weak)); 16 | _Noreturn int __libc_start_main(int (*)(), int, char **, 17 | void (*)(), void(*)(), void(*)()); 18 | 19 | void _start_c(long *p) 20 | { 21 | int argc = p[0]; 22 | char **argv = (void *)(p+1); 23 | __libc_start_main(main, argc, argv, _init, _fini, 0); 24 | } 25 | -------------------------------------------------------------------------------- /src/ap/crt/crti.s: -------------------------------------------------------------------------------- 1 | .section .init 2 | .global _init 3 | _init: 4 | push %rax 5 | 6 | .section .fini 7 | .global _fini 8 | _fini: 9 | push %rax 10 | -------------------------------------------------------------------------------- /src/ap/crt/crtn.s: -------------------------------------------------------------------------------- 1 | .section .init 2 | pop %rax 3 | ret 4 | 5 | .section .fini 6 | pop %rax 7 | ret 8 | -------------------------------------------------------------------------------- /src/ap/dirent/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = libap.a 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | CFLAGS += -I../internal -D_RESEARCH_SOURCE 7 | 8 | .PHONY: all clean 9 | 10 | all: $(TARGET) clean 11 | 12 | %.o: %.c 13 | $(CC) $(CFLAGS) -c $(SRCS) 14 | 15 | $(TARGET): $(OBJ) 16 | ar rcs ${APEXLIB}/$@ $^ 17 | 18 | clean: 19 | rm -f $(OBJ) 20 | -------------------------------------------------------------------------------- /src/ap/dirent/alphasort.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include "libc.h" 12 | 13 | int alphasort(const struct dirent **a, const struct dirent **b) 14 | { 15 | return strcoll((*a)->d_name, (*b)->d_name); 16 | } 17 | 18 | LFS64(alphasort); 19 | -------------------------------------------------------------------------------- /src/ap/dirent/dirfd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | int dirfd(DIR *d) 12 | { 13 | return d->dd_fd; 14 | } 15 | -------------------------------------------------------------------------------- /src/ap/dirent/fdopendir.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | DIR *fdopendir(int fd) 16 | { 17 | DIR *dir; 18 | struct stat st; 19 | 20 | if (fstat(fd, &st) < 0) { 21 | return 0; 22 | } 23 | if (!S_ISDIR(st.st_mode)) { 24 | errno = ENOTDIR; 25 | return 0; 26 | } 27 | if (!(dir = calloc(1, sizeof *dir))) { 28 | return 0; 29 | } 30 | 31 | fcntl(fd, F_SETFD, FD_CLOEXEC); 32 | dir->dd_fd = fd; 33 | return dir; 34 | } 35 | -------------------------------------------------------------------------------- /src/ap/dirent/seekdir.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include "libc.h" 12 | 13 | void seekdir(DIR *dir, long off) 14 | { 15 | LOCK(dir->lock); 16 | dir->dd_loc = lseek(dir->dd_fd, off, SEEK_SET); 17 | dir->dd_buf = 0; 18 | UNLOCK(dir->lock); 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/dirent/telldir.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | long telldir(DIR *dir) 12 | { 13 | return dir->dd_loc; 14 | } 15 | -------------------------------------------------------------------------------- /src/ap/dirent/versionsort.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #define _GNU_SOURCE 10 | #include 11 | #include 12 | #include "libc.h" 13 | 14 | int versionsort(const struct dirent **a, const struct dirent **b) 15 | { 16 | return strverscmp((*a)->d_name, (*b)->d_name); 17 | } 18 | 19 | #undef versionsort64 20 | LFS64(versionsort); 21 | -------------------------------------------------------------------------------- /src/ap/gen/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = libap.a 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | CFLAGS += -I../internal -D_BSD_SOURCE 7 | 8 | .PHONY: all clean 9 | 10 | all: $(TARGET) clean 11 | 12 | %.o: %.c 13 | $(CC) $(CFLAGS) -c $(SRCS) 14 | 15 | $(TARGET): $(OBJ) 16 | ar rcs ${APEXLIB}/$@ $^ 17 | 18 | clean: 19 | rm -f $(OBJ) 20 | -------------------------------------------------------------------------------- /src/ap/gen/__ctype_get_mb_cur_max.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include "locale_impl.h" 11 | 12 | size_t __ctype_get_mb_cur_max() 13 | { 14 | return MB_CUR_MAX; 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/gen/abort.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | void 15 | abort(void) 16 | { 17 | kill(getpid(), SIGABRT); 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/gen/atof.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | double 13 | atof(const char *s) 14 | { 15 | return(strtod(s, (char **)0)); 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/gen/calloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | void * 14 | calloc(size_t nmemb, size_t size) 15 | { 16 | void *mp; 17 | 18 | nmemb = nmemb*size; 19 | if(mp = malloc(nmemb)) 20 | memset(mp, 0, nmemb); 21 | return(mp); 22 | } 23 | -------------------------------------------------------------------------------- /src/ap/gen/clock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | clock_t 14 | clock(void) 15 | { 16 | struct tms t; 17 | 18 | if(times(&t) == (clock_t)-1) 19 | return (clock_t)-1; 20 | return t.tms_utime+t.tms_stime; 21 | } 22 | -------------------------------------------------------------------------------- /src/ap/gen/difftime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | /* Difference in seconds between two calendar times */ 13 | 14 | double 15 | difftime(time_t t1, time_t t0) 16 | { 17 | return (double)t1-(double)t0; 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/gen/div.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | div_t div(int numer, int denom) 13 | { 14 | div_t ans; 15 | ans.quot=numer/denom; /* assumes division truncates */ 16 | ans.rem=numer-ans.quot*denom; 17 | return ans; 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/gen/getenv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | extern char **environ; 13 | 14 | char * 15 | getenv(const char *name) 16 | { 17 | char **p = environ; 18 | char *s1, *s2; 19 | 20 | while (*p != NULL){ 21 | for(s1 = (char *)name, s2 = *p++; *s1 == *s2; s1++, s2++) 22 | continue; 23 | if(*s1 == '\0' && *s2 == '=') 24 | return s2+1; 25 | } 26 | return NULL ; 27 | } 28 | -------------------------------------------------------------------------------- /src/ap/gen/isascii.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #undef isascii 11 | 12 | int isascii(int c) 13 | { 14 | return !(c&~0x7f); 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/gen/isblank.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include "libc.h" 11 | 12 | int isblank(int c) 13 | { 14 | return (c == ' ' || c == '\t'); 15 | } 16 | 17 | int __isblank_l(int c, locale_t l) 18 | { 19 | return isblank(c); 20 | } 21 | 22 | weak_alias(__isblank_l, isblank_l); 23 | -------------------------------------------------------------------------------- /src/ap/gen/iswalnum.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include "libc.h" 11 | 12 | int iswalnum(wint_t wc) 13 | { 14 | return iswdigit(wc) || iswalpha(wc); 15 | } 16 | 17 | int __iswalnum_l(wint_t c, locale_t l) 18 | { 19 | return iswalnum(c); 20 | } 21 | 22 | weak_alias(__iswalnum_l, iswalnum_l); 23 | -------------------------------------------------------------------------------- /src/ap/gen/iswalpha.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include "libc.h" 11 | 12 | static const unsigned char table[] = { 13 | #include "alpha.h" 14 | }; 15 | 16 | int iswalpha(wint_t wc) 17 | { 18 | if (wc<0x20000U) 19 | return (table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1; 20 | if (wc<0x2fffeU) 21 | return 1; 22 | return 0; 23 | } 24 | 25 | int __iswalpha_l(wint_t c, locale_t l) 26 | { 27 | return iswalpha(c); 28 | } 29 | 30 | weak_alias(__iswalpha_l, iswalpha_l); 31 | -------------------------------------------------------------------------------- /src/ap/gen/iswblank.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include "libc.h" 12 | 13 | int iswblank(wint_t wc) 14 | { 15 | return isblank(wc); 16 | } 17 | 18 | int __iswblank_l(wint_t c, locale_t l) 19 | { 20 | return iswblank(c); 21 | } 22 | 23 | weak_alias(__iswblank_l, iswblank_l); 24 | -------------------------------------------------------------------------------- /src/ap/gen/iswcntrl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include "libc.h" 11 | 12 | int iswcntrl(wint_t wc) 13 | { 14 | return (unsigned)wc < 32 15 | || (unsigned)(wc-0x7f) < 33 16 | || (unsigned)(wc-0x2028) < 2 17 | || (unsigned)(wc-0xfff9) < 3; 18 | } 19 | 20 | int __iswcntrl_l(wint_t c, locale_t l) 21 | { 22 | return iswcntrl(c); 23 | } 24 | 25 | weak_alias(__iswcntrl_l, iswcntrl_l); 26 | -------------------------------------------------------------------------------- /src/ap/gen/iswdigit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include "libc.h" 11 | 12 | #undef iswdigit 13 | 14 | int iswdigit(wint_t wc) 15 | { 16 | return (unsigned)wc-'0' < 10; 17 | } 18 | 19 | int __iswdigit_l(wint_t c, locale_t l) 20 | { 21 | return iswdigit(c); 22 | } 23 | 24 | weak_alias(__iswdigit_l, iswdigit_l); 25 | -------------------------------------------------------------------------------- /src/ap/gen/iswgraph.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include "libc.h" 11 | 12 | int iswgraph(wint_t wc) 13 | { 14 | /* ISO C defines this function as: */ 15 | return !iswspace(wc) && iswprint(wc); 16 | } 17 | 18 | int __iswgraph_l(wint_t c, locale_t l) 19 | { 20 | return iswgraph(c); 21 | } 22 | 23 | weak_alias(__iswgraph_l, iswgraph_l); 24 | -------------------------------------------------------------------------------- /src/ap/gen/iswlower.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include "libc.h" 11 | 12 | int iswlower(wint_t wc) 13 | { 14 | return towupper(wc) != wc; 15 | } 16 | 17 | int __iswlower_l(wint_t c, locale_t l) 18 | { 19 | return iswlower(c); 20 | } 21 | 22 | weak_alias(__iswlower_l, iswlower_l); 23 | -------------------------------------------------------------------------------- /src/ap/gen/iswpunct.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include "libc.h" 11 | 12 | static const unsigned char table[] = { 13 | #include "punct.h" 14 | }; 15 | 16 | int iswpunct(wint_t wc) 17 | { 18 | if (wc<0x20000U) 19 | return (table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1; 20 | return 0; 21 | } 22 | 23 | int __iswpunct_l(wint_t c, locale_t l) 24 | { 25 | return iswpunct(c); 26 | } 27 | 28 | weak_alias(__iswpunct_l, iswpunct_l); 29 | -------------------------------------------------------------------------------- /src/ap/gen/iswupper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include "libc.h" 11 | 12 | int iswupper(wint_t wc) 13 | { 14 | return towlower(wc) != wc; 15 | } 16 | 17 | int __iswupper_l(wint_t c, locale_t l) 18 | { 19 | return iswupper(c); 20 | } 21 | 22 | weak_alias(__iswupper_l, iswupper_l); 23 | -------------------------------------------------------------------------------- /src/ap/gen/iswxdigit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include "libc.h" 11 | 12 | int iswxdigit(wint_t wc) 13 | { 14 | return (unsigned)(wc-'0') < 10 || (unsigned)((wc|32)-'a') < 6; 15 | } 16 | 17 | int __iswxdigit_l(wint_t c, locale_t l) 18 | { 19 | return iswxdigit(c); 20 | } 21 | 22 | weak_alias(__iswxdigit_l, iswxdigit_l); 23 | -------------------------------------------------------------------------------- /src/ap/gen/itoa.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | int 13 | itoa(const char *s) 14 | { 15 | return(strtol(s, (char **)0, 10)); 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/gen/itol.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | long 13 | itol(const char *s) 14 | { 15 | return(strtol(s, (char **)0, 10)); 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/gen/ldiv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | ldiv_t ldiv(long numer, long denom) 13 | { 14 | ldiv_t ans; 15 | ans.quot=numer/denom; 16 | ans.rem=numer-ans.quot*denom; 17 | return ans; 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/gen/raise.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | /* not a posix function, but implemented with posix kill, getpid */ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | int 17 | raise(int sig) 18 | { 19 | return kill(getpid(), sig); 20 | } 21 | -------------------------------------------------------------------------------- /src/ap/gen/reduce: -------------------------------------------------------------------------------- 1 | O=$1 2 | shift 3 | objtype=$1 4 | shift 5 | 6 | ls -p ../$objtype/*.[cs] >[2]/dev/null | sed 's/..$//;s/^/^/' > /tmp/reduce.$pid 7 | # 8 | # if empty directory, just return the input files 9 | # 10 | if (! ~ $status '|') { 11 | echo $* 12 | rm /tmp/reduce.$pid 13 | exit 0 14 | } 15 | echo $* | tr ' ' \012 | grep -v -f /tmp/reduce.$pid | tr \012 ' ' 16 | rm /tmp/reduce.$pid 17 | -------------------------------------------------------------------------------- /src/ap/gen/strcoll.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | int 13 | strcoll(const char *s1, const char *s2) 14 | { 15 | /* BUG: supposed to pay attention to LC_COLLATE of current locale */ 16 | return strcmp(s1, s2); 17 | } 18 | -------------------------------------------------------------------------------- /src/ap/gen/strxfrm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | size_t 13 | strxfrm(char *s1, const char *s2, size_t n) 14 | { 15 | /* 16 | * BUG: supposed to transform s2 to a canonical form 17 | * so that strcmp can be used instead of strcoll, but 18 | * our strcoll just uses strcmp. 19 | */ 20 | 21 | size_t xn = strlen(s2); 22 | if(n > xn) 23 | n = xn; 24 | memcpy(s1, s2, n); 25 | return xn; 26 | } 27 | -------------------------------------------------------------------------------- /src/ap/gen/toascii.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | /* nonsense function that should NEVER be used! */ 12 | int toascii(int c) 13 | { 14 | return c & 0x7f; 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/gen/toupper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | int 13 | toupper(int c) 14 | { 15 | 16 | if(c < 'a' || c > 'z') 17 | return c; 18 | return (c-'a'+'A'); 19 | } 20 | 21 | int 22 | tolower(int c) 23 | { 24 | 25 | if(c < 'A' || c > 'Z') 26 | return c; 27 | return (c-'A'+'a'); 28 | } 29 | -------------------------------------------------------------------------------- /src/ap/gen/wcswidth.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | int wcswidth(const wchar_t *wcs, size_t n) 12 | { 13 | int l=0, k=0; 14 | for (; n-- && *wcs && (k = wcwidth(*wcs)) >= 0; l+=k, wcs++); 15 | return (k < 0) ? k : l; 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/internal/floatscan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #ifndef FLOATSCAN_H 10 | #define FLOATSCAN_H 11 | 12 | #include 13 | 14 | long double __floatscan(FILE *, int, int); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/ap/internal/intscan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #ifndef INTSCAN_H 10 | #define INTSCAN_H 11 | 12 | #ifndef __C99 13 | #define __C99 14 | #endif 15 | 16 | #include 17 | 18 | unsigned long long __intscan(FILE *, unsigned, int, unsigned long long); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/ap/internal/shgetc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | void __shlim(FILE *, off_t); 12 | int __shgetc(FILE *); 13 | 14 | #define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->rend)) 15 | #define shlim(f, lim) __shlim((f), (lim)) 16 | #define shgetc(f) (((f)->rpos < (f)->shend) ? *(f)->rpos++ : __shgetc(f)) 17 | #define shunget(f) ((f)->shend ? (void)(f)->rpos-- : (void)0) 18 | -------------------------------------------------------------------------------- /src/ap/locale/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = libap.a 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | CFLAGS += -I../internal -D_BSD_EXTENSION 7 | 8 | .PHONY: all clean 9 | 10 | all: $(TARGET) clean 11 | 12 | %.o: %.c 13 | $(CC) $(CFLAGS) -c $(SRCS) 14 | 15 | $(TARGET): $(OBJ) 16 | ar rcs ${APEXLIB}/$@ $^ 17 | 18 | clean: 19 | rm -f $(OBJ) 20 | -------------------------------------------------------------------------------- /src/ap/locale/__lctrans.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include "locale_impl.h" 13 | #include "libc.h" 14 | 15 | extern const char *__lctrans_impl(const char*, const struct __locale_map*); 16 | 17 | const char *__lctrans(const char *msg, const struct __locale_map *lm) 18 | { 19 | return __lctrans_impl(msg, lm); 20 | } 21 | 22 | const char *__lctrans_cur(const char *msg) 23 | { 24 | return __lctrans_impl(msg, 0); 25 | } 26 | -------------------------------------------------------------------------------- /src/ap/locale/c_locale.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "locale_impl.h" 10 | #include 11 | 12 | static const unsigned long empty_mo[] = { 0x950412de, 0, -1, -1, -1 }; 13 | 14 | const struct __locale_map __c_dot_utf8 = { 15 | .map = empty_mo, 16 | .map_size = sizeof empty_mo, 17 | .name = "C.UTF-8" 18 | }; 19 | 20 | const struct __locale_struct __c_locale = { 0 }; 21 | const struct __locale_struct __c_dot_utf8_locale = { 22 | .cat[LC_CTYPE] = &__c_dot_utf8 23 | }; 24 | -------------------------------------------------------------------------------- /src/ap/locale/wcscoll.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include "locale_impl.h" 12 | #include "libc.h" 13 | 14 | /* FIXME: stub */ 15 | int __wcscoll_l(const wchar_t *l, const wchar_t *r, locale_t locale) 16 | { 17 | return wcscmp(l, r); 18 | } 19 | 20 | int wcscoll(const wchar_t *l, const wchar_t *r) 21 | { 22 | return __wcscoll_l(l, r, 0); 23 | } 24 | 25 | weak_alias(__wcscoll_l, wcscoll_l); 26 | -------------------------------------------------------------------------------- /src/ap/locale/wcsxfrm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include "locale_impl.h" 12 | #include "libc.h" 13 | 14 | /* collate only by code points */ 15 | size_t __wcsxfrm_l(wchar_t *restrict dest, const wchar_t *restrict src, size_t n, locale_t loc) 16 | { 17 | size_t l = wcslen(src); 18 | if (l < n) { 19 | wmemcpy(dest, src, l+1); 20 | } else if (n) { 21 | wmemcpy(dest, src, n-1); 22 | dest[n-1] = 0; 23 | } 24 | return l; 25 | } 26 | 27 | size_t wcsxfrm(wchar_t *restrict dest, const wchar_t *restrict src, size_t n) 28 | { 29 | return __wcsxfrm_l(dest, src, n, 0); 30 | } 31 | -------------------------------------------------------------------------------- /src/ap/math/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = libap.a 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | CFLAGS += -I../internal 7 | 8 | .PHONY: all clean 9 | 10 | all: $(TARGET) clean 11 | 12 | %.o: %.c 13 | $(CC) $(CFLAGS) -c $(SRCS) 14 | 15 | $(TARGET): $(OBJ) 16 | ar rcs ${APEXLIB}/$@ $^ 17 | 18 | clean: 19 | rm -f $(OBJ) 20 | -------------------------------------------------------------------------------- /src/ap/math/__signbit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "libm.h" 10 | 11 | // FIXME: macro in math.h 12 | int __signbit(double x) 13 | { 14 | union { 15 | double d; 16 | uint64_t i; 17 | } y = { x }; 18 | return y.i>>63; 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/ap/math/__signbitl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "libm.h" 10 | 11 | #if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 12 | int __signbitl(long double x) 13 | { 14 | union ldshape u = {x}; 15 | return u.i.se >> 15; 16 | } 17 | #elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 18 | int __signbitl(long double x) 19 | { 20 | return __signbit(x); 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /src/ap/math/copysignl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "libm.h" 10 | 11 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 12 | long double copysignl(long double x, long double y) 13 | { 14 | return copysign(x, y); 15 | } 16 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 17 | long double copysignl(long double x, long double y) 18 | { 19 | union ldshape ux = {x}, uy = {y}; 20 | ux.i.se &= 0x7fff; 21 | ux.i.se |= uy.i.se & 0x8000; 22 | return ux.f; 23 | } 24 | #endif 25 | -------------------------------------------------------------------------------- /src/ap/math/fabs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | double 13 | fabs(double arg) 14 | { 15 | 16 | if(arg < 0) 17 | return -arg; 18 | return arg; 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/math/floor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | /* 12 | * floor and ceil-- greatest integer <= arg 13 | * (resp least >=) 14 | */ 15 | 16 | double 17 | floor(double d) 18 | { 19 | double fract; 20 | 21 | if(d < 0) { 22 | fract = modf(-d, &d); 23 | if(fract != 0.0) 24 | d += 1; 25 | d = -d; 26 | } else 27 | modf(d, &d); 28 | return d; 29 | } 30 | 31 | double 32 | ceil(double d) 33 | { 34 | return -floor(-d); 35 | } 36 | -------------------------------------------------------------------------------- /src/ap/math/scalbn.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | double scalbn(double x, int n) 13 | { 14 | union {double f; uint64_t i;} u; 15 | double_t y = x; 16 | 17 | if (n > 1023) { 18 | y *= 0x1p1023; 19 | n -= 1023; 20 | if (n > 1023) { 21 | y *= 0x1p1023; 22 | n -= 1023; 23 | if (n > 1023) 24 | n = 1023; 25 | } 26 | } else if (n < -1022) { 27 | y *= 0x1p-1022; 28 | n += 1022; 29 | if (n < -1022) { 30 | y *= 0x1p-1022; 31 | n += 1022; 32 | if (n < -1022) 33 | n = -1022; 34 | } 35 | } 36 | u.i = (uint64_t)(0x3ff+n)<<52; 37 | x = y * u.f; 38 | return x; 39 | } 40 | -------------------------------------------------------------------------------- /src/ap/mips/c_fcr0.s: -------------------------------------------------------------------------------- 1 | TEXT C_fcr0(SB), $0 2 | MOVW FCR0, R1 3 | RET 4 | -------------------------------------------------------------------------------- /src/ap/mips/cycles.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | void 11 | _cycles(unsigned long long *u) 12 | { 13 | *u = 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/ap/mips/getfcr.s: -------------------------------------------------------------------------------- 1 | TEXT getfsr(SB), $0 2 | MOVW FCR31, R1 3 | RET 4 | 5 | TEXT setfsr(SB), $0 6 | MOVW R1, FCR31 7 | RET 8 | 9 | TEXT getfcr(SB), $0 10 | MOVW FCR31, R1 11 | RET 12 | 13 | TEXT setfcr(SB), $0 14 | MOVW R1, FCR31 15 | RET 16 | -------------------------------------------------------------------------------- /src/ap/mips/main9.s: -------------------------------------------------------------------------------- 1 | TEXT _main(SB), $16 2 | MOVW $setR30(SB), R30 3 | JAL _envsetup(SB) 4 | MOVW inargc-4(FP), R1 5 | MOVW $inargv+0(FP), R2 6 | MOVW R1, 4(R29) 7 | MOVW R2, 8(R29) 8 | JAL main(SB) 9 | loop: 10 | MOVW R1, 4(R29) 11 | JAL exit(SB) 12 | JMP loop 13 | -------------------------------------------------------------------------------- /src/ap/mips/memchr.s: -------------------------------------------------------------------------------- 1 | TEXT memchr(SB), $0 2 | MOVW R1, 0(FP) 3 | 4 | MOVW n+8(FP), R1 5 | MOVW s1+0(FP), R2 6 | MOVBU c+7(FP), R3 7 | ADDU R1, R2, R6 8 | 9 | AND $(~1), R1, R5 10 | ADDU R2, R5 11 | BEQ R2, R5, lt2 12 | 13 | l1: 14 | MOVBU 0(R2), R4 15 | MOVBU 1(R2), R7 16 | BEQ R3, R4, eq0 17 | ADDU $2, R2 18 | BEQ R3, R7, eq 19 | BNE R2, R5, l1 20 | 21 | lt2: 22 | BEQ R2, R6, zret 23 | 24 | l2: 25 | MOVBU (R2), R4 26 | ADDU $1, R2 27 | BEQ R3, R4, eq 28 | BNE R2, R6, l2 29 | zret: 30 | MOVW R0, R1 31 | RET 32 | 33 | eq0: 34 | MOVW R2, R1 35 | RET 36 | 37 | eq: 38 | SUBU $1,R2, R1 39 | RET 40 | -------------------------------------------------------------------------------- /src/ap/mips/mkfile: -------------------------------------------------------------------------------- 1 | APE=/sys/src/ape 2 | <$APE/config 3 | LIB=/$objtype/lib/ape/libap.a 4 | OFILES=\ 5 | atom.$O\ 6 | c_fcr0.$O\ 7 | cycles.$O\ 8 | getfcr.$O\ 9 | lock.$O\ 10 | main9.$O\ 11 | main9p.$O\ 12 | memchr.$O\ 13 | memcmp.$O\ 14 | memmove.$O\ 15 | memset.$O\ 16 | notetramp.$O\ 17 | setjmp.$O\ 18 | strchr.$O\ 19 | strcmp.$O\ 20 | strcpy.$O\ 21 | tas.$O\ 22 | vlop.$O\ 23 | vlrt.$O\ 24 | 25 | longjmp(1)" */ 20 | MOVW $1, R3 /* bless their pointed heads */ 21 | ok: MOVW (R1), R29 22 | MOVW 4(R1), R31 23 | MOVW R3, R1 24 | RET 25 | -------------------------------------------------------------------------------- /src/ap/mips/strcmp.s: -------------------------------------------------------------------------------- 1 | TEXT strcmp(SB), $0 2 | 3 | MOVW s2+4(FP), R2 4 | 5 | l1: 6 | MOVB (R2), R3 7 | MOVB (R1), R4 8 | ADDU $1, R1 9 | BEQ R3, end 10 | ADDU $1, R2 11 | BEQ R3, R4, l1 12 | 13 | SGTU R4, R3, R1 14 | BNE R1, ret 15 | MOVW $-1, R1 16 | RET 17 | 18 | end: 19 | SGTU R4, R3, R1 20 | ret: 21 | RET 22 | -------------------------------------------------------------------------------- /src/ap/mips/tas.s: -------------------------------------------------------------------------------- 1 | /* 2 | * mips user level lock code 3 | */ 4 | 5 | #define LL(base, rt) WORD $((060<<26)|((base)<<21)|((rt)<<16)) 6 | #define SC(base, rt) WORD $((070<<26)|((base)<<21)|((rt)<<16)) 7 | #define NOOP WORD $0x27 8 | #define COP3 WORD $(023<<26) 9 | 10 | TEXT C_3ktas(SB),$0 11 | MOVW R1, R21 12 | btas: 13 | MOVW R21, R1 14 | MOVB R0, 1(R1) 15 | NOOP 16 | COP3 17 | BLTZ R1, btas 18 | RET 19 | 20 | TEXT tas(SB), $0 21 | TEXT C_4ktas(SB), $0 22 | MOVW R1, R2 /* address of key */ 23 | tas1: 24 | MOVW $1, R3 25 | LL(2, 1) 26 | NOOP 27 | SC(2, 3) 28 | NOOP 29 | BEQ R3, tas1 30 | RET 31 | -------------------------------------------------------------------------------- /src/ap/mips/vlop.s: -------------------------------------------------------------------------------- 1 | TEXT _mulv(SB), $0 2 | MOVW 8(FP), R2 3 | MOVW 4(FP), R3 4 | MOVW 16(FP), R4 5 | MOVW 12(FP), R5 6 | MULU R4, R2 7 | MOVW LO, R6 8 | MOVW HI, R7 9 | MULU R3, R4 10 | MOVW LO, R8 11 | ADDU R8, R7 12 | MULU R2, R5 13 | MOVW LO, R8 14 | ADDU R8, R7 15 | MOVW R6, 4(R1) 16 | MOVW R7, 0(R1) 17 | RET 18 | -------------------------------------------------------------------------------- /src/ap/multibyte/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = libap.a 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | CFLAGS += -I../internal 7 | 8 | .PHONY: all clean 9 | 10 | all: $(TARGET) clean 11 | 12 | %.o: %.c 13 | $(CC) $(CFLAGS) -c $(SRCS) 14 | 15 | $(TARGET): $(OBJ) 16 | ar rcs ${APEXLIB}/$@ $^ 17 | 18 | clean: 19 | rm -f $(OBJ) 20 | -------------------------------------------------------------------------------- /src/ap/multibyte/btowc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include "internal.h" 13 | 14 | wint_t btowc(int c) 15 | { 16 | int b = (unsigned char)c; 17 | return b<128U ? b : (MB_CUR_MAX==1 && c!=EOF) ? CODEUNIT(c) : WEOF; 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/multibyte/mblen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code was written by Rich Felker in 2010; no copyright is claimed. 3 | * This code is in the public domain. Attribution is appreciated but 4 | * unnecessary. 5 | */ 6 | 7 | #include 8 | 9 | int mblen(const char *s, size_t n) 10 | { 11 | return mbtowc(0, s, n); 12 | } 13 | -------------------------------------------------------------------------------- /src/ap/multibyte/mbrlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code was written by Rich Felker in 2010; no copyright is claimed. 3 | * This code is in the public domain. Attribution is appreciated but 4 | * unnecessary. 5 | */ 6 | 7 | #include 8 | 9 | size_t mbrlen(const char *restrict s, size_t n, mbstate_t *restrict st) 10 | { 11 | static unsigned internal; 12 | return mbrtowc(0, s, n, st ? st : (mbstate_t *)&internal); 13 | } 14 | -------------------------------------------------------------------------------- /src/ap/multibyte/mbsinit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code was written by Rich Felker in 2010; no copyright is claimed. 3 | * This code is in the public domain. Attribution is appreciated but 4 | * unnecessary. 5 | */ 6 | 7 | #include 8 | 9 | int mbsinit(const mbstate_t *st) 10 | { 11 | return !st || !*(unsigned *)st; 12 | } 13 | -------------------------------------------------------------------------------- /src/ap/multibyte/mbstowcs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | size_t mbstowcs(wchar_t *restrict ws, const char *restrict s, size_t wn) 13 | { 14 | return mbsrtowcs(ws, (void*)&s, wn, 0); 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/multibyte/wcstombs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | size_t wcstombs(char *restrict s, const wchar_t *restrict ws, size_t n) 13 | { 14 | return wcsrtombs(s, &(const wchar_t *){ws}, n, 0); 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/multibyte/wctob.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include "internal.h" 12 | 13 | int wctob(wint_t c) 14 | { 15 | if (c < 128U) return c; 16 | if (MB_CUR_MAX==1 && IS_CODEUNIT(c)) return (unsigned char)c; 17 | return EOF; 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/multibyte/wctomb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This code was written by Rich Felker in 2010; no copyright is claimed. 3 | * This code is in the public domain. Attribution is appreciated but 4 | * unnecessary. 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | int wctomb(char *s, wchar_t wc) 11 | { 12 | if (!s) return 0; 13 | return wcrtomb(s, wc, 0); 14 | } 15 | -------------------------------------------------------------------------------- /src/ap/plan9/9mallocz.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | void* 14 | _MALLOCZ(int n, int clr) 15 | { 16 | void *v; 17 | 18 | v = malloc(n); 19 | if(v && clr) 20 | memset(v, 0, n); 21 | return v; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/ap/plan9/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = libap.a 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | CFLAGS += -I../internal -D_PLAN9_SOURCE -D_BSD_EXTENSION 7 | 8 | .PHONY: all clean 9 | 10 | all: $(TARGET) clean 11 | 12 | %.o: %.c 13 | $(CC) $(CFLAGS) -c $(SRCS) || exit 1 14 | 15 | $(TARGET): $(OBJ) 16 | ar rcs ${APEXLIB}/$@ $^ 17 | 18 | clean: 19 | rm -f $(OBJ) 20 | -------------------------------------------------------------------------------- /src/ap/plan9/__environ.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2018 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "libc.h" 10 | 11 | char **__environ = 0; 12 | weak_alias(__environ, ___environ); 13 | weak_alias(__environ, _environ); 14 | weak_alias(__environ, environ); 15 | -------------------------------------------------------------------------------- /src/ap/plan9/__sys_alarm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "sys9.h" 11 | 12 | /* syscall in libc */ 13 | extern int64_t alarm(uint64_t); 14 | 15 | int64_t 16 | __sys_alarm(uint64_t u) 17 | { 18 | return alarm(u); 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/plan9/__sys_chdir.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "sys9.h" 11 | 12 | /* syscall in libc */ 13 | extern int chdir(const char*); 14 | 15 | int 16 | __sys_chdir(const char* c) 17 | { 18 | return chdir(c); 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/plan9/__sys_close.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "sys9.h" 11 | 12 | /* syscall in libc */ 13 | extern int close(int); 14 | 15 | int 16 | __sys_close(int i) 17 | { 18 | return close(i); 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/plan9/__sys_dup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "sys9.h" 11 | 12 | /* syscall in libc */ 13 | extern int dup(int, int); 14 | 15 | int 16 | __sys_dup(int n, int i) 17 | { 18 | return dup(n, i); 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/plan9/__sys_open.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "sys9.h" 11 | 12 | /* syscall in libc */ 13 | extern int open(const char *, int); 14 | 15 | int 16 | __sys_open(const char *c, int i) 17 | { 18 | return open(c, i); 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/plan9/__sys_pipe.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "sys9.h" 11 | 12 | /* syscall in libc */ 13 | extern int pipe(int *); 14 | 15 | int 16 | __sys_pipe(int *fd) 17 | { 18 | return pipe(fd); 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/plan9/__sys_read.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "sys9.h" 11 | 12 | int 13 | __sys_read(int fd, void* buf, int32_t nbytes) 14 | { 15 | return pread(fd, buf, nbytes, -1LL); 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/plan9/__sys_remove.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "sys9.h" 11 | 12 | /* syscall in libc */ 13 | extern int remove(const char *); 14 | 15 | int 16 | __sys_remove(const char *c) 17 | { 18 | return remove(c); 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/plan9/__sys_sleep.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "sys9.h" 11 | 12 | /* syscall in libc */ 13 | extern int sleep(int32_t); 14 | 15 | int 16 | __sys_sleep(int32_t i) 17 | { 18 | return sleep(i); 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/plan9/__sys_stat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "sys9.h" 11 | 12 | /* syscalls in libc */ 13 | extern int stat(const char*, unsigned char*, int); 14 | extern int fstat(int, unsigned char*, int); 15 | 16 | int 17 | __sys_stat(const char *c, unsigned char *a, int i) 18 | { 19 | return stat(c, a, i); 20 | } 21 | 22 | int 23 | __sys_fstat(int i, unsigned char *c, int n) 24 | { 25 | return fstat(i, c, n); 26 | } 27 | -------------------------------------------------------------------------------- /src/ap/plan9/__sys_write.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "sys9.h" 11 | 12 | int 13 | __sys_write(int fd, const void* buf, int32_t nbytes) 14 | { 15 | return pwrite(fd, buf, nbytes, -1LL); 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/plan9/_alarm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include "sys9.h" 12 | 13 | unsigned int 14 | __alarm(unsigned seconds) 15 | { 16 | return __sys_alarm(seconds*1000); 17 | } 18 | -------------------------------------------------------------------------------- /src/ap/plan9/_chdir.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "lib.h" 11 | #include 12 | #include "sys9.h" 13 | 14 | int 15 | __chdir(const char *f) 16 | { 17 | int n; 18 | 19 | n = __sys_chdir(f); 20 | if(n < 0) 21 | _syserrno(); 22 | return n; 23 | } 24 | -------------------------------------------------------------------------------- /src/ap/plan9/_nap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "lib.h" 11 | #include 12 | #include 13 | #include "sys9.h" 14 | 15 | /* 16 | * This is an extension to POSIX 17 | */ 18 | unsigned int 19 | _nap(unsigned int millisecs) 20 | { 21 | time_t t0, t1; 22 | 23 | t0 = time(0); 24 | if(__sys_sleep(millisecs) < 0){ 25 | t1 = time(0); 26 | return t1-t0; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /src/ap/plan9/_sleep.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "lib.h" 11 | #include 12 | #include 13 | #include "sys9.h" 14 | 15 | unsigned int 16 | __sleep(unsigned int secs) 17 | { 18 | time_t t0, t1; 19 | 20 | t0 = time(0); 21 | if(__sys_sleep(secs*1000) < 0){ 22 | t1 = time(0); 23 | return t1-t0; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/ap/plan9/cfgetospeed.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | speed_t 13 | cfgetospeed(const struct termios *t) 14 | { 15 | return B0; 16 | } 17 | 18 | int 19 | cfsetospeed(struct termios *t, speed_t s) 20 | { 21 | return 0; 22 | } 23 | 24 | speed_t 25 | cfgetispeed(const struct termios *t) 26 | { 27 | return B0; 28 | } 29 | 30 | int 31 | cfsetispeed(struct termios *t, speed_t s) 32 | { 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/ap/plan9/creat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "lib.h" 11 | #include 12 | #include 13 | 14 | int 15 | creat(const char *name, mode_t mode) 16 | { 17 | int n; 18 | 19 | n = open(name, O_WRONLY | O_CREAT | O_TRUNC, mode); 20 | /* no need to _syserrno; open did it already */ 21 | return n; 22 | } 23 | -------------------------------------------------------------------------------- /src/ap/plan9/ctermid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | char * 15 | ctermid(char *s) 16 | { 17 | static char buf[L_ctermid]; 18 | 19 | if(s == 0) 20 | s = buf; 21 | strncpy(s, "/dev/cons", sizeof buf); 22 | return(s); 23 | } 24 | 25 | char * 26 | ctermid_r(char *s) 27 | { 28 | return s ? ctermid(s) : NULL; 29 | } 30 | -------------------------------------------------------------------------------- /src/ap/plan9/execle.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | extern char **environ; 13 | 14 | int execle(const char *path, const char *argv0, ...) 15 | { 16 | int argc; 17 | va_list ap; 18 | va_start(ap, argv0); 19 | for (argc=1; va_arg(ap, const char *); argc++); 20 | va_end(ap); 21 | { 22 | int i; 23 | char *argv[argc+1]; 24 | va_start(ap, argv0); 25 | argv[0] = (char *)argv0; 26 | for (i=1; i<=argc; i++) 27 | argv[i] = va_arg(ap, char *); 28 | va_end(ap); 29 | return execve(path, argv, environ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/ap/plan9/execv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | extern char **environ; 13 | 14 | int 15 | execv(const char *name, char *const argv[]) 16 | { 17 | return execve(name, argv, environ); 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/plan9/fork.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "lib.h" 11 | #include 12 | #include 13 | #include "sys9.h" 14 | 15 | pid_t 16 | _fork(void) 17 | { 18 | int n; 19 | 20 | n = rfork(RFENVG|RFFDG|RFPROC); 21 | if(n < 0) 22 | _syserrno(); 23 | if(n == 0) { 24 | _sessleader = 0; 25 | } 26 | return n; 27 | } 28 | -------------------------------------------------------------------------------- /src/ap/plan9/fstat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "lib.h" 11 | #include 12 | #include 13 | #include 14 | #include "sys9.h" 15 | #include "dir.h" 16 | 17 | int 18 | __fstat(int fd, struct stat *buf) 19 | { 20 | Dir *d; 21 | 22 | if((d = _dirfstat(fd)) == nil){ 23 | _syserrno(); 24 | return -1; 25 | } 26 | dirtostat(buf, d, &_fdinfo[fd]); 27 | free(d); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /src/ap/plan9/fsync.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int 15 | fsync(int i) 16 | { 17 | errno = EINVAL; 18 | return -1; 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/plan9/ftruncate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "lib.h" 11 | #include 12 | #include 13 | #include 14 | #include "dir.h" 15 | 16 | int 17 | ftruncate(int fd, off_t length) 18 | { 19 | Dir d; 20 | 21 | if(length < 0){ 22 | errno = EINVAL; 23 | return -1; 24 | } 25 | _nulldir(&d); 26 | d.length = length; 27 | if(_dirfwstat(fd, &d) < 0){ 28 | _syserrno(); 29 | return -1; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /src/ap/plan9/getgid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | /* 15 | * BUG: assumes group that is same as user name 16 | * is the one wanted (plan 9 has no "current group") 17 | */ 18 | gid_t 19 | getgid(void) 20 | { 21 | struct group *g; 22 | g = getgrnam(getlogin()); 23 | return g? g->gr_gid : 1; 24 | } 25 | 26 | gid_t 27 | getegid(void) 28 | { 29 | return getgid(); 30 | } 31 | -------------------------------------------------------------------------------- /src/ap/plan9/getgroups.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int 15 | getgroups(int i, gid_t g[]) 16 | { 17 | errno = EINVAL; 18 | return -1; 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/plan9/getuid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | uid_t 15 | getuid(void) 16 | { 17 | struct passwd *p; 18 | p = getpwnam(getlogin()); 19 | return p? p->pw_uid : 1; 20 | } 21 | 22 | uid_t 23 | geteuid(void) 24 | { 25 | return getuid(); 26 | } 27 | -------------------------------------------------------------------------------- /src/ap/plan9/link.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | /* 14 | * BUG: LINK_MAX==1 isn't really allowed 15 | */ 16 | int 17 | link(const char *c, const char *d) 18 | { 19 | errno = EMLINK; 20 | return -1; 21 | } 22 | -------------------------------------------------------------------------------- /src/ap/plan9/panic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "sys9.h" 11 | #include 12 | 13 | void panic(char *s) 14 | { 15 | fprintf(stderr, "panic: %s\n", s); 16 | _exits(s); 17 | } 18 | -------------------------------------------------------------------------------- /src/ap/plan9/pause.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "lib.h" 11 | #include 12 | #include "sys9.h" 13 | 14 | int 15 | pause(void) 16 | { 17 | for(;;) 18 | if(__sys_sleep(1000*1000) < 0) 19 | return -1; 20 | } 21 | -------------------------------------------------------------------------------- /src/ap/plan9/rmdir.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "lib.h" 11 | #include 12 | #include 13 | #include "sys9.h" 14 | 15 | int 16 | rmdir(const char *path) 17 | { 18 | int n; 19 | 20 | n = 0; 21 | if(__sys_remove(path) < 0) { 22 | _syserrno(); 23 | n = -1; 24 | } 25 | return n; 26 | } 27 | -------------------------------------------------------------------------------- /src/ap/plan9/setgid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | /* 15 | * BUG: never works 16 | */ 17 | 18 | int 19 | setgid(gid_t g) 20 | { 21 | errno = EPERM; 22 | return -1; 23 | } 24 | -------------------------------------------------------------------------------- /src/ap/plan9/setsid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "lib.h" 11 | #include 12 | #include "sys9.h" 13 | 14 | pid_t 15 | setsid(void) 16 | { 17 | if(rfork(RFNAMEG|RFNOTEG) < 0){ 18 | _syserrno(); 19 | return -1; 20 | } 21 | _sessleader = 1; 22 | return getpgrp(); 23 | } 24 | -------------------------------------------------------------------------------- /src/ap/plan9/setuid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | /* 15 | * BUG: never works 16 | */ 17 | 18 | int 19 | setuid(uid_t u) 20 | { 21 | errno = EPERM; 22 | return -1; 23 | } 24 | -------------------------------------------------------------------------------- /src/ap/plan9/sigpending.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | /* 13 | * BUG: don't keep track of these 14 | */ 15 | int 16 | sigpending(sigset_t *set) 17 | { 18 | *set = 0; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/ap/plan9/stat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include "lib.h" 11 | #include 12 | #include 13 | #include 14 | #include "sys9.h" 15 | #include "dir.h" 16 | 17 | int 18 | __stat_ap(const char *path, struct stat *buf) 19 | { 20 | Dir *d; 21 | 22 | if((d = _dirstat(path)) == nil){ 23 | _syserrno(); 24 | return -1; 25 | } 26 | dirtostat(buf, d, 0); 27 | free(d); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /src/ap/plan9/ttyname.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | char * 14 | ttyname(int fd) 15 | { 16 | static char buf[100]; 17 | 18 | sprintf(buf, "/fd/%d", fd); 19 | return buf; 20 | } 21 | -------------------------------------------------------------------------------- /src/ap/plan9/umask.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | /* 15 | * No such concept in plan9, but supposed to be always successful 16 | */ 17 | 18 | mode_t 19 | umask(mode_t m) 20 | { 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/ap/posix/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = libap.a 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | 7 | .PHONY: all clean 8 | 9 | all: $(TARGET) clean 10 | 11 | %.o: %.c 12 | $(CC) $(CFLAGS) -c $(SRCS) 13 | 14 | $(TARGET): $(OBJ) 15 | ar rcs ${APEXLIB}/$@ $^ 16 | 17 | clean: 18 | rm -f $(OBJ) 19 | -------------------------------------------------------------------------------- /src/ap/posix/mkfifo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int 15 | mkfifo(const char *c, mode_t _unused) 16 | { 17 | errno = 0; 18 | return -1; 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/power/cycles.s: -------------------------------------------------------------------------------- 1 | #define TBRL 268 2 | #define TBRU 269 /* Time base Upper/Lower (Reading) */ 3 | 4 | /* 5 | * time stamp counter; _cycles since power up 6 | * Runs at fasthz/4 cycles per second (m->clkin>>3) 7 | */ 8 | TEXT _cycles(SB),1,$0 9 | loop: 10 | MOVW SPR(TBRU),R7 11 | MOVW SPR(TBRL),R8 12 | MOVW SPR(TBRU),R5 13 | CMP R5,R7 14 | BNE loop 15 | MOVW R7,0(R3) 16 | MOVW R8,4(R3) 17 | RETURN 18 | -------------------------------------------------------------------------------- /src/ap/power/getfcr.s: -------------------------------------------------------------------------------- 1 | TEXT getfcr(SB), $8 2 | MOVFL FPSCR, F3 3 | FMOVD F3, f-8(SP) 4 | MOVW -4(SP), R3 5 | RETURN 6 | 7 | TEXT getfsr(SB), $8 8 | MOVFL FPSCR, F3 9 | FMOVD F3, f-8(SP) 10 | MOVW -4(SP), R3 11 | RETURN 12 | 13 | TEXT setfcr(SB), $8 14 | SYNC 15 | MOVW R3, -4(SP) 16 | FMOVD -8(SP), F3 17 | MOVFL F3, FPSCR 18 | ISYNC 19 | RETURN 20 | 21 | TEXT setfsr(SB), $8 22 | SYNC 23 | MOVW R3, -4(SP) 24 | FMOVD -8(SP), F3 25 | MOVFL F3, FPSCR 26 | ISYNC 27 | RETURN 28 | 29 | -------------------------------------------------------------------------------- /src/ap/power/main9.s: -------------------------------------------------------------------------------- 1 | TEXT _main(SB), 1, $16 2 | 3 | MOVW $setSB(SB), R2 4 | 5 | BL _envsetup(SB) 6 | MOVW inargc-4(FP), R3 7 | MOVW $inargv+0(FP), R4 8 | MOVW R3, 4(R1) 9 | MOVW R4, 8(R1) 10 | BL main(SB) 11 | loop: 12 | MOVW R3, 4(R1) 13 | BL exit(SB) 14 | BR loop 15 | -------------------------------------------------------------------------------- /src/ap/power/mkfile: -------------------------------------------------------------------------------- 1 | APE=/sys/src/ape 2 | <$APE/config 3 | LIB=/$objtype/lib/ape/libap.a 4 | OFILES=\ 5 | atom.$O\ 6 | cycles.$O\ 7 | getfcr.$O\ 8 | lock.$O\ 9 | main9.$O\ 10 | main9p.$O\ 11 | memcmp.$O\ 12 | memmove.$O\ 13 | memset.$O\ 14 | notetramp.$O\ 15 | setjmp.$O\ 16 | strcmp.$O\ 17 | tas.$O\ 18 | vlop.$O\ 19 | vlrt.$O\ 20 | 21 | longjmp(1)" */ 24 | MOVW $1, R3 /* bless their pointed heads */ 25 | ok: MOVW (R4), R1 26 | MOVW 4(R4), R4 27 | MOVW R4, LR 28 | BR (LR) 29 | 30 | /* 31 | * trampoline functions because the kernel smashes r1 32 | * in the uregs given to notejmp 33 | */ 34 | TEXT __noterestore(SB), 1, $-4 35 | MOVW R4, R3 36 | MOVW R5, LR 37 | BR (LR) 38 | -------------------------------------------------------------------------------- /src/ap/power/strcmp.s: -------------------------------------------------------------------------------- 1 | TEXT strcmp(SB), $0 2 | 3 | MOVW s2+4(FP), R4 4 | 5 | SUB $1, R3 6 | SUB $1, R4 7 | l1: 8 | MOVBZU 1(R3), R5 9 | MOVBZU 1(R4), R6 10 | CMP R5, R6 11 | BNE ne 12 | CMP R5, $0 13 | BNE l1 14 | MOVW $0, R3 15 | RETURN 16 | ne: 17 | MOVW $1, R3 18 | BGT ret 19 | MOVW $-1, R3 20 | ret: 21 | RETURN 22 | -------------------------------------------------------------------------------- /src/ap/power/tas.s: -------------------------------------------------------------------------------- 1 | TEXT tas(SB), $0 2 | SYNC 3 | MOVW R3, R4 4 | MOVW $0xdeaddead,R5 5 | tas1: 6 | DCBF (R4) /* fix for 603x bug */ 7 | LWAR (R4), R3 8 | CMP R3, $0 9 | BNE tas0 10 | DCBT (R4) /* fix 405 errata cpu_210 */ 11 | STWCCC R5, (R4) 12 | BNE tas1 13 | tas0: 14 | SYNC 15 | ISYNC 16 | RETURN 17 | -------------------------------------------------------------------------------- /src/ap/regex/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = libap.a 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | CFLAGS += -I../internal -D_RESEARCH_SOURCE 7 | 8 | .PHONY: all clean 9 | 10 | all: $(TARGET) clean 11 | 12 | %.o: %.c 13 | $(CC) $(CFLAGS) -c $(SRCS) 14 | 15 | $(TARGET): $(OBJ) 16 | ar rcs ${APEXLIB}/$@ $^ 17 | 18 | clean: 19 | rm -f $(OBJ) 20 | -------------------------------------------------------------------------------- /src/ap/sparc/cycles.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | void 11 | _cycles(unsigned long long *u) 12 | { 13 | *u = 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/ap/sparc/main9.s: -------------------------------------------------------------------------------- 1 | TEXT _main(SB), $16 2 | MOVW $setSB(SB), R2 3 | JMPL _envsetup(SB) 4 | MOVW inargc-4(FP), R7 5 | MOVW $inargv+0(FP), R8 6 | MOVW R7, 4(R1) 7 | MOVW R8, 8(R1) 8 | JMPL main(SB) 9 | 10 | loop: 11 | MOVW R7, 4(R1) 12 | JMPL exit(SB) 13 | MOVW $_mul(SB),R7 14 | JMP loop 15 | -------------------------------------------------------------------------------- /src/ap/sparc/memchr.s: -------------------------------------------------------------------------------- 1 | TEXT memchr(SB), $0 2 | 3 | MOVW R7, 0(FP) 4 | MOVW n+8(FP), R7 5 | SUBCC R0,R7, R0 6 | BE ret 7 | MOVW s1+0(FP), R8 8 | MOVBU c+7(FP), R9 9 | ADD R7,R8, R11 10 | 11 | l1: 12 | MOVBU (R8), R10 13 | SUBCC R9,R10, R0 14 | ADD $1, R8 15 | BE eq 16 | SUBCC R8,R11, R0 17 | BNE l1 18 | 19 | MOVW R0, R7 20 | RETURN 21 | 22 | eq: 23 | SUB $1,R8, R7 24 | 25 | ret: 26 | RETURN 27 | -------------------------------------------------------------------------------- /src/ap/sparc/mkfile: -------------------------------------------------------------------------------- 1 | APE=/sys/src/ape 2 | <$APE/config 3 | LIB=/$objtype/lib/ape/libap.a 4 | OFILES=\ 5 | # atom.$O\ 6 | cycles.$O\ 7 | lock.$O\ 8 | main9.$O\ 9 | main9p.$O\ 10 | memchr.$O\ 11 | memcmp.$O\ 12 | memmove.$O\ 13 | memset.$O\ 14 | muldiv.$O\ 15 | notetramp.$O\ 16 | setjmp.$O\ 17 | strchr.$O\ 18 | strcmp.$O\ 19 | strcpy.$O\ 20 | tas.$O\ 21 | vlop.$O\ 22 | vlrt.$O\ 23 | 24 | longjmp(1)" */ 25 | MOVW $1, R7 /* bless their pointed heads */ 26 | ok: MOVW (R8), R1 27 | MOVW 4(R8), R15 28 | RETURN 29 | 30 | /* 31 | * trampoline functions because the kernel smashes r7 32 | * in the uregs given to notejmp 33 | */ 34 | TEXT __noterestore(SB), 1, $-4 35 | MOVW R8, R7 36 | JMP (R9) 37 | -------------------------------------------------------------------------------- /src/ap/sparc/strcmp.s: -------------------------------------------------------------------------------- 1 | TEXT strcmp(SB), $0 2 | 3 | MOVW s2+4(FP), R10 4 | 5 | l1: 6 | MOVB 0(R7), R8 7 | MOVB 0(R10), R9 8 | ADD $1, R7 9 | ADD $1, R10 10 | 11 | CMP R8, R9 12 | BNE l2 13 | 14 | CMP R8, $0 15 | BNE l1 16 | 17 | MOVW R0, R7 18 | RETURN 19 | 20 | l2: 21 | BLEU l3 22 | MOVW $1, R7 23 | RETURN 24 | 25 | l3: 26 | MOVW $-1, R7 27 | RETURN 28 | -------------------------------------------------------------------------------- /src/ap/sparc/tas.s: -------------------------------------------------------------------------------- 1 | /* 2 | * tas uses LDSTUB 3 | */ 4 | TEXT tas(SB),$-4 5 | 6 | TAS (R7),R7 7 | RETURN 8 | -------------------------------------------------------------------------------- /src/ap/stdio/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = libap.a 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | CFLAGS += -I../internal -D_BSD_EXTENSION -D_BSD_SOURCE 7 | 8 | .PHONY: all clean 9 | 10 | all: $(TARGET) clean 11 | 12 | %.o: %.c 13 | $(CC) $(CFLAGS) -c $(SRCS) 14 | 15 | $(TARGET): $(OBJ) 16 | ar rcs ${APEXLIB}/$@ $^ 17 | 18 | clean: 19 | rm -f $(OBJ) 20 | -------------------------------------------------------------------------------- /src/ap/stdio/__fmodeflags.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int __fmodeflags(const char *mode) 13 | { 14 | int flags; 15 | if (strchr(mode, '+')) flags = O_RDWR; 16 | else if (*mode == 'r') flags = O_RDONLY; 17 | else flags = O_WRONLY; 18 | if (strchr(mode, 'x')) flags |= O_EXCL; 19 | if (strchr(mode, 'e')) flags |= O_CLOEXEC; 20 | if (*mode != 'r') flags |= O_CREAT; 21 | if (*mode == 'w') flags |= O_TRUNC; 22 | if (*mode == 'a') flags |= O_APPEND; 23 | return flags; 24 | } 25 | -------------------------------------------------------------------------------- /src/ap/stdio/__overflow.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | int __overflow(FILE *f, int _c) 12 | { 13 | unsigned char c = _c; 14 | if (!f->wend && __towrite(f)) return EOF; 15 | if (f->wpos < f->wend && c != f->lbf) return *f->wpos++ = c; 16 | if (f->write(f, &c, 1)!=1) return EOF; 17 | return c; 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/stdio/__stdio_close.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include 11 | 12 | static int __aio_close(int fd) 13 | { 14 | return fd; 15 | } 16 | 17 | int __stdio_close(FILE *f) 18 | { 19 | return close(__aio_close(f->fd)); 20 | } 21 | -------------------------------------------------------------------------------- /src/ap/stdio/__stdio_seek.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include 11 | 12 | off_t __stdio_seek(FILE *f, off_t off, int whence) 13 | { 14 | off_t ret; 15 | ret = lseek(f->fd, off, whence); 16 | return ret; 17 | } 18 | -------------------------------------------------------------------------------- /src/ap/stdio/__string_read.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include 11 | 12 | size_t __string_read(FILE *f, unsigned char *buf, size_t len) 13 | { 14 | char *src = f->cookie; 15 | size_t k = len+256; 16 | char *end = memchr(src, 0, k); 17 | if (end) k = end-src; 18 | if (k < len) len = k; 19 | memcpy(buf, src, len); 20 | f->rpos = (void *)(src+len); 21 | f->rend = (void *)(src+k); 22 | f->cookie = src+k; 23 | return len; 24 | } 25 | -------------------------------------------------------------------------------- /src/ap/stdio/__toread.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | int __toread(FILE *f) 12 | { 13 | f->mode |= f->mode-1; 14 | if (f->wpos > f->buf) f->write(f, 0, 0); 15 | f->wpos = f->wbase = f->wend = 0; 16 | if (f->flags & F_NORD) { 17 | f->flags |= F_ERR; 18 | return EOF; 19 | } 20 | f->rpos = f->rend = f->buf + f->buf_size; 21 | return (f->flags & F_EOF) ? EOF : 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/ap/stdio/__towrite.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | int __towrite(FILE *f) 12 | { 13 | f->mode |= f->mode-1; 14 | if (f->flags & (F_NOWR)) { 15 | f->flags |= F_ERR; 16 | return EOF; 17 | } 18 | /* Clear read buffer (easier than summoning nasal demons) */ 19 | f->rpos = f->rend = 0; 20 | 21 | /* Activate write through the buffer. */ 22 | f->wpos = f->wbase = f->buf; 23 | f->wend = f->buf + f->buf_size; 24 | 25 | return 0; 26 | } 27 | 28 | void __stdio_exit_needed(void); 29 | 30 | void __towrite_needs_stdio_exit() 31 | { 32 | __stdio_exit_needed(); 33 | } 34 | -------------------------------------------------------------------------------- /src/ap/stdio/__uflow.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | /* This function assumes it will never be called if there is already 12 | * data buffered for reading. */ 13 | 14 | int __uflow(FILE *f) 15 | { 16 | unsigned char c; 17 | if (!__toread(f) && f->read(f, &c, 1)==1) return c; 18 | return EOF; 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/stdio/_atexit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the UCB release of Plan 9. It is subject to the license 3 | * terms in the LICENSE file found in the top-level directory of this 4 | * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No 5 | * part of the UCB release of Plan 9, including this file, may be copied, 6 | * modified, propagated, or distributed except according to the terms contained 7 | * in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #define NONEXIT 34 12 | extern void (*_atexitfns[NONEXIT])(void); 13 | 14 | int 15 | __atexit(void (*f)(void)) 16 | { 17 | int i; 18 | for(i=0; i 15 | 16 | int __remove(const char *f){ 17 | return unlink((char *)f); 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/stdio/asprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #define _GNU_SOURCE 10 | #include 11 | #include 12 | 13 | int asprintf(char **s, const char *fmt, ...) 14 | { 15 | int ret; 16 | va_list ap; 17 | va_start(ap, fmt); 18 | ret = vasprintf(s, fmt, ap); 19 | va_end(ap); 20 | return ret; 21 | } 22 | -------------------------------------------------------------------------------- /src/ap/stdio/clearerr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | void clearerr(FILE *f) 12 | { 13 | FLOCK(f); 14 | f->flags &= ~(F_EOF|F_ERR); 15 | FUNLOCK(f); 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/stdio/ext2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | size_t __freadahead(FILE *f) 12 | { 13 | return f->rend - f->rpos; 14 | } 15 | 16 | const char *__freadptr(FILE *f, size_t *sizep) 17 | { 18 | size_t size = f->rend - f->rpos; 19 | if (!size) return 0; 20 | *sizep = size; 21 | return (const char *)f->rpos; 22 | } 23 | 24 | void __freadptrinc(FILE *f, size_t inc) 25 | { 26 | f->rpos += inc; 27 | } 28 | 29 | void __fseterr(FILE *f) 30 | { 31 | f->flags |= F_ERR; 32 | } 33 | -------------------------------------------------------------------------------- /src/ap/stdio/feof.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | #undef feof 12 | 13 | int feof(FILE *f) 14 | { 15 | FLOCK(f); 16 | int ret = !!(f->flags & F_EOF); 17 | FUNLOCK(f); 18 | return ret; 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/stdio/ferror.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | #undef ferror 12 | 13 | int ferror(FILE *f) 14 | { 15 | FLOCK(f); 16 | int ret = !!(f->flags & F_ERR); 17 | FUNLOCK(f); 18 | return ret; 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/stdio/fgetc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | int fgetc(FILE *f) 12 | { 13 | int c; 14 | if (f->lock < 0 || !__lockfile(f)) 15 | return getc_unlocked(f); 16 | c = getc_unlocked(f); 17 | __unlockfile(f); 18 | return c; 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/stdio/fgetpos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | int fgetpos(FILE *restrict f, fpos_t *restrict pos) 12 | { 13 | off_t off = ftello(f); 14 | if (off < 0) return -1; 15 | *(off_t *)pos = off; 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/ap/stdio/fgetws.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include 11 | 12 | wint_t __fgetwc_unlocked(FILE *); 13 | 14 | wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f) 15 | { 16 | wchar_t *p = s; 17 | 18 | if (!n--) return s; 19 | 20 | FLOCK(f); 21 | 22 | for (; n; n--) { 23 | wint_t c = __fgetwc_unlocked(f); 24 | if (c == WEOF) break; 25 | *p++ = c; 26 | if (c == '\n') break; 27 | } 28 | *p = 0; 29 | if (ferror(f)) p = s; 30 | 31 | FUNLOCK(f); 32 | 33 | return (p == s) ? NULL : s; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/ap/stdio/fileno.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | int fileno(FILE *f) 12 | { 13 | /* f->fd never changes, but the lock must be obtained and released 14 | * anyway since this function cannot return while another thread 15 | * holds the lock. */ 16 | FLOCK(f); 17 | FUNLOCK(f); 18 | return f->fd; 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/stdio/fprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include 11 | 12 | int fprintf(FILE *restrict f, const char *restrict fmt, ...) 13 | { 14 | int ret; 15 | va_list ap; 16 | va_start(ap, fmt); 17 | ret = vfprintf(f, fmt, ap); 18 | va_end(ap); 19 | return ret; 20 | } 21 | -------------------------------------------------------------------------------- /src/ap/stdio/fputc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | int fputc(int c, FILE *f) 12 | { 13 | if (f->lock < 0 || !__lockfile(f)) 14 | return putc_unlocked(c, f); 15 | c = putc_unlocked(c, f); 16 | __unlockfile(f); 17 | return c; 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/stdio/fputs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include 11 | 12 | int fputs(const char *restrict s, FILE *restrict f) 13 | { 14 | return (int)fwrite(s, strlen(s), 1, f) - 1; 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/stdio/fputws.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include "locale_impl.h" 11 | #include 12 | 13 | int fputws(const wchar_t *restrict ws, FILE *restrict f) 14 | { 15 | unsigned char buf[BUFSIZ]; 16 | size_t l=0; 17 | 18 | FLOCK(f); 19 | 20 | fwide(f, 1); 21 | 22 | while (ws && (l = wcsrtombs((void *)buf, (void*)&ws, sizeof buf, 0))+1 > 1) 23 | if (__fwritex(buf, l, f) < l) { 24 | return -1; 25 | } 26 | 27 | FUNLOCK(f); 28 | 29 | return l; /* 0 or -1 */ 30 | } 31 | 32 | weak_alias(fputws, fputws_unlocked); 33 | -------------------------------------------------------------------------------- /src/ap/stdio/fscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include "libc.h" 12 | 13 | int fscanf(FILE *restrict f, const char *restrict fmt, ...) 14 | { 15 | int ret; 16 | va_list ap; 17 | va_start(ap, fmt); 18 | ret = vfscanf(f, fmt, ap); 19 | va_end(ap); 20 | return ret; 21 | } 22 | -------------------------------------------------------------------------------- /src/ap/stdio/fsetpos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | int fsetpos(FILE *f, const fpos_t *pos) 12 | { 13 | return fseeko(f, *(const off_t *)pos, SEEK_SET); 14 | } 15 | -------------------------------------------------------------------------------- /src/ap/stdio/fwide.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include "locale_impl.h" 11 | 12 | int fwide(FILE *f, int mode) 13 | { 14 | FLOCK(f); 15 | if (mode) { 16 | if (!f->locale) f->locale = MB_CUR_MAX==1 17 | ? C_LOCALE : UTF8_LOCALE; 18 | if (!f->mode) f->mode = mode>0 ? 1 : -1; 19 | } 20 | mode = f->mode; 21 | FUNLOCK(f); 22 | return mode; 23 | } 24 | -------------------------------------------------------------------------------- /src/ap/stdio/fwprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int fwprintf(FILE *restrict f, const wchar_t *restrict fmt, ...) 14 | { 15 | int ret; 16 | va_list ap; 17 | va_start(ap, fmt); 18 | ret = vfwprintf(f, fmt, ap); 19 | va_end(ap); 20 | return ret; 21 | } 22 | -------------------------------------------------------------------------------- /src/ap/stdio/fwscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include "libc.h" 13 | 14 | int fwscanf(FILE *restrict f, const wchar_t *restrict fmt, ...) 15 | { 16 | int ret; 17 | va_list ap; 18 | va_start(ap, fmt); 19 | ret = vfwscanf(f, fmt, ap); 20 | va_end(ap); 21 | return ret; 22 | } 23 | 24 | weak_alias(fwscanf,__isoc99_fwscanf); 25 | -------------------------------------------------------------------------------- /src/ap/stdio/getc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | int getc(FILE *f) 12 | { 13 | int c; 14 | if (f->lock < 0 || !__lockfile(f)) 15 | return getc_unlocked(f); 16 | c = getc_unlocked(f); 17 | __unlockfile(f); 18 | return c; 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/stdio/getc_unlocked.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | int (getc_unlocked)(FILE *f) 12 | { 13 | return getc_unlocked(f); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/ap/stdio/getchar.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | int getchar(void) 12 | { 13 | return fgetc(stdin); 14 | } 15 | -------------------------------------------------------------------------------- /src/ap/stdio/gets.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include 11 | #include 12 | 13 | char *gets(char *s) 14 | { 15 | char *ret = fgets(s, INT_MAX, stdin); 16 | if (ret && s[strlen(s)-1] == '\n') s[strlen(s)-1] = 0; 17 | return ret; 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/stdio/getwc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include 11 | 12 | wint_t getwc(FILE *f) 13 | { 14 | return fgetwc(f); 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/stdio/getwchar.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include 11 | 12 | wint_t getwchar(void) 13 | { 14 | return fgetwc(stdin); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /src/ap/stdio/ofl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include "libc.h" 11 | 12 | static FILE *ofl_head; 13 | //static volatile int ofl_lock[2]; 14 | 15 | FILE **__ofl_lock() 16 | { 17 | //LOCK(ofl_lock); 18 | return &ofl_head; 19 | } 20 | 21 | void __ofl_unlock() 22 | { 23 | //UNLOCK(ofl_lock); 24 | } 25 | -------------------------------------------------------------------------------- /src/ap/stdio/ofl_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | FILE *__ofl_add(FILE *f) 12 | { 13 | FILE **head = __ofl_lock(); 14 | f->next = *head; 15 | if (*head) (*head)->prev = f; 16 | *head = f; 17 | __ofl_unlock(); 18 | return f; 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/stdio/perror.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include "stdio_impl.h" 13 | 14 | void perror(const char *msg) 15 | { 16 | FILE *f = stderr; 17 | char *errstr = strerror(errno); 18 | 19 | FLOCK(f); 20 | 21 | if (msg && *msg) { 22 | fwrite(msg, strlen(msg), 1, f); 23 | fputc(':', f); 24 | fputc(' ', f); 25 | } 26 | fwrite(errstr, strlen(errstr), 1, f); 27 | fputc('\n', f); 28 | 29 | FUNLOCK(f); 30 | } 31 | -------------------------------------------------------------------------------- /src/ap/stdio/printf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int printf(const char *restrict fmt, ...) 13 | { 14 | int ret; 15 | va_list ap; 16 | va_start(ap, fmt); 17 | ret = vfprintf(stdout, fmt, ap); 18 | va_end(ap); 19 | return ret; 20 | } 21 | -------------------------------------------------------------------------------- /src/ap/stdio/putc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | int putc(int c, FILE *f) 12 | { 13 | if (f->lock < 0 || !__lockfile(f)) 14 | return putc_unlocked(c, f); 15 | c = putc_unlocked(c, f); 16 | __unlockfile(f); 17 | return c; 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/stdio/putc_unlocked.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | int (putc_unlocked)(int c, FILE *f) 12 | { 13 | return putc_unlocked(c, f); 14 | } 15 | -------------------------------------------------------------------------------- /src/ap/stdio/putchar.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | int putchar(int c) 12 | { 13 | return fputc(c, stdout); 14 | } 15 | -------------------------------------------------------------------------------- /src/ap/stdio/puts.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | int puts(const char *s) 12 | { 13 | int r; 14 | FLOCK(stdout); 15 | r = -(fputs(s, stdout) < 0 || putc_unlocked('\n', stdout) < 0); 16 | FUNLOCK(stdout); 17 | return r; 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/stdio/putwc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include 11 | 12 | wint_t putwc(wchar_t c, FILE *f) 13 | { 14 | return fputwc(c, f); 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/stdio/putwchar.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include 11 | 12 | wint_t putwchar(wchar_t c) 13 | { 14 | return fputwc(c, stdout); 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/stdio/rewind.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | void rewind(FILE *f) 12 | { 13 | FLOCK(f); 14 | __fseeko_unlocked(f, 0, SEEK_SET); 15 | f->flags &= ~F_ERR; 16 | FUNLOCK(f); 17 | } 18 | -------------------------------------------------------------------------------- /src/ap/stdio/scanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include "libc.h" 12 | 13 | int scanf(const char *restrict fmt, ...) 14 | { 15 | int ret; 16 | va_list ap; 17 | va_start(ap, fmt); 18 | ret = vscanf(fmt, ap); 19 | va_end(ap); 20 | return ret; 21 | } 22 | -------------------------------------------------------------------------------- /src/ap/stdio/setbuf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | void setbuf(FILE *restrict f, char *restrict buf) 12 | { 13 | setvbuf(f, buf, buf ? _IOFBF : _IONBF, BUFSIZ); 14 | } 15 | -------------------------------------------------------------------------------- /src/ap/stdio/snprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int snprintf(char *restrict s, size_t n, const char *restrict fmt, ...) 13 | { 14 | int ret; 15 | va_list ap; 16 | va_start(ap, fmt); 17 | ret = vsnprintf(s, n, fmt, ap); 18 | va_end(ap); 19 | return ret; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/ap/stdio/sprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int sprintf(char *restrict s, const char *restrict fmt, ...) 13 | { 14 | int ret; 15 | va_list ap; 16 | va_start(ap, fmt); 17 | ret = vsprintf(s, fmt, ap); 18 | va_end(ap); 19 | return ret; 20 | } 21 | -------------------------------------------------------------------------------- /src/ap/stdio/sscanf.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2005-2014 Rich Felker, et al. 4 | * Copyright (c) 2015-2016 HarveyOS et al. 5 | * 6 | * Use of this source code is governed by a MIT-style 7 | * license that can be found in the LICENSE.mit file. 8 | */ 9 | 10 | #include 11 | #include 12 | #include "libc.h" 13 | 14 | int sscanf(const char *restrict s, const char *restrict fmt, ...) 15 | { 16 | int ret; 17 | va_list ap; 18 | va_start(ap, fmt); 19 | ret = vsscanf(s, fmt, ap); 20 | va_end(ap); 21 | return ret; 22 | } 23 | -------------------------------------------------------------------------------- /src/ap/stdio/stderr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | static unsigned char buf[UNGET]; 12 | static FILE f = { 13 | .buf = buf+UNGET, 14 | .buf_size = 0, 15 | .fd = 2, 16 | .flags = F_PERM | F_NORD, 17 | .lbf = -1, 18 | .write = __stdio_write, 19 | .seek = __stdio_seek, 20 | .close = __stdio_close, 21 | .lock = -1, 22 | }; 23 | FILE *const stderr = &f; 24 | FILE *volatile __stderr_used = &f; 25 | -------------------------------------------------------------------------------- /src/ap/stdio/stdin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | static unsigned char buf[BUFSIZ+UNGET]; 12 | static FILE f = { 13 | .buf = buf+UNGET, 14 | .buf_size = sizeof buf-UNGET, 15 | .fd = 0, 16 | .flags = F_PERM | F_NOWR, 17 | .read = __stdio_read, 18 | .seek = __stdio_seek, 19 | .close = __stdio_close, 20 | .lock = -1, 21 | }; 22 | FILE *const stdin = &f; 23 | FILE *volatile __stdin_used = &f; 24 | -------------------------------------------------------------------------------- /src/ap/stdio/stdout.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | static unsigned char buf[BUFSIZ+UNGET]; 12 | static FILE f = { 13 | .buf = buf+UNGET, 14 | .buf_size = sizeof buf-UNGET, 15 | .fd = 1, 16 | .flags = F_PERM | F_NORD, 17 | .lbf = '\n', 18 | .write = __stdout_write, 19 | .seek = __stdio_seek, 20 | .close = __stdio_close, 21 | .lock = -1, 22 | }; 23 | FILE *const stdout = &f; 24 | FILE *volatile __stdout_used = &f; 25 | -------------------------------------------------------------------------------- /src/ap/stdio/swprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int swprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, ...) 13 | { 14 | int ret; 15 | va_list ap; 16 | va_start(ap, fmt); 17 | ret = vswprintf(s, n, fmt, ap); 18 | va_end(ap); 19 | return ret; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/ap/stdio/swscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include "libc.h" 12 | 13 | int swscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, ...) 14 | { 15 | int ret; 16 | va_list ap; 17 | va_start(ap, fmt); 18 | ret = vswscanf(s, fmt, ap); 19 | va_end(ap); 20 | return ret; 21 | } 22 | 23 | weak_alias(swscanf,__isoc99_swscanf); 24 | -------------------------------------------------------------------------------- /src/ap/stdio/ungetc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | 11 | int ungetc(int c, FILE *f) 12 | { 13 | if (c == EOF) return c; 14 | 15 | FLOCK(f); 16 | 17 | if (!f->rpos) __toread(f); 18 | if (!f->rpos || f->rpos <= f->buf - UNGET) { 19 | FUNLOCK(f); 20 | return EOF; 21 | } 22 | 23 | *--f->rpos = c; 24 | f->flags &= ~F_EOF; 25 | 26 | FUNLOCK(f); 27 | return c; 28 | } 29 | -------------------------------------------------------------------------------- /src/ap/stdio/vasprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #define _GNU_SOURCE 10 | #include 11 | #include 12 | #include 13 | 14 | int vasprintf(char **s, const char *fmt, va_list ap) 15 | { 16 | va_list ap2; 17 | va_copy(ap2, ap); 18 | int l = vsnprintf(0, 0, fmt, ap2); 19 | va_end(ap2); 20 | 21 | if (l<0 || !(*s=malloc(l+1U))) return -1; 22 | return vsnprintf(*s, l+1U, fmt, ap); 23 | } 24 | -------------------------------------------------------------------------------- /src/ap/stdio/vprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | int vprintf(const char *restrict fmt, va_list ap) 12 | { 13 | return vfprintf(stdout, fmt, ap); 14 | } 15 | -------------------------------------------------------------------------------- /src/ap/stdio/vscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include "libc.h" 12 | 13 | int vscanf(const char *restrict fmt, va_list ap) 14 | { 15 | return vfscanf(stdin, fmt, ap); 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/stdio/vsprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int vsprintf(char *restrict s, const char *restrict fmt, va_list ap) 13 | { 14 | return vsnprintf(s, INT_MAX, fmt, ap); 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/stdio/vsscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include "stdio_impl.h" 10 | #include "libc.h" 11 | 12 | static size_t do_read(FILE *f, unsigned char *buf, size_t len) 13 | { 14 | return __string_read(f, buf, len); 15 | } 16 | 17 | int vsscanf(const char *restrict s, const char *restrict fmt, va_list ap) 18 | { 19 | FILE f = { 20 | .buf = (void *)s, .cookie = (void *)s, 21 | .read = do_read, .lock = -1 22 | }; 23 | return vfscanf(&f, fmt, ap); 24 | } 25 | -------------------------------------------------------------------------------- /src/ap/stdio/vwprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | int vwprintf(const wchar_t *restrict fmt, va_list ap) 13 | { 14 | return vfwprintf(stdout, fmt, ap); 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/stdio/vwscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include "libc.h" 13 | 14 | int vwscanf(const wchar_t *restrict fmt, va_list ap) 15 | { 16 | return vfwscanf(stdin, fmt, ap); 17 | } 18 | 19 | weak_alias(vwscanf,__isoc99_vwscanf); 20 | -------------------------------------------------------------------------------- /src/ap/stdio/wprintf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | int wprintf(const wchar_t *restrict fmt, ...) 14 | { 15 | int ret; 16 | va_list ap; 17 | va_start(ap, fmt); 18 | ret = vwprintf(fmt, ap); 19 | va_end(ap); 20 | return ret; 21 | } 22 | -------------------------------------------------------------------------------- /src/ap/stdio/wscanf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include "libc.h" 13 | 14 | int wscanf(const wchar_t *restrict fmt, ...) 15 | { 16 | int ret; 17 | va_list ap; 18 | va_start(ap, fmt); 19 | ret = vwscanf(fmt, ap); 20 | va_end(ap); 21 | return ret; 22 | } 23 | 24 | weak_alias(wscanf,__isoc99_wscanf); 25 | -------------------------------------------------------------------------------- /src/ap/stdlib/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = libap.a 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | CFLAGS += -I../internal 7 | 8 | .PHONY: all clean 9 | 10 | all: $(TARGET) clean 11 | 12 | %.o: %.c 13 | $(CC) $(CFLAGS) -c $(SRCS) 14 | 15 | $(TARGET): $(OBJ) 16 | ar rcs ${APEXLIB}/$@ $^ 17 | 18 | clean: 19 | rm -f $(OBJ) 20 | -------------------------------------------------------------------------------- /src/ap/string/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = libap.a 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | CFLAGS += -I../internal -D_BSD_EXTENSION 7 | 8 | 9 | .PHONY: all clean 10 | 11 | all: $(TARGET) clean 12 | 13 | %.o: %.c 14 | $(CC) $(CFLAGS) -c $(SRCS) 15 | 16 | $(TARGET): $(OBJ) 17 | ar rcs ${APEXLIB}/$@ $^ 18 | 19 | clean: 20 | rm -f $(OBJ) 21 | -------------------------------------------------------------------------------- /src/ap/string/mempcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #define _GNU_SOURCE 10 | #include 11 | 12 | void *mempcpy(void *dest, const void *src, size_t n) 13 | { 14 | return (char *)memcpy(dest, src, n) + n; 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/string/strdup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | #include "libc.h" 12 | 13 | char *__strdup(const char *s) 14 | { 15 | size_t l = strlen(s); 16 | char *d = malloc(l+1); 17 | if (!d) return NULL; 18 | return memcpy(d, s, l+1); 19 | } 20 | 21 | weak_alias(__strdup, strdup); 22 | -------------------------------------------------------------------------------- /src/ap/string/strndup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | char *strndup(const char *s, size_t n) 13 | { 14 | size_t l = strnlen(s, n); 15 | char *d = malloc(l+1); 16 | if (!d) return NULL; 17 | memcpy(d, s, l); 18 | d[l] = 0; 19 | return d; 20 | } 21 | -------------------------------------------------------------------------------- /src/ap/string/strnlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | size_t strnlen(const char *s, size_t n) 12 | { 13 | const char *p = memchr(s, 0, n); 14 | return p ? p-s : n; 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/string/wcscat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | wchar_t *wcscat(wchar_t *restrict dest, const wchar_t *restrict src) 12 | { 13 | wcscpy(dest + wcslen(dest), src); 14 | return dest; 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/string/wcschr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | wchar_t *wcschr(const wchar_t *s, wchar_t c) 12 | { 13 | if (!c) return (wchar_t *)s + wcslen(s); 14 | for (; *s && *s != c; s++); 15 | return *s ? (wchar_t *)s : 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/string/wcscmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | int wcscmp(const wchar_t *l, const wchar_t *r) 12 | { 13 | for (; *l==*r && *l && *r; l++, r++); 14 | return *l - *r; 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/string/wcscpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | wchar_t *wcscpy(wchar_t *restrict d, const wchar_t *restrict s) 12 | { 13 | wchar_t *a = d; 14 | while ((*d++ = *s++)); 15 | return a; 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/string/wcscspn.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | size_t wcscspn(const wchar_t *s, const wchar_t *c) 12 | { 13 | const wchar_t *a; 14 | if (!c[0]) return wcslen(s); 15 | if (!c[1]) return (s=wcschr(a=s, *c)) ? s-a : wcslen(a); 16 | for (a=s; *s && !wcschr(c, *s); s++); 17 | return s-a; 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/string/wcslen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | size_t wcslen(const wchar_t *s) 12 | { 13 | const wchar_t *a; 14 | for (a=s; *s; s++); 15 | return s-a; 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/string/wcsncat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | wchar_t *wcsncat(wchar_t *restrict d, const wchar_t *restrict s, size_t n) 12 | { 13 | wchar_t *a = d; 14 | d += wcslen(d); 15 | while (n && *s) n--, *d++ = *s++; 16 | *d++ = 0; 17 | return a; 18 | } 19 | -------------------------------------------------------------------------------- /src/ap/string/wcsncmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | int wcsncmp(const wchar_t *l, const wchar_t *r, size_t n) 12 | { 13 | for (; n && *l==*r && *l && *r; n--, l++, r++); 14 | return n ? *l - *r : 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/string/wcsncpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | wchar_t *wcsncpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) 12 | { 13 | wchar_t *a = d; 14 | while (n && *s) n--, *d++ = *s++; 15 | wmemset(d, 0, n); 16 | return a; 17 | } 18 | -------------------------------------------------------------------------------- /src/ap/string/wcspbrk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | wchar_t *wcspbrk(const wchar_t *s, const wchar_t *b) 12 | { 13 | s += wcscspn(s, b); 14 | return *s ? (wchar_t *)s : NULL; 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/string/wcsrchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | wchar_t *wcsrchr(const wchar_t *s, wchar_t c) 12 | { 13 | const wchar_t *p; 14 | for (p=s+wcslen(s); p>=s && *p!=c; p--); 15 | return p>=s ? (wchar_t *)p : 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/string/wcsspn.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | size_t wcsspn(const wchar_t *s, const wchar_t *c) 12 | { 13 | const wchar_t *a; 14 | for (a=s; *s && wcschr(c, *s); s++); 15 | return s-a; 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/string/wcstok.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | wchar_t *wcstok(wchar_t *restrict s, const wchar_t *restrict sep, wchar_t **restrict p) 12 | { 13 | if (!s && !(s = *p)) return NULL; 14 | s += wcsspn(s, sep); 15 | if (!*s) return *p = 0; 16 | *p = s + wcscspn(s, sep); 17 | if (**p) *(*p)++ = 0; 18 | else *p = 0; 19 | return s; 20 | } 21 | -------------------------------------------------------------------------------- /src/ap/string/wmemchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n) 12 | { 13 | for (; n && *s != c; n--, s++); 14 | return n ? (wchar_t *)s : 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/string/wmemcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | int wmemcmp(const wchar_t *l, const wchar_t *r, size_t n) 12 | { 13 | for (; n && *l==*r; n--, l++, r++); 14 | return n ? *l-*r : 0; 15 | } 16 | -------------------------------------------------------------------------------- /src/ap/string/wmemcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | wchar_t *wmemcpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) 12 | { 13 | wchar_t *a = d; 14 | while (n--) *d++ = *s++; 15 | return a; 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/string/wmemmove.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n) 12 | { 13 | wchar_t *d0 = d; 14 | if ((size_t)(d-s) < n) 15 | while (n--) d[n] = s[n]; 16 | else 17 | while (n--) *d++ = *s++; 18 | return d0; 19 | } 20 | -------------------------------------------------------------------------------- /src/ap/string/wmemset.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2005-2014 Rich Felker, et al. 3 | * Copyright (c) 2015-2016 HarveyOS et al. 4 | * 5 | * Use of this source code is governed by a MIT-style 6 | * license that can be found in the LICENSE.mit file. 7 | */ 8 | 9 | #include 10 | 11 | wchar_t *wmemset(wchar_t *d, wchar_t c, size_t n) 12 | { 13 | wchar_t *ret = d; 14 | while (n--) *d++ = c; 15 | return ret; 16 | } 17 | -------------------------------------------------------------------------------- /src/ap/syscall/genall: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | # genall - generate the APE versions of the system call C interfaces. 3 | # must be invoked by mk so that the right env variables are set. 4 | rfork e 5 | # ugh. sources's build process can't hack absolute path names. 6 | # we're in /sys/src/ape/lib/ap/syscall. 7 | SYSH=../../../../libc/9syscall/sys.h # /sys/src/libc/9syscall/sys.h 8 | 9 | SYS=`{sed '/^#define._/d; s/#define.([A-Z0-9_]*).*/\1/' $SYSH} 10 | for(I in $SYS) { 11 | i=_^$I 12 | n=`{sed -n '/[ ]'$I'[ ]/s/.* //p' $SYSH} 13 | gencall 14 | } 15 | ar rv /$objtype/lib/ape/libap.a *.$O 16 | rm -f *.$O *.s 17 | -------------------------------------------------------------------------------- /src/ap/syscall/mkfile: -------------------------------------------------------------------------------- 1 | NPROC=1 2 | $target 16 | chmod +x $target 17 | 18 | nuke clean:V: 19 | rm -f *.[$OS] *.s gencall 20 | 21 | installall:V: 22 | for(objtype in $CPUS) mk install 23 | 24 | update:V: 25 | update $UPDATEFLAGS mkfile 26 | -------------------------------------------------------------------------------- /src/cmd/apextest/.gitignore: -------------------------------------------------------------------------------- 1 | /apextest 2 | /*.o 3 | -------------------------------------------------------------------------------- /src/cmd/apextest/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = apextest 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | CFLAGS += -I. -DHAVE_CONFIG_H -D_BSD_SOURCE 7 | 8 | .PHONY: all clean 9 | 10 | all: $(TARGET) clean 11 | 12 | %.o: %.c 13 | $(CC) $(CFLAGS) -c $(SRCS) 14 | 15 | $(TARGET): $(OBJ) 16 | $(CC) --verbose -nostdlib -o $(TARGET) $(APEXLIB)/crt0.o $(APEXLIB)/crti.o $(APEXLIB)/crtn.o $(OBJ) -L$(APEXLIB) -L$(HARVEYLIB) -lbsd -lap -lc 17 | 18 | clean: 19 | rm -f $(OBJ) 20 | -------------------------------------------------------------------------------- /src/cmd/apextest/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern char **environ; 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | int count = 0; 10 | 11 | printf("\n"); 12 | while(environ[count] != NULL) 13 | { 14 | printf("[%s] :: ", environ[count]); 15 | count++; 16 | } 17 | 18 | char *val = getenv("USER"); 19 | printf("\n\nCurrent value of environment variable USER is [%s]\n",val); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/cmd/awk/.gitignore: -------------------------------------------------------------------------------- 1 | ytab.c 2 | ytab.h 3 | -------------------------------------------------------------------------------- /src/cmd/diff/FREEBSD-upgrade: -------------------------------------------------------------------------------- 1 | Import of GNU diff 2.7 2 | 3 | Original source available as ftp://prep.ai.mit.edu/pub/gnu/diffutils-2.7.tar.gz 4 | 5 | The following files and directories were removed for this import: 6 | 7 | Makefile.in 8 | INSTALL 9 | alloca.c 10 | cmp.c 11 | diff.info 12 | diff.info-1 13 | diff.info-2 14 | diff.info-3 15 | diff.info-4 16 | error.c 17 | fnmatch.c 18 | fnmatch.h 19 | memchr.c 20 | mkinstalldirs 21 | regex.c 22 | regex.h 23 | texinfo.tex 24 | waitpid.c 25 | -------------------------------------------------------------------------------- /src/cmd/diff/README: -------------------------------------------------------------------------------- 1 | This directory contains the GNU diff, diff3, sdiff, and cmp utilities. 2 | Their features are a superset of the Unix features and they are 3 | significantly faster. cmp has been moved here from the GNU textutils. 4 | 5 | See the file COPYING for copying conditions. 6 | See the file diff.texi (or diff.info*) for documentation. 7 | See the file INSTALL for compilation and installation instructions. 8 | 9 | Report bugs to bug-gnu-utils@prep.ai.mit.edu 10 | -------------------------------------------------------------------------------- /src/cmd/diff/mkfile: -------------------------------------------------------------------------------- 1 | $target 37 | 38 | clean:V: 39 | rm -f [$OS].out *.[$OS] y.tab.? lex.yy.c grapl.c grap.c grap 40 | -------------------------------------------------------------------------------- /src/cmd/lp/lpsend.rc: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | # lpsend.rc dialstring - run lpsend network!dialstring!printer 3 | if (! ~ $DEBUG '') 4 | flag x + 5 | if (! test -e /net/tcp/clone) 6 | exit 'no tcp' 7 | 8 | dialstring=`{ndb/query sys $1 dom} 9 | if (~ $#dialstring 0 || ~ $dialstring '') # no dom for sys in ndb? 10 | dialstring=$1 # use arg unchanged 11 | 12 | lpsend tcp!^$dialstring^!printer 13 | exit $status 14 | -------------------------------------------------------------------------------- /src/cmd/lp/mkfile: -------------------------------------------------------------------------------- 1 | $target 38 | 39 | clean:V: 40 | rm -f *.[$OS] [$OS].out y.tab.? y.debug $TARG picy.c picl.c 41 | -------------------------------------------------------------------------------- /src/cmd/psh.rc: -------------------------------------------------------------------------------- 1 | #!/bin/rc 2 | exec /rc/bin/ape/psh $* 3 | -------------------------------------------------------------------------------- /src/cmd/sed/Makefile: -------------------------------------------------------------------------------- 1 | include $(APEX)/src/$(OS).inc 2 | 3 | TARGET = sed 4 | SRCS = $(wildcard *.c) 5 | OBJ = ${SRCS:.c=.o} 6 | 7 | CFLAGS += -I. 8 | 9 | .PHONY: all clean 10 | 11 | all: $(TARGET) 12 | 13 | %.o: %.c 14 | $(CC) $(CFLAGS) -c $(SRCS) 15 | 16 | $(TARGET): $(OBJ) 17 | $(LD) -static -nostdlib -z noseparated-code -z max-page-size=0x200000 -o $(TARGET) $(APEXLIB)/crt0.o $(APEXLIB)/crti.o $(APEXLIB)/crtn.o $(OBJ) -L$(APEXLIB) -L$(HARVEYLIB) -lap -lc 18 | 19 | install: 20 | cp $(TARGET) $(APEXBIN) 21 | 22 | clean: 23 | rm -f $(OBJ) $(TARGET) 24 | -------------------------------------------------------------------------------- /src/cmd/sed/mkfile: -------------------------------------------------------------------------------- 1 | APE=/sys/src/ape 2 | <$APE/config 3 | 4 | TARG=sed 5 | OFILES=sed0.$O\ 6 | sed1.$O 7 | 8 | HFILES=sed.h 9 | 10 | BIN=$APEBIN 11 |