BSD4.3 LIBRARY(3,L) AIX Technical Reference BSD4.3 LIBRARY(3,L) ------------------------------------------------------------------------------- BSD4.3 library PURPOSE Describes the 4.3BSD functions provided by AIX. LIBRARY Standard C Library (libc.a) Math Library (libm.a) BSD Compatibility (libbsd.a) DESCRIPTION This section provides a list of 4.3BSD routines supported in AIX and information to help application programmers port 4.3BSD programs to AIX. Some of these routines can be found in libbsd.a and most of the rest in libc.a. The location and full description of each of the 4.3BSD routines can be found in the appropriate alphabetical location in this chapter. Even if you are familiar with 4.3BSD programming, you should read this entire section before porting existing programs or writing new AIX programs that use BSD4.3 library functions. Once you have read this section, you can refer back to specific discussions or to the individual routine descriptions as needed. BSD4.3 LIBRARY ROUTINES The following table lists the 4.3BSD library routines that are available in AIX and indicates the library where the routine is located. When the routine is listed as being in both libc.a and libbsd.a, the libbsd.a routine provides the maximum 4.3BSD compatibility, while the libc.a version provides a different behavior. +-----------------------------------------+-----------------------------+ | Subroutine Name | library Name | +-----------------------------------------+-----------------------------+ | accept | libc.a | +-----------------------------------------+-----------------------------+ | adjtime | libc.a | +-----------------------------------------+-----------------------------+ | alphasort | libc.a | +-----------------------------------------+-----------------------------+ | bcmp, bzero, ffs | libc.a | +-----------------------------------------+-----------------------------+ | bcopy | libc.a | +-----------------------------------------+-----------------------------+ | bind | libc.a | +-----------------------------------------+-----------------------------+ Processed November 7, 1990 BSD4.3 LIBRARY(3,L) 1 BSD4.3 LIBRARY(3,L) AIX Technical Reference BSD4.3 LIBRARY(3,L) +-----------------------------------------+-----------------------------+ | chown, fchown | libc.a | +-----------------------------------------+-----------------------------+ | connect | libc.a | +-----------------------------------------+-----------------------------+ | copysign | libm.a | +-----------------------------------------+-----------------------------+ | directory: closedir, opendir, readdir, | libc.a | | rewinddir, telldir, seekdir | | +-----------------------------------------+-----------------------------+ | dup2 | libc.a | +-----------------------------------------+-----------------------------+ | flock | libbsd.a | +-----------------------------------------+-----------------------------+ | fsync | libc.a | +-----------------------------------------+-----------------------------+ | ftime | libc.a | +-----------------------------------------+-----------------------------+ | ftruncate | libc.a | +-----------------------------------------+-----------------------------+ | getdtablesize | libc.a | +-----------------------------------------+-----------------------------+ | getgroups | libc.a | +-----------------------------------------+-----------------------------+ | gethostbyaddr, gethostbyname, | libc.a | | sethostent, endhostent | | +-----------------------------------------+-----------------------------+ | gethostid, sethostid | libc.a | +-----------------------------------------+-----------------------------+ | gethostname, sethostname | libc.a | +-----------------------------------------+-----------------------------+ | getitimer, setitimer | libc.a | +-----------------------------------------+-----------------------------+ | getnetent, getnetbyaddr, getnetbyname, | libc.a | | setnetent, endnetent | | +-----------------------------------------+-----------------------------+ | getpeername | libc.a | +-----------------------------------------+-----------------------------+ | getpriority, setprioity, nice | libc.a | +-----------------------------------------+-----------------------------+ | getprotoent, getprotobynumber, | libc.a | | getprotobyname, setprotoent, | | +-----------------------------------------+-----------------------------+ | getservent, getservbyname, | libc.a | | getservbyport, setservent, endservent | | +-----------------------------------------+-----------------------------+ | getsockname | libc.a | +-----------------------------------------+-----------------------------+ | getsockopt, setsockopt | libc.a | +-----------------------------------------+-----------------------------+ | gettimeofday, settimeofday | libc.a | +-----------------------------------------+-----------------------------+ Processed November 7, 1990 BSD4.3 LIBRARY(3,L) 2 BSD4.3 LIBRARY(3,L) AIX Technical Reference BSD4.3 LIBRARY(3,L) +-----------------------------------------+-----------------------------+ | gtty | libc.a | +-----------------------------------------+-----------------------------+ | getwd | libc.a | +-----------------------------------------+-----------------------------+ Processed November 7, 1990 BSD4.3 LIBRARY(3,L) 3 BSD4.3 LIBRARY(3,L) AIX Technical Reference BSD4.3 LIBRARY(3,L) +-----------------------------------------+-----------------------------+ | Subroutine Name | library Name | +-----------------------------------------+-----------------------------+ | htonl, htons, ntohl, ntohs | libc.a | +-----------------------------------------+-----------------------------+ | index, rindex | libc.a | +-----------------------------------------+-----------------------------+ | inet_addr, inet_network, inet_ntoa, | libc.a | | inet_makeaddr, inet_lnaof, inet_netof | | +-----------------------------------------+-----------------------------+ | initgroups | libc.a | +-----------------------------------------+-----------------------------+ | insque, remque | libc.a | +-----------------------------------------+-----------------------------+ | kill, kill3 | libc.a | +-----------------------------------------+-----------------------------+ | killpg | libbsd.a | +-----------------------------------------+-----------------------------+ | listen | libc.a | +-----------------------------------------+-----------------------------+ | mkdir | libc.a | +-----------------------------------------+-----------------------------+ | rand | libc.a | +-----------------------------------------+-----------------------------+ | regcmp | libpw.a | +-----------------------------------------+-----------------------------+ | random, srandom, initstate, setstate | libc.a | +-----------------------------------------+-----------------------------+ | rcmd, rresvport, ruserok | libc.a | +-----------------------------------------+-----------------------------+ | readlink | libc.a | +-----------------------------------------+-----------------------------+ | read, readv, readx | libc.a | +-----------------------------------------+-----------------------------+ | reboot | libc.a | +-----------------------------------------+-----------------------------+ | recv, recvfrom, recvmsg | libc.a | +-----------------------------------------+-----------------------------+ | rename | libc.a | +-----------------------------------------+-----------------------------+ | resolver: res_mkquery, res_send, | libc.a | | res_init, dn_comp, dn_expand, getshort, | | | getlong, putshort, putlong | | +-----------------------------------------+-----------------------------+ | rexec | libc.a | +-----------------------------------------+-----------------------------+ | rmdir | libc.a | +-----------------------------------------+-----------------------------+ | scandir | libc.a | +-----------------------------------------+-----------------------------+ | select | libc.a | +-----------------------------------------+-----------------------------+ Processed November 7, 1990 BSD4.3 LIBRARY(3,L) 4 BSD4.3 LIBRARY(3,L) AIX Technical Reference BSD4.3 LIBRARY(3,L) +-----------------------------------------+-----------------------------+ | send, sendto, sendmsg | libc.a | +-----------------------------------------+-----------------------------+ | setbuffer, setlinebuf | libc.a | +-----------------------------------------+-----------------------------+ | setgroups | libc.a | +-----------------------------------------+-----------------------------+ | setreuid, setregid | libc.a | +-----------------------------------------+-----------------------------+ | shutdown | libc.a | +-----------------------------------------+-----------------------------+ | sigblock | libc.a, libbsd.a | +-----------------------------------------+-----------------------------+ | signal | libc.a, libbsd.a | +-----------------------------------------+-----------------------------+ | sigpause | libc.a, libbsd.a | +-----------------------------------------+-----------------------------+ Processed November 7, 1990 BSD4.3 LIBRARY(3,L) 5 BSD4.3 LIBRARY(3,L) AIX Technical Reference BSD4.3 LIBRARY(3,L) +-----------------------------------------+-----------------------------+ | Subroutine Name | library Name | +-----------------------------------------+-----------------------------+ | sigsetmask | libc.a, libbsd.a | +-----------------------------------------+-----------------------------+ | sigstack | libc.a | +-----------------------------------------+-----------------------------+ | sigvec | libc.a, libbsd.a | +-----------------------------------------+-----------------------------+ | sleep | libc.a | +-----------------------------------------+-----------------------------+ | socket | libc.a | +-----------------------------------------+-----------------------------+ | socketpair | libc.a | +-----------------------------------------+-----------------------------+ | stty | libc.a | +-----------------------------------------+-----------------------------+ | symlink | libc.a | +-----------------------------------------+-----------------------------+ | syslog, openlog, closelog, setlogmask | libc.a | +-----------------------------------------+-----------------------------+ | utimes | libbsd.a | +-----------------------------------------+-----------------------------+ | valloc | libbsd.a | +-----------------------------------------+-----------------------------+ | varargs | libc.a | +-----------------------------------------+-----------------------------+ | vfork | libbsd.a | +-----------------------------------------+-----------------------------+ | vlimit | libbsd.a | +-----------------------------------------+-----------------------------+ | vtimes | libbsd.a | +-----------------------------------------+-----------------------------+ | wait3 | libc.a | +-----------------------------------------+-----------------------------+ | writev | libc.a | +-----------------------------------------+-----------------------------+ PORTING 4.3BSD APPLICATIONS TO AIX This section provides programmers with the information necessary to use the 4.3BSD functions provided by AIX. It explains how to use the libc.a library and suggests some of the changes that may be needed to port 4.3BSD programs to AIX. In general, when porting you should try to use makefile changes whenever possible, changing the original source code only when absolutely necessary. Changes you may want to make in the makefile include: Processed November 7, 1990 BSD4.3 LIBRARY(3,L) 6 BSD4.3 LIBRARY(3,L) AIX Technical Reference BSD4.3 LIBRARY(3,L) When compiling o Add a "-D_BSD" to your compile command to obtain 4.3BSD behavior in include files. When linking o To access the BSD4.3 library routines, link with /usr/lib/libbsd.a. An alternative to defining "-D_BSD" and "-lbsd" explicitly on the cc command line is to define the environment variable BSD in your shell. This environment variable instructs cc to place these items on the command line for you automatically. If you must modify your source code, for the cpp C language preprocessor, enclose your changes in ifdef statements similar to the following: #ifdef _BSD #else #endif Note: The define for the AIX Operating System is _AIX. There are two versions of signal and two versions of sigvec, one each in libbsd.a and libc.a. The versions of signal and sigvec in libbsd.a conform to 4.3BSD behavior: for example, caught signals are not reset, signal restarts certain system calls and sigvec restarts certain system calls by default. The versions of signal and sigvec in libc.a conform to the behavior of earlier versions of AIX. The AIX signal implementation has been enhanced to support 63 signals through the sigaction system call. All 4.3BSD signals, except SIGVTALRM, have signal numbers less than or equal to 32 and can be used with sigvec and signal. SIGVTALRM has a signal number of 34 and must be used with the sigaction system call. See "sigaction, sigvec, signal" for more information. 4.3BSD Include Files For most applications, the include files on the following list contain the necessary 4.3BSD definitions and structures. Just be sure to use "-D_BSD" when compiling your programs. Although the include file sys/errno.h contains definitions for ENOTEMPTY and EWOULDBLOCK, no AIX system call returns these error numbers. Instead, EAGAIN is returned where a 4.3BSD application would expect EWOULDBLOCK, and EEXIST is returned by the rename and rmdir system calls rather than ENOTEMPTY. If _BSD is defined prior to including sys/errno.h, EWOULDBLOCK is automatically defined Processed November 7, 1990 BSD4.3 LIBRARY(3,L) 7 BSD4.3 LIBRARY(3,L) AIX Technical Reference BSD4.3 LIBRARY(3,L) to EAGAIN. Then place the following definitions in your program after including sys/errno.h: #undef ENOTEMPTY #define ENOTEMPTY EEXIST GENERAL INCLUDE FILES NETWORK INCLUDE FILES fcntl.h arpa/ftp.h math.h arpa/inet.h sgtty.h arpa/nameser.h strings.h arpa/telnet.h sysexits.h arpa/tftp.h sys/dir.h net/af.h sys/file.h net/if.h sys/ioctl.h net/if_arp.h sys/msgbuf.h netinet/in.h sys/param.h netinet/in_systm.h sys/resource.h netinet/in_var.h sys/signal.h netdb.h sys/socket.h resolv.h sys/syslog.h sys/un.h sys/time.h sys/ttychars.h sys/ttydev.h sys/types.h sys/uio.h sys/wait.h Specific Information on BSD4.3 library Routines A few of the 4.3BSD library routines function differently in AIX. This section provides you with details of these differences for a few routines, then gives you a list of individual routine descriptions that also contain information on such differences. strcpyn Calls to this subroutine must be replaced with the strncpy subroutine. strcatn Calls to this subroutine must be replaced with the strncat subroutine. If your 4.3BSD program uses any of the subroutines on the following list, refer to the full description of that routine in this chapter before porting. flock killpg setbuffer, setlinebuf syslog utimes Processed November 7, 1990 BSD4.3 LIBRARY(3,L) 8 BSD4.3 LIBRARY(3,L) AIX Technical Reference BSD4.3 LIBRARY(3,L) 4.3BSD TTY Devices The AIX TTY driver also supports the 4.3BSD TTY interfaces. See "termio" for more information. If your 4.3BSD program uses the curses library, libcurses.a, TTY issues should be handled at that level. Note, however, that AIX uses the terminfo subroutine instead of the termcap subroutine that is used in 4.3BSD. When writing or updating code that gets and uses ptys, keep in mind that: o AIX uses an extended naming convention for ptys. In 4.3BSD, the master pseudo-terminal name is taken from the set /dev/ptyp-r 0-9a-f, and the slave pseudo-terminal name is taken from the set /dev/ttyp-r 0-9a-f. In AIX, the master pseudo-terminal is referred to as the controller; its name is taken from the set /dev/ptyp-zA-Z 0-9a-f. The slave pseudo-terminal is referred to as the server; its name is taken from the set /dev/ttyp-zA-Z 0-9a-f. o ptys may be obtained differently in AIX from 4.3BSD. When ptys are configured into the system using the devices command, the user has the choice of enabling a logger (that is, a getty process) on the server side of a pty. This is not necessary (and must not be done) for remote login applications such as Telnet. However, other applications may expect a logger to be enabled. The /etc/ports file contains a stanza for each pty for which a logger has been enabled. See the special file, "pty" for more information. RELATED INFORMATION In this book: "sockets library." The descriptions of individual BSD commands in AIX Operating System Commands Reference. The descriptions of individual BSD commands in AIX TCP/IP User's Guide. Processed November 7, 1990 BSD4.3 LIBRARY(3,L) 9