HP C/iX Library Reference Manual HP 3000 MPE/iX Computer Systems Edition 4 Manufacturing Part Number: 30026-90004 E1092 U.S.A.
Notice The information contained in this document is subject to change without notice. Hewlett-Packard makes no warranty of any kind with regard to this material, including, but not limited to, the implied warranties of merchantability or fitness for a particular purpose. Hewlett-Packard shall not be liable for errors contained herein or for direct, indirect, special, incidental or consequential damages in connection with the furnishing or use of this material.
Introduction to the HP C/iX Library 1 Introduction to the HP C/iX Library HP C/iX has an extensive library of standard functions that are found in most implementations of the language. The functions provide facilities for such operations as input, output, mathematics, string manipulation, and time and date operations.
Introduction to the HP C/iX Library Organization of the HP C/iX Library Organization of the HP C/iX Library The HP C/iX library consists of several files that can be divided into three groups: standard library functions, mathematical library functions, and library functions available only on HP 3000 Series 900 computers. If you are developing POSIX applications on MPE/iX, you will be using the POSIX/iX library. This library is separate from the HP C/iX library and is organized differently.
Introduction to the HP C/iX Library Organization of the HP C/iX Library Table 1-1. Standard Library Files File Description LIBCWC.LIB.SYS The relocatable library that enables an HP C/iX program to expand valid file set wildcards into fully qualified permanent file names and pass them into the main program. See the HP C/iX Reference Manual for details. LIBCXL.LIB.SYS A relocatable library that is used to build the XL form of the standard library. LIBM.LIB.
Introduction to the HP C/iX Library Organization of the HP C/iX Library LIBCANSI.LIB.SYS To use the rand function with the RL version of the standard library in a program called MYPROG2, specify the following LINK command: LINK FROM=MYOBJ2;TO=MYPROG2;RL=LIBCRAND.LIB.SYS,LIBC.LIB.SYS, LIBCANSI.LIB.SYS For a complete specification of available functions, see chapter 5.
Introduction to the HP C/iX Library Library Header Files Library Header Files To use many of the facilities of the HP C/iX library, your C source code should include the preprocessing directive: #include incfile.h> Enclosing incfile.h in angle brackets tells the preprocessing phase of the compiler to look for that file in a standard location on the system, the H group of the SYS account for HP C/iX. For example, if you want to use the fprintf function, your program should specify: #include stdio.
Introduction to the HP C/iX Library Library Header Files Table 1-2. HP C/iX Library Header Files Header Description Defines the types used with the hsearch and tsearch functions. Declares a type and several functions for bypassing the normal function call and return discipline. Contains declaration used in dealing with conditions that may be reported during program execution. Provides a standard method for dealing with variable arguments.
Introduction to the HP C/iX Library Library Header Files when you invoke the compiler. For compatibility with previous releases, this directive is automatically issued for you if you are not compiling in ANSI mode.
Introduction to the HP C/iX Library Library Header Files 10 Chapter 1
HP C/iX Library Input and Output 2 HP C/iX Library Input and Output This chapter discusses HP C/iX library input/output functions and streams.
HP C/iX Library Input and Output HP C/iX Library Input and Output HP C/iX Library Input and Output The C language does not provide any direct facility to perform input or output. Instead, C implementations usually provide a set of functions that perform I/O. Care must be used when calling the I/O functions because the compiler does not ensure that the arguments to the functions are correct.
HP C/iX Library Input and Output HP C/iX Library Input and Output After a stream has been opened, you may read from it or write to it in several ways. Reading or writing can be done on a character-by-character basis using the inline macros getc and putc, or on a block-by-block basis using functions such as fread or fwrite.
HP C/iX Library Input and Output HP C/iX Library Input and Output of which is six characters in length, the result is different. Assume the same five characters are written. When the C I/O system encounters the \n, it gets ready to write out a record. The record contains "ABCD" at this point. However, since the record is a fixed-length record with a length of six characters, the two characters after the 'D are padded with spaces (040). The record written to the MPE file is: ABCD where indicates a space.
HP C/iX Library Input and Output HP C/iX Library Input and Output pointer to a structure type called FILE. The FILE structure, which is defined in , contains several fields to hold information about the pointer to the buffer, the file descriptor, and the file access mode. The FILE structures provide the operating system with bookkeeping information, but your only means of access to the stream is the pointer to the FILE structure (called a file pointer).
HP C/iX Library Input and Output HP C/iX Library Input and Output a null character. Whether or not padding is applied depends on the file type of the input batch stream file. If the batch stream file is a variable record length ASCII file, no padding is applied and reading from stdin in batch behaves the same as reading in interactive mode. If the batch stream file has fixed record lengths, the input records are padded with trailing blanks.
Interfacing with MPE/iX 3 Interfacing with MPE/iX The mpe.h> header file provides several facilities that allow you to more easily interface with the MPE/iX operating system. Note that calling MPE/iX directly from C programs makes the C programs less portable than using the standard C library. For information about interfacing with MPE/iX intrinsics from the POSIX/iX library, refer to the MPE/iX Developer's Kit Reference Manual.
Interfacing with MPE/iX Foptions Foptions The structure tag fop names a structure that describes the bit positions of the MPE/iX FOPEN intrinsic's foptions.
Interfacing with MPE/iX Aoptions Aoptions Similar to the fop structure, the aop structure provides access to the aoptions used in FOPEN.
Interfacing with MPE/iX Condition Codes Condition Codes Many MPE/iX intrinsics return condition code information upon their completion. The condition codes are defined with macros in the mpe.h header file. The macros are as follows: Table 3-1. Standard Stream Designators CCG Condition Code Greater CCE Condition Code Equal CCL Condition Code Less These macros may be used with the ccode function also declared in this header file.
Interfacing with MPE/iX MPE/iX File Numbers MPE/iX File Numbers The values returned by HP C/iX library functions such as fopen and open do not represent values that are meaningful to the MPE/iX file system intrinsics. The function _mpe_fileno, declared in mpe.h, maps a file descriptor returned by a C library function such as open into an MPE/iX file number that can be passed directly to MPE/iX file system intrinsics.
Interfacing with MPE/iX MPE/iX File Numbers 26 Chapter 3
HP C/iX Library Header Descriptions 4 HP C/iX Library Header Descriptions This chapter describes the contents of the header files provided with the HP C/iX library. Some of the header files described in this chapter contain extensions required for conformance with the POSIX standard. These POSIX extensions are not documented in this manual. Refer to the MPE/iX Developer's Kit Reference Manual for additional information about these extensions.
HP C/iX Library Header Descriptions Available Header Files Available Header Files The HP C/iX library is divided into sections. Each section has a header file that defines the objects found in that section of the library. The standard ANSI C headers are The non-ANSI HP C/iX header files are 28
HP C/iX Library Header Descriptions Referencing Library Header Files Referencing Library Header Files To reference the HP C/iX library header files, place the #include preprocessor directive in your source code. The order of inclusion of the header files is of no significance. The same header file may be included more than once in the same program without generating errors. The syntax for including a HP C/iX library header file is: #include
HP C/iX Library Header Descriptions Library Functions and Header File Macros Library Functions and Header File Macros The HP C/iX library contains both functions and macros. Macros improve the execution speed of certain frequently used operations. One drawback to using macros is that they do not have an address. For example, if a function expects the address of (a pointer to) another function as an argument, you cannot use a macro name in that argument.
HP C/iX Library Header Descriptions Header File Contents Header File Contents This section describes the contents of the HP C/iX library header files. All header files provided by HP C/iX are listed. This includes those headers files that comply with the ANSI C standard, and those that do not comply with this standard. The non-ANSI headers files are provided for compatibility with other UNIX-based 1 systems and for interfacing with the MPE operating system. Diagnostics The header assert.
HP C/iX Library Header Descriptions Header File Contents Table 4-1. Character Handling Macros and Functions Name Type Description isprint() function Tests whether an argument is any printable character including the space character (octal values 040 through 0176). ispunct() function Tests whether an argument is any printable character that is not a space, a digit, or a letter. isspace() function Tests whether an argument is a white space character.
HP C/iX Library Header Descriptions Header File Contents NOTE The values associated with symbolic names are subject to change. It is suggested that the symbolic names in errno.h> be used rather than the actual numeric values. ENOENT (2) No such file. This error occurs when a file name is specified and the file should exist but doesn't. EBADF (9) Bad file number.
HP C/iX Library Header Descriptions Header File Contents second 16 bits contain the subsystem number. The errno.h> header file lists the symbolic names used for intrinsics and gives a type definition for _mpe_status(t_mpe_status). The following is a list of the _mpe_intrinsic symbolic names and their values.
HP C/iX Library Header Descriptions Header File Contents short subsys_num; }; /* subsystem number */ typedef union { struct _status_work decode; /* for individual part access */ int word; /* for complete struct access */ } t_mpe_status /* for type definition */ extern t_mpe_status _mpe_status; /******************************************************************/ if (fclose(unopened_file)) if (errno == ESYSERR) HPERRMSG(2, , , _mpe_status.
HP C/iX Library Header Descriptions Header File Contents Table 4-2. Floating Types Name Description FLT_DIG, DBL_DIG, LDBL_DIG Number of decimal digits, q, such that any floating-point number with q decimal digits can be rounded into a floating-point number with p radix b digits and back again without change to the q decimal digits. FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON The difference between 1.0 and the last value greater than 1.0 that is representable in the given floating-point type.
HP C/iX Library Header Descriptions Header File Contents Table 4-3. Integral Type Limits Name Description SCHAR_MAX The maximum value stored in a signed char. SCHAR_MIN The minimum value stored in a signed char. SHRT_MAX The maximum value stored in a short. SHRT_MIN The minimum value stored in a short. UCHAR_MAX The maximum value stored in an unsigned char. UINT_MAX The maximum value stored in an unsigned int. ULONG_MAX The maximum value stored in an unsigned long.
HP C/iX Library Header Descriptions Header File Contents Table 4-4. Localization Name Type Description lconv type definition A structure type definition for a record containing numeric and monetary formatting values. See the description of the localeconv function for more details. localeconv() function Returns information about the editing symbols of a numeric quantity specific to a locale. NULL macro The constant 0.
HP C/iX Library Header Descriptions Header File Contents The following identifiers are declared in this header file: Table 4-6. Math Library Functions Name Type Description abs() function Computes the absolute value of an integer. acos() function Returns the arc cosine in radians of an input value. asin() function Returns the arc sine of an input value. atan2() function Returns the arc tangent of the input Cartisian coordinates.
HP C/iX Library Header Descriptions Header File Contents Table 4-6. Math Library Functions Name Type Description jn() function Return Bessel functions of x of the first kind of order i. ldexp() function Accepts a double value and an integer exponent and returns a double quantity equal to N * 2exp. log() function Returns the natural logarithm of a positive number. log10() function Returns the logarithm base ten of a positive number.
HP C/iX Library Header Descriptions Header File Contents Table 4-6. Math Library Functions Name Type Description pow() function Returns the value of a number raised to the power of an exponent. signgam external integer Contains the sign of the value returned by the gamma function. sin() function Computes a sine value. SING macro Expands to an integral constant. sinh() function Computes the hyperbolic sine of an angle. sqrt() function Computes the square root of an input value.
HP C/iX Library Header Descriptions Header File Contents Table 4-7. Memory Handling Name Type Description memcpy() function Copies a specified number of characters from one object to another. memset() function Initializes an object with a supplied character value. NOTE This header file is not defined by the ANSI C standard. Programs using this header are likely to be less portable. Use for ANSI compliance. MPE Aids The mpe.
HP C/iX Library Header Descriptions Header File Contents NOTE This header file is not defined by the ANSI C standard. Programs using this header are likely to be less portable. Non-local Jumps The header declares a type and several functions for bypassing the normal function call and return discipline. The following identifiers are declared in this header file: Table 4-9. Nonlocal Jumps
HP C/iX Library Header Descriptions Header File Contents Table 4-10. Signal Handling Name Type Description SIGINT macro A signal indicating that an interactive interrupt has been received. signal function Specifies how a signal is to be handled. SIGSEGV macro A signal indicating that an invalid address to storage has been requested. SIGTERM macro A signal indicating that a termination request was sent to the program. Variable Number of Arguments The header
HP C/iX Library Header Descriptions Header File Contents Table 4-12. Common Definitions Name Type Description offsetof(type, identifier) macro Expands to an integral constant that has type size_t, the value of which is the offset in bytes, from the beginning of a structure designated by type, of the member designated by identifier. ptrdiff_t type definition The signed integral type of subtracting two pointers. size_t type definition The unsigned integral type of the sizeof operator.
HP C/iX Library Header Descriptions Header File Contents Table 4-13. Input/Output Name Type Description FILENAME_MAX macro Specifies the maximum number of characters allowed in a file name. fileno() b macro, function Maps a stream pointer to a file descriptor. fopen() function Opens a file. FOPEN_MAX macro Specifies the minimum number of files that the operating system guarantees may be opened simultaneously.
HP C/iX Library Header Descriptions Header File Contents Table 4-13. Input/Output Name Type Description putchar() macro, function Writes a character to the standard output stream stdout. puts() function Writes a string to the standard output stream stdout. putw() function Writes a word (4 bytes) to an open stream. remove() function Purges an existing file. rename() function Renames an existing file.
HP C/iX Library Header Descriptions Header File Contents Table 4-13. Input/Output Name Type Description vsprintf() function Writes formatted data to a character string in memory using a variable argument list. _IOFBF, _IOLBF, _IONBF macro Constant expressions with values suitable for use as the third argument to the setvbuf function. _NFILE d macro Defines the maximum number of open files allowed per process. a. These identifiers are not defined by the ANSI C standard.
HP C/iX Library Header Descriptions Header File Contents Table 4-14. General Utilities Name Type Description calloc() function Allocates a block of memory. div() function Computes the quotient and remainder of two integers. div_t type definition A data type definition used when declaring the return value for div(). exit() function Terminates the calling process normally.
HP C/iX Library Header Descriptions Header File Contents Table 4-14. General Utilities Name Type Description strtoul() function Converts a string to an unsigned integer representation. system() function Executes an MPE/iX command. wchar_t type definition A data type definition used for wide characters. wcstombs() function Converts a sequence of wide character codes to a sequence of multibyte characters.
HP C/iX Library Header Descriptions Header File Contents Table 4-15. String Handling Name Type Description strerror() function Maps an error number to a message string. strlen() function Computes the length of the string pointed to by s. strncat() function Appends a copy of one string to another string. strncmp() function Compares two strings up to a maximum of n characters and returns the result of the comparison.
HP C/iX Library Header Descriptions Header File Contents Table 4-16. Date and Time Name Type Description CLOCKS_PER_SEC macro The number of clock ticks per second, as counted by the clock function. ctime() function Converts a calendar time into a 26-character ASCII string. daylight a global variable Communicates with functions in this library. See the function descriptions in chapter 5 for more information. difftime() function Computes the difference between two times.
HP C/iX Library Header Descriptions Header File Contents b. These identifiers are not defined by the ANSI C standard. Programs using these identifiers are likely to be less portable. The tm structure, used by several of the
HP C/iX Library Header Descriptions Header File Contents Table 4-18. Machine-Dependent Values Name Type Description HIBITS macro The value of a short integer with only the high-order bit set. HIBITL macro The value of a long integer with only the high-order bit set. HIBITI macro The value of a regular integer with only the high-order bit set. MAXSHORT macro The maximum value of a signed short integer. MAXLONG macro The maximum value of a signed long integer.
HP C/iX Library Header Descriptions Header File Contents Table 4-19. Variable Arguments Name Type Description va_end macro Terminates access to a variable argument list. NOTE Chapter 4 This header file is for non-ANSI mode only. Use stdarg.h> in ANSI mode. Using this header is likely to make a program less portable.
HP C/iX Library Header Descriptions Header File Contents 56 Chapter 4
HP C/iX Library Function Descriptions 5 HP C/iX Library Function Descriptions This chapter provides descriptions of HP C/iX library functions arranged in alphabetical order. If a function conforms to the ANSI C or POSIX standard, a cross-reference to the standard is given at the end of the function description.
HP C/iX Library Function Descriptions a64l a64l Converts a base-64 ASCII string to a long integer. Syntax [long a64l (char s);] Parameters A pointer to a null terminated base-64 ASCII string. Maximum length is 6 bytes; not counting the null terminator. s Return Values x A long integer containing the binary value of the base-64 ASCII string. Description This function maintains numbers stored in base-64 ASCII characters. Long integers can be represented by up to six characters.
HP C/iX Library Function Descriptions abort abort Terminates a program abnormally. Syntax #include void abort (void); Parameters None. Return Values None. Description The abort function causes abnormal program termination to occur unless the signal SIGABRT is being caught and the signal handler does not return. The abort function closes all open files if possible and then terminates the process. Temporary files under MPE/iX are not saved.
HP C/iX Library Function Descriptions abs abs Computes the absolute value of an integer argument. Syntax #include int abs (int x); Parameters x An integer value whose absolute value is to be computed. Return Values x The absolute value of the integer specified in x. Example The following program calculates integer absolute values until a zero is entered from the keyboard: #include #include
HP C/iX Library Function Descriptions access access Determines the accessibility of a file. Syntax #include int access (char *fname, int amode); Parameters fname A pointer to a character string containing a file name. amode An integer indicating whether read or write access to a file is requested. Return Values 0 Requested access is permitted.
HP C/iX Library Function Descriptions acos acos Returns the arc cosine in radians of the input value. Syntax #include double acos (double x); Parameters x A real number. Return Values n The arc cosine of x. 0 The magnitude of the argument of acos is greater than one or less than negative one. In addition, errno is set to EDOM. Description The acos function returns the arc cosine of x, in the range of zero to pi.
HP C/iX Library Function Descriptions asctime asctime Converts a tm structured time variable into a null-terminated 26-character string. Syntax #include char *asctime (const struct tm *timeptr); Parameters timeptr A pointer to a structure of type tm that contains the broken-down time. Return Values x A pointer to the string. Description The asctime function provides a way for you to get the current time, modify it in some way, and then print the result in ASCII form.
HP C/iX Library Function Descriptions asctime modify the date stored in tm before you print the data. If you only want to print the date, use the time/ctime combination. Of all the ctime functions, the localtime function is the most useful. The localtime function enables you to break up the current time into chunks that can be easily referenced and examined for such applications as personal calendar programs and program schedulers.
HP C/iX Library Function Descriptions asin asin Returns the arc sine of the input value in radians. Syntax #include math.h> double asin (double x); Parameters x A real number. Return Values n The arc sine of x. 0 The magnitude of the argument of asin is greater than one or less than negative one. errno is set to EDOM. Description The asin function returns the arc sine of x, in the range of −pi/2 to pi/2.
HP C/iX Library Function Descriptions assert assert Terminates the program if the assertion is false. Syntax #include void assert (int expression); Parameters expression An integer value to be evaluated. Return Values None. Description The assert macro terminates the program if the assertion is false. The assert macro takes a single integer (expression) argument.
HP C/iX Library Function Descriptions atan2 atan2 Returns the arc tangent of the input Cartisian coordinates x and y. Syntax #include math.h> double atan2 (double y, double x) Parameters y A real number indicating the Cartisian coordinate y. x A real number indicating the Cartisian coordinate x. Return Values n The arc tangent of (x, y). 0 Indicates both arguments are zero and errno is set to EDOM. A DOMAIN error is also printed on the standard error output device.
HP C/iX Library Function Descriptions atan atan Returns the arc tangent of the input value x. Syntax #include math.h> double atan (double x); Parameters x A real number. Return Values y The arc tangent of x in the range of −pi/2 to pi/2. Description The atan function returns the arc tangent of x, in the range −pi/2 to pi/2. No range or domain errors are possible. See Also matherr(), ANSI C 4.5.2.3, POSIX.1 8.
HP C/iX Library Function Descriptions atexit atexit Specifies a function to call when a program terminates. Syntax #include int atexit (void (*func) (void)); Parameters func A pointer to a function to be registered. Return Values 0 The function is successfully registered. ≠0 An error occurred. Description The atexit function registers a function pointed to by func that will be called at normal program termination. The function is called without arguments.
HP C/iX Library Function Descriptions atof atof Converts a string to a double floating-point number. Syntax #include double atof (const char *str); Parameters str A pointer to a character string to be converted to a double floating-point number. Return Values x A double floating-point number. Description The atof function converts the string of characters that the str argument points to into a double floating-point number.
HP C/iX Library Function Descriptions atoi atoi Converts a string to an integer. Syntax #include int atoi (const char *str); Parameters str A pointer to a character string to convert to an integer. Return Values x An integer value upon successful completion. 0 An error occurred. The str argument may have started with an unrecognized character. Description The atoi function converts the string of characters pointed to by the str argument into an integer.
HP C/iX Library Function Descriptions atol atol Converts a string to a long integer. Syntax #include long int atol (const char *str); Parameters str A pointer to a character string to be converted to an object of type long int. Return Values x A long integer upon successful completion. 0 An error occurred. The str argument may have started with an unrecognized character.
HP C/iX Library Function Descriptions Bessel Functions Bessel Functions The Bessel functions are j0, j1, jn, y0, y1, and yn. Syntax #include double j0 (double x); double j1 (double x); double jn (int i, double x); double y0 (double x); double y1 (double x); double yn (int i, double x); Parameters x A real number input to the Bessel functions. i An integer value indicating the order to use when calculating the Bessel functions. Return Values n The result of the Bessel function.
HP C/iX Library Function Descriptions Bessel Functions Error handling can be changed by a user-written matherr function.
HP C/iX Library Function Descriptions bsearch bsearch Performs a binary search of a sorted array. Syntax #include void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *)); Parameters key A pointer to the search pattern to be found in the table. base A pointer to the beginning of a table of items to be searched. nmemb The number of elements in the array. size The total size, in bytes, of each element of the array.
HP C/iX Library Function Descriptions calloc calloc Allocates a block of memory. Syntax #include void *calloc (size_t nelem, size_t elsize); Parameters nelem The number of elements, each of size elsize, to be found in the block of allocated memory. elsize The size, in bytes, of each element specified in nelem. Return Values x A pointer to the allocated space. NULL There is not enough available memory or elsize is zero.
HP C/iX Library Function Descriptions catread catread Returns a message from a message catalog file in HP-UX format. Syntax int catread (int fd, int set_num, int msg_num, char *msg_buf, int buflen [,char *arg]....); Parameters fd An integer containing a file descriptor of the message catalog. set_num An integer containing the message set number where the message to be read is located. msg_num An integer containing the message number within the set to read from the message catalog.
HP C/iX Library Function Descriptions ccode ccode Retrieves the condition code for the calling process. Syntax #include int ccode(); Parameters None. Return Values The general meanings of the values returned by ccode are described below. The specific meaning depends upon the intrinsic called. Refer to the individual intrinsic descriptions in the MPE/iX Intrinsics Reference Manual for details on the specific meaning.
HP C/iX Library Function Descriptions ceil ceil Computes the ceiling function that finds the smallest integer that is greater than or equal to the specified real number. Syntax #include double ceil (double x); Parameters x A real number. Return Values n An integer value of type double. Description The ceil function returns the smallest integer not less than the argument x. See Also floor(), fmod(), ANSI C 4.5.6.1, POSIX.1 8.
HP C/iX Library Function Descriptions clearerr clearerr Clears the end-of-file and error indicators of a stream. Syntax #include void clearerr (FILE *stream); Parameters stream A pointer to an open stream. Return Values None. Description The clearerr function clears the end-of-file and error indicators to zero for the file pointed to by stream. See Also fopen(), ANSI C 4.9.10.1, POSIX.1 8.
HP C/iX Library Function Descriptions clock clock Reports CPU time used. Syntax #include clock_t clock (void) Parameters None. Return Values x The number of clock ticks consumed by the program. Description The clock function returns the amount of CPU time, in microseconds, used since the first call to clock(). The time reported is the sum of the user and system times of the calling process. The resolution of the clock varies, depending on the hardware and on the software configuration.
HP C/iX Library Function Descriptions close close Closes a file. Syntax int close (int fildes); Parameters An open file descriptor. fildes Return Values 0 A successful close. −1 An unsuccessful close and errno is set to one of the following values: EBADF The fildes parameter is not a valid open file descriptor. ESYSERR A call to a system intrinsic failed. Description The close function closes the file indicated by fildes.
HP C/iX Library Function Descriptions cos cos Computes a cosine value for a given angle. Syntax #include double cos (double x); Parameters x A real number giving the angle measured in radians. Return Value n The cosine of the angle. 0 A complete loss of significance. A TLOSS error message is printed on the standard error output. The external variable errno is set to ERANGE. Description The cos function returns the cosine of its argument, x, measured in radians.
HP C/iX Library Function Descriptions cosh cosh Computes the hyperbolic cosine of an angle. Syntax #include double cosh (double x); Parameters x A real number giving the angle measured in radians. Return Values HUGE_VAL An overflow condition occurred, and errno is set to ERANGE. n The hyperbolic cosine of the given angle. Description The cosh function returns the hyperbolic cosine of the given angle. Error handling can be changed by a user-written matherr function.
HP C/iX Library Function Descriptions creat creat Creates a new file or rewrites an existing file. Syntax #include creat (char *pathname, int mode) Parameters pathname A pointer to a string containing the pathname of a file to be created or rewritten. The pathname must be terminated by a null character. mode The mode parameter is ignored. This parameter is provided for compatibility with other systems. Return Values ≥0 Success.
HP C/iX Library Function Descriptions creat open (path, O_WRONLY | O_CREAT | O_TRUNC, mode); NOTE If linking with the POSIX/iX library, refer to the description of creat() located in the MPE/iX Developer's Kit Reference Manual.
HP C/iX Library Function Descriptions crypt crypt Provides one-way encryption of passwords. Syntax char *crypt (char *key, char *salt); Parameters key A pointer to a character string to be encrypted. salt A pointer to a character string used as the initial value in the hashing algorithm. Return Values x A pointer to a character string containing the encrypted password. Description The crypt function is the password encryption function based on the NBS Data Encryption Standard (DES).
HP C/iX Library Function Descriptions ctime ctime Converts the current time into a 26-character ASCII string of the form Fri May 11 09:53:03 1984\n\0 where \n is a newline character and \0 is a terminating null character. Syntax #include char *ctime(const time_t *timer); Parameters timer A pointer to the time to be converted. Return Value x A pointer to a 26-byte character string containing the converted time.
HP C/iX Library Function Descriptions difftime difftime Computes the difference between two times. Syntax #include double difftime (time_t time2, time_t time1); Parameters time2 A time, in time_t format. time1 A time, in time_t format. Return Values x Returns time2 - time1 in seconds as a double. Description The difftime function computes the time difference between time2 and time1 in seconds. The time2 parameter should be the later of the two times. See Also time(), ANSI C 4.12.2.
HP C/iX Library Function Descriptions div div Computes the quotient and remainder of two integers. Syntax #include div_t div (int numer, int denom); Parameters numer The numerator. denom The denominator. Return Values Returns a structure of type div_t, comprising the quotient and the remainder.
HP C/iX Library Function Descriptions dup dup Duplicates an open file descriptor. Syntax #include int dup (int fildes); Parameters A file descriptor. fildes Return Values n A non-negative integer representing the new file descriptor. −1 An error occurred and errno is set to one of the following values: EBADF The fildes parameter is not a valid open file descriptor. EMFILE The maximum number of file descriptors are currently open.
HP C/iX Library Function Descriptions ecvt ecvt Converts a floating-point number to a string. Syntax char *ecvt (double value, int ndigit, int *decpt, int sign); Parameters value The floating-point number to be converted to a character string. ndigit The number of digits to convert. decpt A pointer to an integer to which the position of the decimal point relative to the beginning of the string is returned. sign A pointer to an integer to which a flag indicating the sign of the number is returned.
HP C/iX Library Function Descriptions encrypt encrypt Encrypts a block of data. Syntax void encrypt (char *block, int edflag); Parameters block A pointer to the character array that is encrypted. edflag An integer that is ignored by the function. Return Values None. Description The encrypt function scrambles the data in block using the same hashing algorithm used by crypt().
HP C/iX Library Function Descriptions erf erf Returns the statistical error function of the input value. Syntax #include double erf (double x); Parameters x A real number defining the upper limit of the integral. Return Values n The integral given by the error function from 0 to x. Description The erf function returns the error function of x, defined as: Figure 5-1.
HP C/iX Library Function Descriptions erfc erfc Returns the complementary error function of the input value. Syntax #include double erfc (double x); Parameters x A real number defining the upper limit of the integral. Return Values n The complement of the integral given by the error function from 0 to x. Description The erfc function returns the complementary error function, 1- erf(x).
HP C/iX Library Function Descriptions exit exit Terminates the calling process normally. Syntax #include void exit (int status); Parameters status A value passed to the environment upon program termination. Return Values None. Description The exit function terminates the calling process. The parameter status is returned to the MPE/iX command interpreter using the CJCW job control word.
HP C/iX Library Function Descriptions exp exp Returns the base e raised to the power of the argument. Syntax #include double exp (double x); Parameters x A real number used as the exponent of e. Return Values n e raised to the power of x. HUGE_VAL An overflow condition has occurred and errno is set to ERANGE. 0 An underflow condition has occurred. Description exp returns ex. This function sets errno to ERANGE when an underflow or overflow occurs.
HP C/iX Library Function Descriptions fabs fabs Computes the absolute value of a floating-point argument. Syntax #include double fabs (double x); Parameters x A floating-point value whose absolute value is to be computed. Return Values n The absolute value of the floating-point value specified in x. Example The following program calculates floating-point absolute values until a zero is entered from the keyboard: #include
HP C/iX Library Function Descriptions fclose fclose Closes an open file. Syntax #include int fclose (FILE *stream); Parameters stream A pointer to the file to be closed. Return Values 0 The file is successfully closed. ≠0 An error occurred. The file is not closed. Description The fclose function flushes the buffer associated with the specified stream, and, if the buffer was allocated automatically by the standard I/O system, frees the space allocated to that buffer.
HP C/iX Library Function Descriptions fcvt fcvt Converts a floating-point number to a string. Syntax char *fcvt (double value, int ndigit, int *decpt, int *sign); Parameters value The floating-point number to be converted to a character string. ndigit The number of digits to convert. decpt A pointer to an integer to which the position of the decimal point relative to the beginning of the string is returned. sign A pointer to an integer to which a flag indicating the sign of the number is returned.
HP C/iX Library Function Descriptions fdopen fdopen Opens a stream on a file descriptor. Syntax #include FILE *fdopen (int fildes, const char *type); Parameters fildes An open file descriptor. type A pointer to a character string containing a new access mode. Following are valid strings and their meanings: r Open or create file for reading. w Open or create file for writing. a Open or create file in append mode. All writes are at end-of-file.
HP C/iX Library Function Descriptions fdopen file. The fseek function may be used to reposition the file pointer to any position in the file, but when output is written to the file, the current file pointer is disregarded. All output is written at the end of the file, and the file pointer is repositioned at the end of the output. When opening a binary file, the file position indicator may, in some cases, be positioned beyond the last data written because of blank or null padding.
HP C/iX Library Function Descriptions feof feof Tests whether the end-of-file indicator for a stream has been set. Syntax #include int feof (FILE *stream); Parameters stream A pointer to a file to be tested. Return Values =0 End-of-file has not been set. ≠0 End-of-file has been set. Description The feof function is intended to clarify ambiguous return values from standard I/O functions. The feof function returns a nonzero value if the end-of-file indicator was set on the specified stream.
HP C/iX Library Function Descriptions feof fprintf("Can't open %s.\n", argv[1]); exit(1); } datale = fopen("dfle", "w"); if(datale == NULL) { fprintf("Can't create dfle file.\n"); exit(1); } datagt = fopen("dfgt", "w"); if(datagt == NULL) { fprintf("Can't create dfgt file.
HP C/iX Library Function Descriptions ferror ferror Tests whether the error indicator for a stream has been set. Syntax #include int ferror (FILE *stream); Parameters stream A pointer to a file to be tested. Return Values 0 Error indicator has not been set. ≠0 Error indicator has been set. Description The ferror function is intended to clarify ambiguous return values from standard I/O functions.
HP C/iX Library Function Descriptions fflush fflush Flushes an I/O buffer to a file. Syntax #include int fflush (FILE *stream); Parameters stream A file pointer to an output stream. Return Values 0 Success. EOF An error occurred. Description The fflush function causes any information that was buffered by the stream pointed to by the stream argument to be flushed out to the associated file. The fflush function returns an EOF if the flush operation caused a write error.
HP C/iX Library Function Descriptions fgetc fgetc Reads a character from an open stream. Syntax #include int fgetc (FILE *stream); Parameters stream Pointer to an open stream. Return Values x The character read, expressed as an integer. EOF No more input, or an error occurred. Description The fgetc function reads the next character from the specified stream and advances the file position. The character is returned as an integer.
HP C/iX Library Function Descriptions fgetpos fgetpos Returns the current file position of an open stream. Syntax #include int fgetpos (FILE *stream, fpos_t *pos); Parameters stream A pointer to an open stream. pos A pointer to an object of type fpos_t, where the current file position indicator is returned. Return Values 0 Success. ≠0 An error occurred, and errno is set to indicate the error condition.
HP C/iX Library Function Descriptions fgets fgets Reads a string from an open stream. Syntax #include char *fgets (char *string, int n, FILE *stream); Parameters string A pointer to a character array. n The maximum number of characters to read, plus one. stream A pointer to an open stream. Return Values x If successful, a pointer to a character array. NULL An error occurred. Description The fgets function reads a string from an open stream.
HP C/iX Library Function Descriptions fgets if(argc != 3) { printf("Usage: cp fromfile tofile\n"); exit(1); } from = fopen(argv[1], "r"); if(from == NULL) { printf("Can't open %s.\n", argv[1]); exit(1); } to = fopen(argv[2], "w"); if(to == NULL) { printf("Can't create %s.\n", argv[2]); exit(1); } while(fgets(line, 256, from) != NULL) fputs(line, to); exit(0); } The program above accepts two arguments: the first is the name of the file to be copied, and the second is the name of the file to be created.
HP C/iX Library Function Descriptions fgets printf("Can't open %s.\n", argv[1]); exit(1); } while(fgets(line, 256, from) != NULL) fputs(line, stdout); exit(0); } See Also ferror(), fopen(), fread(), getc(), puts(), scanf() ANSI C 4.9.7.2, POSIX.1 8.
HP C/iX Library Function Descriptions fileno fileno Maps a stream pointer to a file descriptor. Syntax #include int fileno (FILE *stream); Parameters stream A pointer to an open stream. Return Values ≥0 An open file descriptor associated with stream. Description The fileno function returns the file descriptor associated with stream. The following symbolic values, located in
HP C/iX Library Function Descriptions floor floor Computes the largest integer value that is less than or equal to its argument. Syntax #include double floor (double x); Parameters x A real number. Return Values n An integer value stored as a double. Description The floor function returns the largest integer not greater than x. See Also ANSI C 4.5.6.3, POSIX.1 8.
HP C/iX Library Function Descriptions fmod fmod Returns the floating-point remainder of x divided by y. Syntax #include double fmod (double x, double y); Parameters x The numerator. y The divisor. Return Values f The remainder of x/y. NaN Neither x or y is a number, x is +INFINITY, or y is zero. In addition, errno is set to EDOM. x An underflow condition has occurred; y may be ±infinity. 0 An overflow condition has occurred.
HP C/iX Library Function Descriptions fopen fopen Opens a stream. Syntax #include FILE *fopen (const char *fname, const char *mode); Parameters fname A pointer to a character string containing the name of the file. mode A pointer to a character string defining the mode of the file open. Return Values x If successful, a pointer to the FILE structure associated with the stream. NULL The file open operation failed.
HP C/iX Library Function Descriptions fopen rb Open or create binary stream for reading. wb Open or create binary stream for writing. Truncate to zero length. ab Open or create binary stream in append mode. All writes are at end-of-file. r+ Open or create text stream for update (reading and writing). w+ Open or create text stream for update. Truncate to zero length. a+ Open or create text stream for append update (read anywhere but all writes at end-of-file).
HP C/iX Library Function Descriptions fopen closed. The affect of each value of n is defined as follows: 0 Don't change the disposition. 1 Save the file as a permanent file. 2 Save the file as a temporary file. 3 Don't rewind on close. 4 Purge the file on close. If the Df option is not specified and the file is a new file, then the default is to save the file as a permanent file. If the file is old, the default is not to change the disposition.
HP C/iX Library Function Descriptions fopen specified. The default for text and binary streams is 256 bytes. The default for byte streams is 1 byte. Sn The S option specifies the maximum size of the file. The value of n is the maximum size of the file in records for text and binary streams, and in bytes for byte streams. Notice that if the S parameter is not specified, the default is 4095. Te If the Te option is specified, the file is saved in the temporary file domain.
HP C/iX Library Function Descriptions fprintf fprintf Writes data in formatted form to an open stream. Syntax #include int fprintf (FILE *stream, const char *format [,item [,item]...] ); Parameters stream A pointer to an open stream where data is to be written. format A pointer to a character string defining the format of the data to be written (or the character string itself enclosed in double quotes). item,… Each item is a variable or expression specifying the data to write.
HP C/iX Library Function Descriptions fprintf 5. An optional l, h, or L indicating that the argument is of an alternate type. When used in conjunction with an integer conversion character, an l or h indicates a long or short integer argument, respectively. When used in conjunction with a floating-point conversion character, an L indicates a long double argument. 6. A conversion character, which indicates the type of data to be converted and printed.
HP C/iX Library Function Descriptions fprintf to be formatted and printed appropriately. The integer conversion characters are: d, i An integer item is converted to signed decimal. The precision, if given, specifies the minimum number of digits to appear. If the value has fewer digits than that specified by the precision, the value is expanded with leading zeros. The default precision is 1. A null string results if a zero value is printed with a zero precision. The # flag has no effect.
HP C/iX Library Function Descriptions fprintf [-]d.ddde±ddd where there is always one digit before the decimal point. The number of digits after the decimal point is equal to precision. If precision is not given, six digits are written after the decimal point. If the precision is explicitly zero, the decimal point is eliminated entirely. The exponent always contains exactly three digits. If the # flag is specified, the result always contains a decimal point, even if no digits follow the decimal point.
HP C/iX Library Function Descriptions fprintf } file = fopen(argv[1], "r"); if(file == NULL) { fprintf(stderr, "Can't open %s.\n", argv[1]); exit(1); } while(fscanf(file, "%*s") != EOF) count; fprintf(stdout, "Number of words found: %d\n", count); exit(0); } This program counts the number of "words" in the file specified as its only argument. A word is defined as a string of nonspace characters. In this program, fprintf() directs error messages to stderr.
HP C/iX Library Function Descriptions fprintmsg fprintmsg Prints formatted output with numbered arguments. Syntax #include int fprintmsg (file *stream, char *format [, arg] ...); Parameters stream A stream file pointer to which the output is directed. format A pointer to the string containing formatting information to be output. format contains optional placeholders and formatting specifications where arg1 thru argn are to be substituted. arg1 ...
HP C/iX Library Function Descriptions fputc fputc Writes a character to an output stream. Syntax #include int fputc (int c, FILE *stream); Parameters c A character, expressed as an integer, to be written to the output stream. stream A pointer to an open stream. Return Values x The character written, expressed as an integer. EOF An error occurred. Description The fputc function writes the character specified in c to the specified stream and advances the file position.
HP C/iX Library Function Descriptions fputs fputs Writes a string to an output stream. Syntax #include int fputs (const char *string, FILE *stream); Parameters string A pointer to an array of characters. stream A pointer to an output stream. Return Values ≥0 Success. EOF An error occurred. Description The fputs function writes the character string pointed to by string to the specified stream, stopping when a null character is encountered. The terminating null character is not written.
HP C/iX Library Function Descriptions fread fread Reads data items from an open stream. Syntax #include size_t fread (void *fileptr, size_t size, size_t nitems, FILE *stream); Parameters fileptr A pointer to a buffer to hold the data. The type of the buffer is determined by the type of the data being read. size The size of each data item, in bytes. nitems The number of data items to read. stream A pointer to an open stream. Return Values >0 The number of items actually read.
HP C/iX Library Function Descriptions fread #include struct emp { char name[40]; char job[40]; long salary; char hire[6] char curve[2] int rank; } #define EMPS 400 main() { int items; struct emp staff[EMPS]; FILE *data; /* /* /* /* /* /* name */ job title */ salary */ hire date */ pay curve */ percentile ranking */ /* no. of employees */ data = fopen("empdata", "r"); if(data == NULL) { fprintf(stderr, "Can't open employee data file.
HP C/iX Library Function Descriptions fread } This program reads the employee information contained in the binary file empdata. The data in this file consists of concatenated streams of bytes describing each employee in a 400-employee company. The bytes are written such that, when read correctly, they correspond exactly with the emp structure defined in the program. The staff array is an array of structures containing one structure for each employee.
HP C/iX Library Function Descriptions free free Frees a block of allocated memory. Syntax #include void free (void *ptr); Parameters ptr A pointer to a block of memory previously allocated by a call to calloc(), malloc(), or realloc(). Return Values None. Description The free function frees the block of memory pointed to by ptr, making the space available for further allocation. The contents of the block are destroyed.
HP C/iX Library Function Descriptions freopen freopen Closes and reopens a stream. Syntax #include FILE *freopen (const char *fname, const char *type, FILE *stream); Parameters fname A pointer to a character string that contains the name of the file to be opened. type A pointer to a character string defining the mode of the file open. stream A pointer to an open stream. Return Values x If successful, a pointer to the FILE structure associated with the stream.
HP C/iX Library Function Descriptions freopen The type parameter points to a character string beginning with one of the following sequences: r Open or create text stream for reading. w Open or create text stream for writing. Truncate to zero length. a Open or create text stream in append mode. All writes are at end-of-file. rb Open or create binary stream for reading. wb Open or create binary stream for writing. Truncate to zero length. ab Open or create binary stream in append mode.
HP C/iX Library Function Descriptions freopen Bun The Bu option specifies the number of buffers to be allocated to this file. If the Bu option is not specified, the default is 2. C If the C option is specified, then the file accepts carriage control information. The default is to not have carriage control. Dfn The Df option specifies the final disposition of the file after the file is closed. The affect of each value of n is defined as follows: 0 Don't change the disposition.
HP C/iX Library Function Descriptions freopen Rn The R option specifies the size of the record if the file is created by this open request. If the V option is also used, this option specifies the maximum size of the variable sized records. The option letter is followed by a decimal number that is equal to the number of bytes in the record size. Notice that the number must be positive. A byte count is always specified. The default for text and binary streams is 256 bytes.
HP C/iX Library Function Descriptions frexp frexp Breaks a floating-point number into a normalized fraction and an integral power of 2. Syntax #include double frexp (double value, int *eptr); Parameters value A real number input to the function. eptr A pointer to the integer exponent returned by the function. Return Values x A real number between 0.5 and 1.
HP C/iX Library Function Descriptions fscanf fscanf Reads externally formatted data from an open stream. Syntax #include int fscanf (FILE *stream, const char *format [,item [,item]...] ); Parameters stream A pointer to an open stream from which data is to be read. format A pointer to a character string defining the format of the data to be read (or the character string itself enclosed in double quotes). item Each item is the address of a variable into which the data will be placed.
HP C/iX Library Function Descriptions fscanf are called conversion characters. The integer and floating-point conversion characters may be optionally preceded by a character indicating the size of the receiving variable. When a conversion specification is encountered in a format, it is matched up with the corresponding item in the item list. The data formatted by that specification is then stored in the location pointed to by that item.
HP C/iX Library Function Descriptions fscanf Matches a single %. No conversion or assignment occurs. The complete conversion specification is &%&% % Integer Conversion Characters The d, o, and x conversion characters read characters from the stream until an inappropriate character is encountered, or until the number of characters specified by the field width, if given, is exhausted (whichever comes first). For d, an inappropriate character is any character except +, -, and 0 through 9.
HP C/iX Library Function Descriptions fscanf character in the input). The [ conversion character also reads a character string from the open stream. However, you should use this character when a string is not to be delimited by space characters. The left bracket is followed by a list of characters, and is terminated by a right bracket.
HP C/iX Library Function Descriptions fscanf See Also getc(), setlocale(), scanf(), fprintf(), printf(), ANSI C 4.9.6.2, POSIX.1 8.
HP C/iX Library Function Descriptions fseek fseek Positions the next I/O operation on an open stream to a new position relative to the current position. Syntax #include int fseek (FILE *stream, long int offset, int ptrname); Parameters stream A pointer to an open stream. offset The number of bytes to skip over. The offset parameter can be negative or positive, indicating backward or forward movement in the file, respectively.
HP C/iX Library Function Descriptions fseek Example The following program uses the ftell() and fseek() functions. The program prints each line of an n-line file in this order: line 1, line n, line 2, line n-1, line 3, and so on. #include
HP C/iX Library Function Descriptions fseek { char c; int count = 0; while((c = getc(fp)) != EOF) { if(c == '\n') count++ } rewind(fp); return(count); } findnl(fp, offset) FILE *fp; long offset; { char c; fseek(fp, (offset-2), 0); while((c = getc(fp)) != '\n') { fseek(fp, -2, 1); } } This program uses the ftell() and fseek() functions to print lines from a file starting at the beginning and the end of the file, and converging toward the center.
HP C/iX Library Function Descriptions fseek fseek to do this: … int empno, bytes; long total; FILE *data; struct emp empinfo; /* check for usage error and open data file */ … sscanf(argv[1], “%d”, &empno); bytes = sizeof(empinfo); total = (empno - 1) * bytes; fseek(data, total, 0); fread((char *)&empinfo, sizeof(empinfo), 1, data); /* print out desired information */ … exit(0); } In this program, argv[1] contains, using a command-line argument, the employee number about whom information is desired.
HP C/iX Library Function Descriptions fsetpos fsetpos Sets the file position for a stream. Syntax #include int fsetpos (FILE *stream, const fpos_t *pos); Parameters stream Pointer to a file. pos A pointer to a structure that specifies the position of the file position indicator. Return Values 0 Success. ≠0 An error occurred, and errno is set to indicate the error condition.
HP C/iX Library Function Descriptions ftell ftell Returns the current file position indicator for the next I/O operation on an open stream. Syntax #include long int ftell (FILE *stream); Parameters stream A pointer to an open stream. Return Values ≥0 The current position for the next I/O operation, expressed as a byte offset relative to the beginning of the open file. (The first byte is byte 0.) −1 An error occurred.
HP C/iX Library Function Descriptions fwrite fwrite Writes data items to an open stream. Syntax #include size_t fwrite (const void *ptr, size_t size, size_t nitems, FILE *stream); Parameters ptr A pointer to a buffer that holds the data to be written to the open stream. The type of the buffer is determined by the type of the data being written. size The size of each data item, in bytes. nitems The number of data items to write. stream A pointer to an open stream.
HP C/iX Library Function Descriptions gamma gamma Returns the log gamma of the input value. Syntax #include double gamma (double x); extern int signgam; Parameters x A real number. Return Values n A real number giving the natural log of the absolute value of the gamma of x. HUGE Indicates one of the following: • The parameter x is a non-positive integer, and errno is set to EDOM. A message indicating SING error is printed on the standard error output.
HP C/iX Library Function Descriptions gamma y = signgam * exp(y); where LN_MAXDOUBLE is the lowest value that causes exp to return a range error, and is defined in the header file. Error handling can be changed by a user-written matherr function.
HP C/iX Library Function Descriptions gcvt gcvt Converts floating-point numbers to strings. Syntax char *gcvt (double value, int ndigit, char *buf); Parameters value The floating-point number to be converted to a character string. ndigit The number of digits to convert. buf A pointer to a character string containing the numeric string to be formatted and to which the resulting formatted character string is returned.
HP C/iX Library Function Descriptions getc getc Reads a character from an open stream. Syntax #include int getc (FILE *stream); Parameters stream A pointer to an open stream. Return Values x The character read, expressed as an integer. EOF No more data, or an error occurred. Description The getc function returns the next character from the input stream pointed to by stream. The getc function is equivalent to the fgetc function except that it is implemented as a macro.
HP C/iX Library Function Descriptions getc putc('\n', stdout); exit(0); } This program accepts a single argument that is assumed to be the name of a file whose contents are to be printed on the terminal. The specified file is opened for reading, and the resulting file pointer fp is used in getc() to read a character from the file. Each character read is written on stdout using putc(). (Note that stdout, stdin, and stderr are legal file pointers.
HP C/iX Library Function Descriptions getchar getchar Reads a character from the standard input stream stdin. Syntax include int getchar (void); Parameters None. Return Values x The character read from stdin. EOF Either an end-of-file was detected or an error occurred. Description The getchar function reads one character from the standard input stream stdin. The getchar function returns the next character in the currently defined stdin stream.
HP C/iX Library Function Descriptions getchar modify data before passing it on). For example, the following program puts parentheses around each vowel encountered in the input: #include
HP C/iX Library Function Descriptions getchar Thus, the putchar() call in the previous program can be stated as putc(c); without altering the behavior of the program. See Also fread(), getc(), gets(), fscanf(), scanf(), putchar(), ANSI C 4.9.7.6, POSIX.1 8.
HP C/iX Library Function Descriptions getenv getenv Returns the value of an environment variable. Syntax #include char *getenv (const char *name); Parameters The string to search. The string may be either the desired name, null-terminated, or of the form name=value, in which case getenv() uses the portion to the left of the = as the search key. name Return Values x A pointer to a string associated with the environment variable pointed to by name.
HP C/iX Library Function Descriptions getmsg getmsg Gets a message from a catalog. This function provides support for message catalogs that are created on HP-UX and moved to an MPE/iX system. Syntax char *getmsg (int fd, int set_num, int msg_num, char *buf, int buflen); Parameters fd An integer containing a file descriptor of an open message catalog file. set_num An integer containing the message set number where the message to be read is located.
HP C/iX Library Function Descriptions getopt getopt Gets ASCII characters from an argument vector. Syntax int getopt (int argc, char *argv, char *optstring); extern char *optarg; extern int optind, opterr; Parameters argc An integer giving the length of the array argv. argv A pointer to the command line. optstring A string of recognized option letters. Return Values '?' An option letter is not included in optstring. This error message can be disabled by setting opterr to zero.
HP C/iX Library Function Descriptions getopt beyond . Options can be any ASCII characters except colon (:), question mark (?), or null (\0). It is impossible to distinguish between a ? used as a legal option, and the character that getopt returns when it encounters an invalid option character in the input. Set opterr to 0 to disable getopt from printing error messages on the standard error device.
HP C/iX Library Function Descriptions getopt } 202 Chapter 5
HP C/iX Library Function Descriptions gets gets Reads a string from the standard input stream stdin. Syntax #include char *gets (char *s); Parameters A pointer to a character array where the string is to be returned. s Return Values x A pointer to the character array. NULL An error occurred. If any characters were read, the array contents are indeterminate.
HP C/iX Library Function Descriptions getpid getpid Returns the process identification number. NOTE If linking with the POSIX/iX libraries, refer to the description of getpid() located in the MPE/iX Developer's Kit Reference Manual. Syntax int getpid (void) Parameters None. Return Values x The process identification number (PIN) of the calling process. See Also MPE/iX intrinsics FATHER and GETPROCID, described in the MPE/iX Intrinsics Reference Manual.
HP C/iX Library Function Descriptions getw getw Reads a word from an open stream. Syntax #include int getw (FILE *stream); Parameters stream A pointer to an open stream. Return Values x The word read, expressed as an integer. EOF No more data, or an error occurred. Description The getw function returns the next word (int in C) from the named input stream. The getw function increments the associated file pointer, if defined, to point to the next word.
HP C/iX Library Function Descriptions gmtime gmtime Converts time to Coordinated Universal Time (UTC) in the structured tm type format. Syntax #include struct tm *gmtime (const time_t *timer); Parameters timer A pointer to a variable of type time_t. Return Values x A pointer to a variable of type tm. NULL The Coordinated Universal Time (UTC) is not available. Description The gmtime function converts a time_t variable, such as that returned by the time function, into a structured tm format.
HP C/iX Library Function Descriptions hcreate hcreate Allocates sufficient space for a hash table used by the hsearch function. Syntax #include int hcreate (unsigned nel); Parameters An estimate of the maximum number of elements that the table contains. This number may be adjusted upward by the algorithm to obtain a mathematically favorable table size. nel Return Values ≠0 Successful. The space was allocated.
HP C/iX Library Function Descriptions hcreate int age, room; /* other than the key.
HP C/iX Library Function Descriptions hcreate } } } See Also hsearch(), hdestroy() Chapter 5 209
HP C/iX Library Function Descriptions hdestroy hdestroy Destroys a search table created by hcreate(). Syntax #include void hdestroy (void); Parameters None. Return Values None. Description The hdestroy function destroys the search table created by a previous call to hcreate(). A subsequent call to hcreate() can be made to create a new search table. Only one hash search table may be active at any given time. NOTE The hdestroy function and the header file are not part of ANSI C.
HP C/iX Library Function Descriptions hsearch hsearch Returns a pointer into a hash table, indicating the location of a specified entry. Syntax #include ENTRY *hsearch (ENTRY item, ACTION action); Parameters A structure of type ENTRY, defined in the header file. The item parameter contains two pointers: item • item.key points to the comparison key. • item.data points to any other data to be associated with that key.
HP C/iX Library Function Descriptions hsearch Example Refer to the example located in the hcreate function description.
HP C/iX Library Function Descriptions hypot hypot Computes the length of the hypotenuse of a right triangle. Syntax #include double hypot (double x, double y); Parameters x A real number indicating the length of one of the sides of the triangle adjacent to the right angle. y A real number indicating the length of the other side of the triangle adjacent to the right angle. Return Values n The length of the hypotenuse of a right triangle.
HP C/iX Library Function Descriptions isalnum isalnum Tests whether an argument is a letter or a decimal digit. Syntax #include int isalnum (int c); Parameters c An argument to be evaluated. The argument must be representable as an unsigned char or the macro EOF. Return Values ≠0 The argument passed in c is a letter or a decimal digit. 0 The argument passed in c is not a letter or a decimal digit.
HP C/iX Library Function Descriptions isalpha isalpha Tests whether an argument is a letter. Syntax #include int isalpha (int c); Parameters c An argument to be evaluated. The argument must be representable as an unsigned char or the macro EOF. Return Values ≠0 The argument passed in c is a letter. 0 The argument passed in c is not a letter.
HP C/iX Library Function Descriptions isatty isatty Checks whether a file descriptor is associated with a display device, such as a terminal. Syntax int isatty (int fildes) Parameters An open file descriptor. fildes Return Values 1 The file descriptor is a terminal device. 0 The file descriptor is not a terminal device. Description The isatty function returns true or false depending on whether or not fildes is associated with a terminal.
HP C/iX Library Function Descriptions iscntrl iscntrl Tests whether an argument is a control character. Syntax #include int iscntrl (int c); Parameters c An argument to be evaluated. The argument must be representable as an unsigned char or the macro EOF. Return Values ≠0 The argument passed in c is an ASCII control character. 0 The argument passed in c is not an ASCII control character.
HP C/iX Library Function Descriptions isdigit isdigit Tests whether an argument is a decimal digit. Syntax #include int isdigit (int c); Parameters c An argument to be evaluated. The argument must be representable as an unsigned char or the macro EOF. Return Values ≠0 The argument passed in c is a decimal digit. 0 The argument passed in c is not a decimal digit.
HP C/iX Library Function Descriptions isgraph isgraph Tests whether an argument is a printable nonspace character. Syntax #include int isgraph (int c); Parameters c An argument to be evaluated. The argument must be representable as an unsigned char or the macro EOF. Return Values ≠0 The argument passed in c is printable. 0 The argument passed in c is not printable.
HP C/iX Library Function Descriptions islower islower Tests whether an argument is a lowercase letter. Syntax #include int islower (int c); Parameters c An argument to be evaluated. The argument must be representable as an unsigned char or the macro EOF. Return Values ≠0 The argument passed in c is a lowercase letter. 0 The argument passed in c is not a lowercase letter.
HP C/iX Library Function Descriptions isprint isprint Tests whether an argument is any printable character including the space character (octal values 040 through 0176). Syntax #include int isprint (int c); Parameters c An argument to be evaluated. The argument must be representable as an unsigned char or the macro EOF. Return Values ≠0 The argument passed in c is any printable character including the space character (octal values 040 through 0176).
HP C/iX Library Function Descriptions ispunct ispunct Tests whether an argument is any printable character that is not a space, a digit, or a letter. Syntax #include int ispunct (int c); Parameters c An argument to be evaluated. The argument must be representable as an unsigned char or the macro EOF. Return Values ≠0 The argument passed in c is any printable character that is not a space, a digit, or a letter.
HP C/iX Library Function Descriptions isspace isspace Tests whether an argument is a white-space character. Syntax #include int isspace (int c); Parameters c An argument to be evaluated. The argument must be representable as an unsigned char or the macro EOF. Return Values ≠0 The argument passed in c is a white-space character. 0 The argument passed in c is not a white-space character.
HP C/iX Library Function Descriptions isupper isupper Tests whether an argument is an uppercase letter. Syntax #include int isupper (int c); Parameters c An argument to be evaluated. The argument must be representable as an unsigned char or the macro EOF. Return Values ≠0 The argument passed in c is an uppercase letter. 0 The argument passed in c is not an uppercase letter.
HP C/iX Library Function Descriptions isxdigit isxdigit Tests whether an argument is a hexadecimal digit. Syntax #include int isxdigit (int c); Parameters c An argument to be evaluated. The argument must be representable as an unsigned char or the macro EOF. Return Values ≠0 The argument passed in c is a hexadecimal digit. 0 The argument passed in c is not a hexadecimal digit.
HP C/iX Library Function Descriptions l3tol l3tol The l3tol function converts 3-byte integers to long integers. Syntax void l3tol (long *lp, char *cp, int *n); Parameters lp A pointer to an array of n converted long integers. cp A pointer to a character string containing the n three-byte integers to be converted. n The number of three-byte integers packed in cp. Return Values None.
HP C/iX Library Function Descriptions l64a l64a Converts a long integer to a base-64 ASCII string. Syntax char *l64a (l) long l; Parameters A long integer. l Return Values x A pointer to the base-64 ASCII string. NULL The argument is 0. Description This function maintains numbers stored in base-64 ASCII characters. Long integers can be represented by up to six characters. Each character represents a digit in a radix-64 notation. The characters used to represent digits are: Characters Digits .
HP C/iX Library Function Descriptions labs labs Computes the absolute value of a long integer argument. Syntax #include long int labs (long int j); Parameters j A long integer value whose absolute value is to be computed. Return Values x The absolute value of the long integer specified in j. Description The labs function returns the absolute value of the long integer value specified in j. See Also abs(), fabs(), ANSI C 4.10.6.
HP C/iX Library Function Descriptions ldexp ldexp Accepts a double value and an integer exponent exp, and returns a double quantity equal to value * 2exp. Syntax #include double ldexp (double value, int exp); Parameters value A real number that is to be multiplied by 2exp. exp The integer exponent value to which 2 is raised. Return Values n The result of value * 2exp. 0 An underflow condition has occurred; errno is set to indicate the error. HUGE_VAL An overflow condition has occurred.
HP C/iX Library Function Descriptions ldiv ldiv Computes the quotient and remainder of two long integers. Syntax #include ldiv_t ldiv (long int numer, long int denom); Parameters numer The numerator. denom The denominator. Return Values Returns a structure of type ldiv_t comprising the quotient and the remainder.
HP C/iX Library Function Descriptions lfind lfind Performs a linear search. Syntax #include char *lfind ((char *)key, (char *)base, nelp, sizeof(*key), compar) unsigned *nelp int (*compar) ( ); Parameters key A pointer to the value to be found in the table. base A pointer to the first element in the table. nelp A pointer to an integer containing the current number of elements in the table. width The size of each datum in the table; it is the width of each table row.
HP C/iX Library Function Descriptions lfind See Also lsearch() 232 Chapter 5
HP C/iX Library Function Descriptions localeconv localeconv Returns information about the editing symbols of a numeric quantity specific to a locale. Syntax #include struct lconv *localeconv (void); Parameters None. Return Values x A pointer to an object of type struct lconv. Description The localeconv function returns a pointer to an object of type struct lconv that contains information about the editing symbols of a numeric quantity specific to a locale.
HP C/iX Library Function Descriptions localtime localtime Converts time to the local time zone. Syntax #include struct tm *localtime (const time_t *timer); Parameters timer A pointer to a variable of type time_t. Return Values x A pointer to a structured time variable of type tm. Description The localtime function is passed a pointer to a time_t variable whose value is typically set by the time function.
HP C/iX Library Function Descriptions log, log10 log, log10 Syntax #include double log (double x); double log10 (double y); Parameters x A real number whose natural logarithm is to be returned. y A real number whose logarithm in base 10 is to be returned. Return Values n The logarithm of the input value x. -HUGE The input value x is ≤0, and errno is set to EDOM. A DOMAIN error or SING error if x=0 is printed on the standard error output device.
HP C/iX Library Function Descriptions longjmp longjmp Restores an environment previously saved by setjmp(). Syntax #include void longjmp (jmp_buf env, int val); Parameters env Passes information needed to restore a previous environment. This variable was used in a previous call to setjmp() to save the environment. The type jmp_buf (defined in ) defines an array of unsigned integers. For this reason, the env argument does not require an & operator.
HP C/iX Library Function Descriptions longjmp Control does not return directly from a call to longjmp(), so there are no return values. Instead, control is returned to setjmp(), and the value stored in val is used as the return value of setjmp(). NOTE This function is also implemented as the macro _longjmp. See Also setjmp(), ANSI C 4.6.2.1, POSIX.1 8.
HP C/iX Library Function Descriptions lsearch lsearch Performs a linear search and update. Syntax #include #include char *lsearch ((char *)key, (char *)base, nelp, sizeof(*key), compar) unsigned *nelp; int (*compar)( ); Parameters key A pointer to the value to be found in the table. base A pointer to the first element in the table. nelp A pointer to an integer containing the current number of elements in the table. This integer is incremented if the item is added to the table.
HP C/iX Library Function Descriptions lsearch pointer-to-element. Undefined results can occur if there is not enough room in the table to add a new item. Example This fragment reads in TABSIZE strings of length ELSIZE and stores them in a table, eliminating duplicates. #include stdio.h> #include search.
HP C/iX Library Function Descriptions lseek lseek Moves the file position indicator. Syntax #include long lseek (int fildes, long offset, int whence); Parameters filedes An open file descriptor. offset The number of bytes to move the current file position indicator, according to the method defined by whence. whence The starting point for the seek operation. The possible values are: SEEK_SET Seek relative to the beginning of file.
HP C/iX Library Function Descriptions lseek See Also open(), dup() Chapter 5 241
HP C/iX Library Function Descriptions ltol3 ltol3 Converts long integers to 3-byte integers. Syntax void ltol3 (char *cp, long *lp, int n) char *cp; long *lp; int n; Parameters cp A pointer to a character string to which n 3-byte integers are returned. lp A pointer to an array of n long integers. n The number of long integers to be converted. Return Values None. Description The ltol3 function converts long integers (lp) to 3-byte integers (cp).
HP C/iX Library Function Descriptions mallinfo mallinfo Returns information describing space usage. Syntax #include struct mallinfo mallinfo (void); Parameters None. Return Values x A pointer to an object of type struct mallinfo. Description The mallinfo function provides instrumentation describing space usage, but may not be called until the first small block is allocated.
HP C/iX Library Function Descriptions malloc malloc Allocates a block of memory. Syntax #include void *malloc (size_t size); Parameters size The number of bytes in the block to be allocated. Return Values x A pointer to an allocated block of memory. NULL There is not enough memory available, or size is 0. Description The malloc function returns a pointer to a block of at least size bytes suitably aligned for any use.
HP C/iX Library Function Descriptions mallopt mallopt Provides control over the memory allocation algorithm. Syntax #include int mallopt (int cmd, int value); Parameters cmd value The available values for cmd are: M_MXFAST Set maxfast to value. The algorithm allocates all blocks below the size of maxfast in large groups and then passes them out very quickly. The default value for maxfast is 24. M_NLBLKS Set numlblks to value. The above mentioned large groups each contain numlblks blocks.
HP C/iX Library Function Descriptions mallopt NOTE The header and the mallopt() and mallinfo() functions are not ANSI C and should be avoided if portability is a consideration.
HP C/iX Library Function Descriptions matherr matherr The matherr function is a user-written call-back routine invoked by many functions in the math library when errors are detected. Syntax #include int matherr (x) struct exception *x; Parameters x A pointer to the exception structure defined in the header file. Return Values x A user-defined integer value. Description Users override the default math library error handler by defining a function named matherr in their programs.
HP C/iX Library Function Descriptions matherr it to a different value. Consult the function descriptions in this chapter to determine if a specific function calls matherr. If your matherr function returns nonzero, no error message is printed, and errno is not set. If matherr is not supplied, the default error-handling procedures, described with the math functions involved, are invoked upon error. In every case, errno is set to EDOM or ERANGE, and the program continues. Example #include
HP C/iX Library Function Descriptions mblen mblen Determines the number of bytes in a multibyte character. Syntax #include int mblen(const char *s, size_t n); Parameters s A pointer to a single multibyte character. n A variable of type size_t that controls the number of characters that mblen searches when scanning for a multibyte character. This argument is typically set to MB_CUR_MAX. Return Values >0 The length of the multibyte character to which s points.
HP C/iX Library Function Descriptions mblen See Also wchar_t, LC_CTYPE, MB_CUR_MAX, mbtowc(), wctomb(), mbstowcs(), wcstombs(), ANSI C 4.10.7.
HP C/iX Library Function Descriptions mbstowcs mbstowcs Converts a sequence of multibyte characters in a null-terminated string to a sequence of wide character codes. Syntax #include size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n); Parameters pwcs A pointer to an array of wide characters where the converted wide character codes are stored. s A pointer to a sequence of multibyte characters to be converted.
HP C/iX Library Function Descriptions mbtowc mbtowc Converts a single multibyte character to its wide character representation. Syntax #include int mbtowc(wchar_t *pwc, const char *s,size_t n); Parameters pwc A pointer to an object of type wchar_t to which the function returns the converted value. s A pointer to a multibyte character to be converted. n An expression of type size_t indicating the number of characters in s to be examined.
HP C/iX Library Function Descriptions memccpy memccpy Copies characters from one memory location to another until a specified character is found or until the specified count is reached. Syntax #include char *memccpy (char *s1, char *s2, int c, int n) Parameters s1 A pointer to the target string. s2 A pointer to the source string. c The character used to signal the end of the source string. n The number of bytes to be copied.
HP C/iX Library Function Descriptions memchr memchr Searches memory for a specified character. Syntax #include void *memchr(const void *s, int c, size_t n); Parameters s A pointer to the object to search. c The character value to find in the object. n The maximum number of characters to examine. Return Values x A pointer to the first occurrence of the character. If the character c is not found, a null pointer is returned.
HP C/iX Library Function Descriptions memcmp memcmp Compares the first n characters of two objects. Syntax #include int memcmp(const void *s1, const void *s2, size_t n); Parameters s1 A pointer to the first object. s2 A pointer to the second object. n The number of characters to compare. Return Values <0 s1 is less than s2. 0 s1 is equal to s2. >0 s1 is greater than s2.
HP C/iX Library Function Descriptions memcpy memcpy Copies a specified number of characters from one object to another. Syntax #include void *memcpy(void *s1, const void *s2, size_t n); Parameters s1 A pointer to the target object. s2 A pointer to the source object. n The number of characters to copy. Return Values x The value of s1. Description The memcpy function copies n characters from the object pointed to by s2 to the object pointed to by s1.
HP C/iX Library Function Descriptions memmove memmove Copies a specified number of characters from one object to another. Syntax #include void *memmove(void *s1, const void *s2, size_t n); Parameters s1 A pointer to the target object. s2 A pointer to the source object. n The number of characters to copy. Return Values x The value of s1. Description This function copies n characters from the object pointed to by s2 into the object pointed to by s1.
HP C/iX Library Function Descriptions memset memset Initializes an object with a supplied character value. Syntax #include void *memset(void *s, int c, size_t n); Parameters s A pointer to an object. c The value to be duplicated throughout the object that s points to. n The number of characters in object s to be filled with the value c. Return Values x The value of s. Description The memset function stores n copies of the character c into the object pointed to by s.
HP C/iX Library Function Descriptions mktemp mktemp Creates a unique file name. Syntax char *mktemp (char *template) Parameters template A character pointer to a string containing a template file name having six trailing Xs. Return Values x A pointer to template, or to a null string if it runs out of letters. Description The mktemp function replaces the contents of the string pointed to by template with a unique file name, and returns the address of template.
HP C/iX Library Function Descriptions mktime mktime Converts a calendar time value of type tm to a time value in time_t. Syntax #include time_t mktime(struct tm *timeptr); Parameters timeptr A pointer to a structure of type tm, as defined in . Return Values x The value pointed to by timeptr, as a type time_t. Description The mktime function converts the broken-down time in the structure pointed to by timeptr into a calendar time value.
HP C/iX Library Function Descriptions mktime By default, mktime adjusts the returned value to the Eastern Standard Time (EST) zone. You may override this default behavior by using the MPE/iX command SETVAR TZ name. Time zone names, and the format of TZTAB.LIB.SYS file containing time zone offsets from GMT are listed in appendix A, "Time Zones." Example What day of the week is July 4, 2001? #include $include
HP C/iX Library Function Descriptions modf modf Accepts a double value and splits the value into its integer and fractional parts. Syntax #include double modf (double value, double *iptr); Parameters value A real number input to the function. iptr A pointer to a real number output from the function containing the integer part of value. Return Values n The signed fractional part of value.
HP C/iX Library Function Descriptions _mpe_fileno _mpe_fileno Maps a file descriptor to an MPE file number. Syntax int _mpe_fileno(int fildes) Parameters A file descriptor. fildes Return Values x The MPE file number of the fildes. Description The _mpe_fileno function returns the MPE file number associated with fildes. This file number may be passed to MPE file system intrinsics to access files.
HP C/iX Library Function Descriptions offsetof offsetof Finds the offset of a member in a structure. Syntax #include offsetof (type, member); Parameters type The name of a structured data type. member The name of an element within the data structure type. Return Values x The byte offset of member within the structure type returned as an unsigned integer of type size_t. Description The offsetof macro calculates the offset in bytes of member from the beginning of the structure (type).
HP C/iX Library Function Descriptions open open Opens a file for reading or writing. Syntax #include int open (char *path, int oflag [,int mode [,char mpe_opts]] ); Parameters path A pointer to a path name naming a file. oflag An integer containing open mode bit flags. mode An unused integer parameter provided for compatibility with other systems. mpe_opts A pointer to a string containing file attributes and options.
HP C/iX Library Function Descriptions open O_CREAT If the file exists, this flag has no effect. If the file does not exist, the file is created. O_TRUNC If the file exists, its length is truncated to zero and the mode and owner are unchanged. The file pointer used to mark the current position within the file is set to the beginning of the file. O_MPEOPTS If this flag is specified, the argument mpe_opts specifies additional open options that provide greater control in the MPE file environment.
HP C/iX Library Function Descriptions open value of n is defined as follows: 0 Don't return any disk space allocated beyond the end-of-file indicator. 1 Return to the system any disk space allocated beyond the end-of-file indicator. The EOF becomes the file limit. No records may be added to the file beyond this new limit.
HP C/iX Library Function Descriptions open Un If the U option is specified, the file is created with n user-label records. If this option is not specified, the default is no user-label records. V If the V option is specified, the file is created with an MPE variable-length record format. If the V or Bs options are not specified, then the file is created with an MPE fixed-length record format. This option is mutually exclusive with the Bs option.
HP C/iX Library Function Descriptions perror perror Prints an error message corresponding to errno. Syntax #include void perror (const char *s); Parameters s A pointer to an optional string to be printed with the error message. If a null pointer is passed, the parameter is ignored. Return Values None. Description The perror function prints an error message corresponding to the value of errno.
HP C/iX Library Function Descriptions pow pow Returns the value of x raised to the power y. Syntax #include double pow (double x, double y); Parameters x A real number. y A real number. Return Values n The value of xy. 0 Indicates any of the following: • The x parameter is zero and y is non-positive. The `errno'' variable is set to EDOM. A DOMAIN error message is also printed on the standard error output. • The x parameter is negative and y is not an integer.
HP C/iX Library Function Descriptions printf printf Writes data in formatted form to the standard output stream stdout. Syntax #include int printf (const char *format [,item [,item]...] ); Parameters format A pointer to a character string defining the format (or the character string itself enclosed in double quotes). item,… Each item is a variable or expression specifying the data to print. Return Values ≥0 If successful, the number of characters written. <0 An error occurred.
HP C/iX Library Function Descriptions printf 6. A conversion character, which indicates the type of data to be converted and printed. A one-to-one correlation must exist between each specification encountered and each item in the item list. The available flags are: - Causes the data to be left-justified within its output field. Normally, the data is right-justified. + Causes all signed data to begin with a sign (+ or -). Normally, only negative values have signs.
HP C/iX Library Function Descriptions printf leading zeros. The default precision is 1. A null string results if a zero value is printed with a zero precision. The # flag has no effect. u An integer item is converted to unsigned decimal. The effects of the precision and the # flag are the same as for d. o An integer item is converted to unsigned octal. The # flag, if specified, causes the precision to be expanded, and the octal value is printed with a leading zero (a C convention).
HP C/iX Library Function Descriptions printf always contains exactly three digits. If the # flag is specified, the result always contains a decimal point, even if no digits follow the decimal point. E Same as e above, except that E is used to introduce the exponent instead of e (style E). g The float or double item is converted to either style f or style e, depending on the size of the exponent. If the exponent resulting from the conversion is less than -4 or greater than the precision, style e is used.
HP C/iX Library Function Descriptions printf main() { double x; printf("Enter your number: "); printf("Your number is %g\n", x); printf("Its square is %g\nIts cube is %g\n", x*x, x*x*x); } The g conversion character is used so that the decision about using an exponent is automatic. Note that the item list contains expressions to calculate x squared and x cubed.
HP C/iX Library Function Descriptions printf printf("O'%s, not %s.\n", last, last); } See Also fprintf(), vprintf(), sprintf(), putc(), setlocale(), scanf(), ANSI C 4.9.6.3, POSIX.1 8.
HP C/iX Library Function Descriptions printmsg printmsg Prints formatted output with numbered arguments to stdout. Syntax #include int printmsg (format [, arg] ...) char *format; Parameters format A pointer to the string containing the formatting information. It contains optional placeholders and formatting specifications where arg1 through argn are to be substituted. arg1 ...
HP C/iX Library Function Descriptions printmsg See Also printf(), fprintmsg(), sprintmsg() 278 Chapter 5
HP C/iX Library Function Descriptions putc putc Writes a character to an open stream. Syntax #include int putc (int c, FILE *stream); Parameters c A character to be written to an open stream. stream A pointer to an open stream. Return Values x The character written. EOF An error occurred, and errno is set to indicate the error condition. Description The putc function writes a single character to the specified stream.
HP C/iX Library Function Descriptions putchar putchar Writes a character to the standard output stream stdout. Syntax #include int putchar (int c); Parameters c A character to be written to stdout. Return Values x The character written to stdout. EOF An error occurred; errno is set to indicate the error condition. Description The putchar function writes a single character c to the standard output stream stdout. The putchar(c) function is equivalent to putc(c,stdout_ptr).
HP C/iX Library Function Descriptions puts puts Writes a string to the standard output stream stdout. Syntax #include int puts (const char *s); Parameters A pointer to a character array containing the string to be written to stdout. The character array must be terminated with a null character. s Return Values ≥0 Success. EOF An error occurred. Description The puts function writes the string from a character array pointed to by s to the standard output stream stdout.
HP C/iX Library Function Descriptions putw putw Writes a word to an open stream. Syntax #include int putw (int w, FILE *stream); Parameters w A word to be written to an open stream. stream A pointer to an open stream. Return Values 0 Indicates success. Non-zero An error occurred. Description The putw function writes the word (int in C) w to the output stream (at the position at which the file pointer, if defined, is pointing).
HP C/iX Library Function Descriptions qsort qsort Sorts an array of objects. Syntax #include void qsort (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *)); Parameters base A pointer to an array to be sorted. nmemb The number of elements in the array. size The size, in bytes, of each element of the array. compar A pointer to a user-written comparison function. Return Values None. Description The qsort function sorts an array of objects.
HP C/iX Library Function Descriptions raise raise Causes a signal to be raised. Syntax #include int raise (int sig); Parameters A signal number specifying the signal to be raised. sig Return Values 0 The signal was successfully raised. ≠0 The signal was not raised. Description The raise function causes the signal specified in sig to be raised to the calling process.
HP C/iX Library Function Descriptions rand rand Returns a random number. Syntax #include int rand (void); Parameters None. Return Values x A pseudo-random integer in the range 0 to RAND_MAX. The macro RAND_MAX expands to the value 32767. Description If the srand function is not used to initialize the random number generator to a particular starting point, rand() returns the same sequence of numbers every time the program is executed. See Also rand(), srand(), ANSI C 4.10.2.1, POSIX.1 8.
HP C/iX Library Function Descriptions rand48 rand48 The drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48, and lcong48 functions generate uniformly distributed pseudo-random numbers.
HP C/iX Library Function Descriptions rand48 Return Values x Random numbers appropriate to the type and function called (except seed, which returns a pointer to the internal buffer where X is stored). Description This family of functions generates uniform pseudo-random numbers using the linear congruential algorithm and 48-bit integer arithmetic. The drand48 and erand48 functions return non-negative double-precision floating-point values uniformly distributed over the interval of 0.0 (inclusive) to 1.
HP C/iX Library Function Descriptions rand48 times the functions have been called to generate numbers for the other streams. The initializer function srand48 sets the high-order 32 bits of Xi to the 32 bits contained in its argument. The low-order 16 bits of Xi are set to the arbitrary value 330E16. The initializer function seed48 sets the value of Xi to the 48-bit value specified in the argument array.
HP C/iX Library Function Descriptions read read Reads input from a file. Syntax int read (int fildes, char *buffer, unsigned nbyte); Parameters fildes An open file descriptor. buffer A pointer to a buffer where the function returns data. nbyte The number of bytes to read and place in buffer. Return Values >0 Indicates success and the number of bytes read. This number may be less than nbyte if: • The file is associated with a communication line.
HP C/iX Library Function Descriptions read See Also open(), write() 290 Chapter 5
HP C/iX Library Function Descriptions realloc realloc Changes the size of a block of allocated memory. Syntax #include void *realloc (void *ptr, size_t size); Parameters ptr A pointer to a block of memory previously allocated. size The new size, in bytes. Return Values x A successful call to realloc() returns a pointer to the possibly moved block of allocated memory. NULL There is not enough available memory. The block pointed to by ptr is left intact, or, size is 0.
HP C/iX Library Function Descriptions remove remove Purges an existing file. Syntax #include int remove (const char *filename); Parameters filename A pointer to a character array containing the name of a file to purge. The string must be terminated by a null character. Return Values 0 The file is successfully purged. −1 An error occurred and errno is set to one of the following values: ENOENT The file does not exist. ESYSERR A call to a system intrinsic failed.
HP C/iX Library Function Descriptions rename rename Renames an existing file. Syntax #include int rename (const char *oldname, const char *newname); Parameters oldname A pointer to a string containing the name of the existing file whose name is to be changed. The string must be terminated by a null character. newname A pointer to a string containing the new name of the file. The string must be terminated by a null character. Return Values 0 The file is successfully renamed.
HP C/iX Library Function Descriptions rewind rewind Sets the file position indicator for a stream to the beginning of the file. Syntax #include void rewind (FILE *stream); Parameters A pointer to an open stream. stream Return Values None. Description The rewind function sets the file position indicator for the specified stream to the beginning of the file.
HP C/iX Library Function Descriptions rewind } pswd = fopen(argv[1], "r"); if(pswd == NULL) { fprintf(stderr, "Can't open %s.\n", argv[1]); exit(1); } fgets(line, 256, pswd); if(line[0] == '*' line[1] == 'P') { /* ask for and check password */ } else rewind(pswd); /* application program goes here */ exit(0); } If the first two characters of the first line are "*P", the code that asks for and checks a password is executed.
HP C/iX Library Function Descriptions scanf scanf Reads externally formatted data from the standard input stream stdin. Syntax #include int scanf (const char *format [,item [,item]...] ); Parameters format A pointer to a character string defining the format of the data to be read (or the character string itself enclosed in double quotes). item Each item is the address of a variable into which the data will be placed.
HP C/iX Library Function Descriptions scanf followed by an integer value (called the field width). The conversion specification is terminated by a character specifying the type of data to expect; the terminating characters are called conversion characters. The integer and floating-point conversion characters may be optionally preceded by a character indicating the size of the receiving variable.
HP C/iX Library Function Descriptions scanf stream so far by this call to fscanf(). Matches a single %. No conversion or assignment occurs. The complete conversion specification is &%&% % Integer Conversion Characters The d, o, and x conversion characters read characters from stdin until an inappropriate character is encountered, or until the number of characters specified by the field width, if given, is exhausted (whichever comes first).
HP C/iX Library Function Descriptions scanf (Ten spaces followed by "Hello, there!"; the double quotes are added for clarity). If you use %c, you get a space character. However, if you use %1s, you get "H" (the first nonspace character in the input). The [ conversion character also reads a character string from stdin. However, you should use this character when a string is not to be delimited by space characters. The left bracket is followed by a list of characters, and is terminated by a right bracket.
HP C/iX Library Function Descriptions scanf ("NAME:"). To read the strings, first note that the identifying strings are always delimited by space characters. This suggests use of the s conversion character to read them. Second, you can never know the exact sizes of the NAME and PROF fields, but note that they are both terminated by a semicolon. Thus, you can use [ to read them. Finally, the d conversion character can be used to read both integers.
HP C/iX Library Function Descriptions scanf multiple spaces between items and varying identifying strings (that is, "PROFESSION:" could be specified instead of "PROF:"). The following scanf() call reads the same data, but is much less flexible: scanf("NAME: %[^;]; AGE:%d; PROF: %[^;]; SAL: %d",name,&age,prof,&salary); In this example, literal characters are used to exactly match the characters in the input line. This only works if you can be sure that the data always appears in this form.
HP C/iX Library Function Descriptions scanf character, in the array arr4. Note that there are some characters left in stdin that were not read. Any characters left unread in the input remain there, which might cause unexpected errors. Suppose that, later in the above program fragment, you want to read a string from stdin using %s.
HP C/iX Library Function Descriptions setbuf setbuf Assigns a buffer to an open stream. Syntax #include void setbuf (FILE *stream, char *buffer); Parameters stream A pointer to an open stream. buffer Either a pointer to a character array for buffered I/O, or null for unbuffered I/O. Return Values None. Description Normally, a standard I/O buffer is obtained through a call to malloc() on the first call to getc() or putc() (which all I/O functions eventually call).
HP C/iX Library Function Descriptions setbuf FILE *fp; char buffer[BUFSIZ]; fp = fopen(argv[1], "r"); … setbuf(fp, buffer); … This fragment shows the correct order of events. First, the file is opened, and the buffering is assigned using setbuf(). From that point on any input taken from fp is buffered through the array buffer.
HP C/iX Library Function Descriptions setjmp setjmp Saves the current environment. Syntax #include int setjmp (jmp_buf env); Parameters env An array of unsigned integers as defined by the type jmp_buf. Return Values 0 Successful completion of setjmp(). ≠0 Returned as a result of a call to longjmp(). The value returned is the value passed in the val parameter of longjmp(). Description The setjmp macro creates an entry point in your program that can be reached with longjmp().
HP C/iX Library Function Descriptions setkey setkey Defines the key used for encrypting blocks of text. Syntax void setkey (key) char *key; Parameters key A pointer to a character string that contains the encryption key. Return Values None. Description The setkey function provides primitive access to the hashing algorithm used by crypt(). It is used in conjunction with encrypt to first prime the machine and then encrypt a block of text.
HP C/iX Library Function Descriptions setlocale setlocale Controls locale-specific features of the library. Syntax #include char *setlocale (int category, const char *locale); Parameters category Specifies that only a certain aspect is to be set to that locale and the others are unchanged. This parameter can be set to any one of the following macros (defined in
HP C/iX Library Function Descriptions setlocale — If locale is not specified (an empty string is used), as in the following example, setlocale (category,"") the locale is set according to the following scheme: 1. If an equivalent 'LC_' environment variable is set, the language is set to the language specified by the variable. 2. If the environment variable LANG is set, the language is set as specified by LANG. 3.
HP C/iX Library Function Descriptions setvbuf setvbuf Assigns a buffer and buffering method to an open stream. Syntax #include int setvbuf (FILE *stream, char *buffer, int type, size_t size); Parameters stream A pointer to an open stream. buffer Either a pointer to a character array for buffered I/O, or null. type The method of buffering. size The size of the buffer. Return Values 0 Success. ≠0 An error occurred.
HP C/iX Library Function Descriptions setvbuf identical: setvbuf(fp, NULL, _IONBF, 0) setbuf(fp, NULL) When type is _IOFBF or _IOLBF, buffering for stream is determined by buffer and size. If buffer is not the null pointer, it must point to a character array of size bytes. All buffering of stream is then handled through this array.
HP C/iX Library Function Descriptions signal signal Specifies how a signal is to be handled. Syntax #include void (*signal (int sig, void (*func)(int)))(int); Parameters sig A signal number. func A pointer to the function that performs the exception handling. Return Values x If successful, the most recent value of func. SIG_ERR An error occurred; errno is set to a positive value. Description The signal function defines the actions to take when the specified signal is raised.
HP C/iX Library Function Descriptions signal expressions that have a type compatible with func, and whose values compare unequal with any declarable function. These macros cause signal() to behave as follows: SIG_DFL The default handling for that signal occurs. Usually this default action is to terminate the program with some message. SIG_IGN The signal is ignored when it is raised.
HP C/iX Library Function Descriptions signal raise(SIGSEGV); printf ("did not raise SIGSEGV\n"); } else { printf ("longjmp'ed back\n"); } printf ("about to raise SIGTERM\n"); if (raise (SIGTERM)) printf ("could not raise SIGTERM\n"); /* else it should not get here.. */ } void segv_handler (int sig) { printf ("Raised SIGSEGV: In handler\n"); longjmp (state0, 100); /* leap back */ } void goodbye (int sig) { printf ("Raised SIGTERM: In handler\n"); exit (0); } See Also raise(), exit(), abort(), ANSI C 4.7.1.
HP C/iX Library Function Descriptions sin sin Computes a sine value. Syntax #include double sin (double x); Parameters x A real number measured in radians. Return Value n The sine of x measured in radians. 0 Indicates a complete loss of significance for large values of x. A TLOSS error message is printed on the standard error output; errno is set to ERANGE. Description The sin function loses accuracy when its argument is far from zero.
HP C/iX Library Function Descriptions sinh sinh Calculates the hyperbolic sine of an angle. Syntax #include double sinh (double x); Parameters x A real number. Return Values n The hyperbolic sine of the given angle. ±HUGE_VAL An overflow condition has occurred for large absolute values of x; errno is set to ERANGE. Description Error-handling can be changed by a user-written matherr function. See Also cosh(), tanh(), sin(), matherr(), ANSI C 4.5.3.2, POSIX.1 8.
HP C/iX Library Function Descriptions sleep sleep Suspends program execution for an interval. Syntax unsigned long sleep (unsigned long seconds); Parameters The number of seconds to suspend program execution. seconds Return Values x The difference between the requested sleep time and the actual sleep time. Description The current process is suspended from execution for the number of seconds specified by the argument.
HP C/iX Library Function Descriptions sprintf sprintf Writes formatted data to a character string in memory. Syntax #include int sprintf (char *string, const char *format [,item [,item]...]); Parameters string A pointer to a buffer in memory where the data is to be written. format Pointer to a character string defining the format (or the character string itself enclosed in double quotes). item,… Each item is a variable or expression specifying the data to write.
HP C/iX Library Function Descriptions sprintf 2. Zero or more flags, which affect the way a value is written (see below). 3. An optional decimal digit string which specifies a minimum field width. 4. An optional precision consisting of a dot (.) followed by a decimal digit string. 5. An optional l, h, or L indicating that the argument is of an alternate type. When used in conjunction with an integer conversion character, an l or h indicates a long or short integer argument, respectively.
HP C/iX Library Function Descriptions sprintf Conversion Characters Conversion characters specify the type of data to expect in the item list and cause the data to be formatted and written appropriately. The integer conversion characters are: d, i An integer item is converted to signed decimal. The precision, if given, specifies the minimum number of digits to appear. If the value has fewer digits than that specified by the precision, the value is expanded with leading zeros. The default precision is 1.
HP C/iX Library Function Descriptions sprintf The float or double item is converted to scientific notation in style e; that is, in the form e [-]d.ddde±ddd where there is always one digit before the decimal point. The number of digits after the decimal point is equal to the precision. If no precision is given, six digits are written after the decimal point. If the precision is explicitly zero, the decimal point is eliminated entirely. The exponent always contains exactly three digits.
HP C/iX Library Function Descriptions sprintf { char name[31], prof[31], hdate[7], curve[3], string[81]; char *format = "%30s%2d%30s%6ld%6s%2d%2s"; int age, rank; long salary; /* start asking questions */ printf("\nName (30 chars max): "); gets(name); while(name[0] != ']') { printf("Age: "); printf("Job title (30 chars max): "); gets(prof); printf("Salary (6 digits max, no comma): "); printf("Hire date (numerical MMDDYY): "); gets(hdate); printf("Pay curve: "); gets(curve); /* format string */ sprintf(stri
HP C/iX Library Function Descriptions sprintmsg sprintmsg Prints formatted output with numbered arguments to a character array. Syntax int sprintmsg (char *s, char *format [, arg] ...) Parameters s A pointer to a character array where the output is directed format A pointer to the string containing the formatting information. It contains optional placeholders and formatting specifications where arg1 thru argn are to be substituted. arg1 ...
HP C/iX Library Function Descriptions sqrt sqrt Computes the square root of a number. Syntax #include double sqrt (double x); Parameters x A real number. Return Values n The square root of the real number. 0 The x parameter is negative; errno is set to EDOM. Description Error handling can be changed by a user-written matherr function. See Also pow(), matherr(), ANSI C 4.5.5.2, POSIX.1 8.
HP C/iX Library Function Descriptions srand srand Sets a starting point for subsequent calls to rand(). Syntax #include void srand (unsigned int seed); Parameters seed A value that sets the starting point for subsequent calls to the rand function. Return Values None. Description The srand function causes subsequent calls to rand() to return a new random sequence based on the value passed in seed.
HP C/iX Library Function Descriptions sscanf sscanf Reads formatted data from a character string in memory. Syntax #include int sscanf (const char *string, const char *format [,item [,item]...]); Parameters string A pointer to a buffer in memory containing the formatted data to be read. format A pointer to a character string defining the format of the data to be read (or the character string itself enclosed in double quotes).
HP C/iX Library Function Descriptions sscanf optionally followed by an asterisk (*) (called the assignment suppression character), optionally followed by an integer value (called the field width). The conversion specification is terminated by a character specifying the type of data to expect; the terminating characters are called conversion characters. The integer and floating-point conversion characters may be optionally preceded by a character indicating the size of the receiving variable.
HP C/iX Library Function Descriptions sscanf n No input is consumed. The corresponding argument is a pointer to an integer into which is written the number of characters read from the input stream so far by this call to fscanf(). % Matches a single %. No conversion or assignment occurs.
HP C/iX Library Function Descriptions sscanf character from the following input line: " Hello, there!" (Ten spaces followed by "Hello, there!"; the double quotes are added for clarity). If you use %c, you get a space character. However, if you use %1s, you get "H" (the first nonspace character in the input). The [ conversion character also reads a character string from string. However, you should use this character when a string is not to be delimited by space characters.
HP C/iX Library Function Descriptions sscanf Examples The following program reads a string from stdin, stores the string in the character array string, and prints the first word of the string. #include main() { char string[80], word[25], *gets(); /* get the string */ printf("Enter your string: "); gets(string); /* get the first word */ sscanf(string, "%s", word); printf("The first word is %s.
HP C/iX Library Function Descriptions sscanf while(n1 >= n2) n1 -= n2; printf("Answer: %ld\n\n", n1); } else printf("Can't recognize operator: %s\n\n", op); printf("> "); gets(line); } } The calculator program above accepts input lines having the form value operator value where value is any number, and operator is the symbol +, -, *, /, or %, representing addition, subtraction, multiplication, division, or remainder, respectively.
HP C/iX Library Function Descriptions strcat strcat Appends one string to another. Syntax #include char *strcat(char *s1, const char *s2); Parameters s1 and s2 Character pointers to null-terminated character strings. Return Values x The value of s1. Description The strcat function appends the entire string pointed to by s2 including the terminating null character onto the end of string s1. The first character of s2 overwrites the terminating null character of s1.
HP C/iX Library Function Descriptions strchr strchr Locates the first occurrence of a specified character within a string. Syntax #include char *strchr(const char *s, int c); Parameters s A pointer to a null-terminated character string. c The value to find in the target string. Return Values x A character pointer to the first occurrence of c in string s. NULL The character is not found.
HP C/iX Library Function Descriptions strcmp strcmp Compares two strings and returns an integer indicating the result of the comparison. Syntax #include int strcmp(const char *s1, const char *s2); Parameters s1, s2 Pointers to character strings. Return Values <0 The s1 parameter is less than s2 =0 The s1 and s2 parameters are equal. >0 The s1 parameter is greater than s2.
HP C/iX Library Function Descriptions strcoll strcoll Compares two strings, interpreting them as appropriate for the current locale. This function is generally used in conjunction with Native Language Support (NLS). Syntax #include int strcoll(const char *s1, const char *s2); Parameters s1 A pointer to the first string. s2 A pointer to the second string. Return Values >0 The s1 parameter is greater than s2. =0 The s1 parameter is equal to s2. <0 The s1 parameter is less than s2.
HP C/iX Library Function Descriptions strcpy strcpy Copies the contents of s2 into s1. Syntax #include char *strcpy(char *s1, const char *s2); Parameters s1 A pointer to the target string. s2 A pointer to the source string. Return Values x The value of s1. Description In the strcpy function, s2 is a character pointer to the string to be copied, and s1 is a character pointer to the beginning of the string into which the contents of string s2 are copied.
HP C/iX Library Function Descriptions strcpy character early in the program. The first chr element is then successively set to the next lowercase character in the for loop, and the resulting two-character string is concatenated onto the end of the alphabet assembled so far in alpha. Note the use of strcpy() to initialize alpha. Remember that C transforms one or more characters enclosed in double quotation marks into a character pointer to those characters followed by a null character.
HP C/iX Library Function Descriptions strcspn strcspn Returns the length of the first substring in s1 composed entirely of non-members of the character set s2. Syntax #include size_t strcspn(const char *s1, const char *s2); Parameters s1 A pointer to a character string to search. s2 A pointer to a character string defining the character set. Return Values x The length of the initial segment in s1 formed by characters not in s2.
HP C/iX Library Function Descriptions strerror strerror Maps an error number to a message string. Syntax #include char *strerror(int errnum); Parameters errnum An error number. Return Values x A pointer to the error message. NULL A null pointer is returned if there is no matching error message. Description The strerror function returns a pointer to an error message that corresponds with the specified error number.
HP C/iX Library Function Descriptions strftime strftime Creates a formatted time string. Syntax #include size_t strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr); Parameters s A pointer to a character array to which the function returns a formatted character string. maxsize The size of the character array. format A pointer to an array containing conversion specifications and ordinary multibyte characters to be inserted the string.
HP C/iX Library Function Descriptions strftime • %c is replaced by the locale's appropriate date and time representation. • %d is replaced by the day of the month as a decimal number (01-31). • %e is replaced by the day of the month as a decimal number (1-31 in a two-digit right-justified field with leading space> fill). • %H is replaced by the hour (24-hour clock) as a decimal number (00-23). • %I is replaced by the hour (12-hour clock) as a decimal number (01-12).
HP C/iX Library Function Descriptions strlen strlen Computes the length of the string pointed to by s. Syntax #include size_t strlen(const char *s); Parameters A pointer to the character string. s Return Values x The length of the string specified as an unsigned integer. Description In the strlen function, s is a character pointer to the null-terminated string to be scanned. strlen() counts up to, but not including, the terminating null character.
HP C/iX Library Function Descriptions strncat strncat Appends a copy of string 2 to string 1. Syntax #include char *strncat(char *s1, const char *s2, size_t n); Parameters s1 A pointer to a destination. s2 A pointer to a null-terminated source character string. n The maximum number of characters to concatenate from s2 to s1, unless strncat() first encounters a null terminator in s2. Return Values x The address of s1.
HP C/iX Library Function Descriptions strncmp strncmp Compares two strings up to a maximum of n characters and returns an integer result of the comparison. Syntax #include int strncmp(const char *s1, const char *s2, size_t n); Parameters s1, s2 Pointers to character strings. n Specifies the maximum number of characters to compare in both s1 and s2. Return Values <0 s1 is less than s2. =0 s1 and s2 are equal. >0 s1 is greater than s2.
HP C/iX Library Function Descriptions strncmp exit(2); } fp = fopen(argv[1], "r"); if(fp == NULL) { fprintf(stderr, "Can't open %s.\n", argv[1]); exit(1); } while(fgets(line, 100, fp) != NULL) { if(strncmp(line, ".SH", 3) == 0) else if(strncmp(line, ".PP", 3) == 0) else if(strncmp(line, ".TP", 3) == 0) else if(strncmp(line, ".RS", 3) == 0) else if(strncmp(line, ".RE", 3) == 0) else if(strncmp(line, ".PD", 3) == 0) else if(strncmp(line, ".IP", 3) == 0) else if(line[0] == '.') } printf("No. printf("No.
HP C/iX Library Function Descriptions strncpy strncpy Copies all or part of s2 into s1. Syntax #include char *strncpy(char *s1, const char *s2, size_t n); Parameters s1 A pointer to a destination. s2 A pointer to a null-terminated source character string. n The maximum number of characters to copy from s2 to s1. Return Values x The address of s1.
HP C/iX Library Function Descriptions strpbrk strpbrk Returns a pointer to the location in s1 of the first occurrence of any member of the character set s2. Syntax #include char *strpbrk(const char *s1, const char *s2); Parameters s1 A pointer to a null-terminated character string to be searched. s2 A pointer to a null-terminated character string containing a character set. Return Values x A character pointer to the first occurrence of a character from s2 in string s1.
HP C/iX Library Function Descriptions strpbrk passed to sscanf(), which interprets ptr as if it were a pointer to the beginning of a string from which input is to be taken. The number is read correctly because ptr points to the beginning of a number, and because the f conversion terminates at the first inappropriate character. See Also strchr(), strrchr(), ANSI C 4.11.5.4, POSIX.1 8.
HP C/iX Library Function Descriptions strrchr strrchr Locates the last occurrence of a supplied character within a string. Syntax #include char *strrchr(const char *s, int c); Parameters s A pointer to a null-terminated character string. c The value to find in the target string. Return Values x A character pointer to the last occurrence of c in string s. This function returns a null pointer if the character is not found.
HP C/iX Library Function Descriptions strspn strspn Returns the length of the first substring in s1 composed entirely of members of the character set s2. Syntax #include size_t strspn(const char *s1, const char *s2); Parameters s1 A pointer to a null-terminated character string to be searched. s2 A pointer to a null-terminated character string containing a character set. Return Values x The length of the initial segment in s1 formed by characters found in the s2 character set.
HP C/iX Library Function Descriptions strstr strstr Locates the first occurrence in one string of the sequence of characters specified by another string. Syntax #include char *strstr(const char *s1, const char *s2); Parameters s1 A pointer to the character string to search. s2 A pointer to the character string with the search value. Return Values x A pointer to the string found in s1. If s2 is null, the value of s1 is returned. NULL The s2 was not found in s1.
HP C/iX Library Function Descriptions strtod strtod Converts a string to a double-precision, floating-point number. Syntax #include double strtod (const char *str, char **ptr); Parameters str A pointer to a character string to be converted. ptr If ptr is not NULL, a pointer to the character terminating the scan is stored in the object pointed to by ptr. Return Values x A double-precision floating-point number resulting from the successful conversion of the string.
HP C/iX Library Function Descriptions strtod See Also strtol(), strtoul(), atof(), ANSI C 4.10.1.
HP C/iX Library Function Descriptions strtok strtok Divides string s1 into zero or more tokens. The token separators consist of any characters contained in string s2. Syntax #include char *strtok(char *s1, const char *s2); Parameters s1 A pointer to a string with zero or more tokens. s2 A pointer to a character string with token delimiters. Return Values x A pointer to the first character of a token. NULL No token found.
HP C/iX Library Function Descriptions strtok arg1 = NULL; } This code sees to it that strtok()'s first argument is null after the first call. Also, note that delims did not change from call to call, but it could have. This greatly increases the power of strtok, because it enables you to change the token delimiters between calls. See Also ANSI C 4.11.5.8, POSIX.1 8.
HP C/iX Library Function Descriptions strtol strtol Converts a string to a long integer value. Syntax #include long strtol (const char *str, char **ptr, int base); Parameters str A pointer to a character string to be converted. If base is set to zero, leading characters in str define the conversion. After an optional leading sign, a leading zero indicates octal conversion, and a leading "0x" or "0X" indicates hexadecimal conversion. Otherwise, decimal conversion is used.
HP C/iX Library Function Descriptions strtoul strtoul Converts a string to an unsigned long int representation. Syntax #include unsigned long int strtoul (const char *str, char **ptr, int base); Parameters str A pointer to a character string to be converted. If base is set to zero, leading characters in str define the conversion. After an optional leading sign, a leading zero indicates octal conversion, and a leading "0x" or "0X" indicates hexadecimal conversion.
HP C/iX Library Function Descriptions strxfrm strxfrm Transforms a string in a manner appropriate for the current locale. Syntax #include size_t strxfrm(char *s1, const char *s2, size_t n); Parameters s1 A string pointer to the destination string. s2 A string pointer to a null-terminated source string. n The maximum number of characters to transform, including the terminating null character.
HP C/iX Library Function Descriptions swab swab Swaps bytes in an array. Syntax void swab (char *from, char *to, int nbytes); Parameters from A pointer to the source array. to A pointer to the target array. nbytes The number of bytes to copy. Return Values None. Description This function copies nbytes bytes pointed to by from to the array pointed to by to, exchanging adjacent even and odd bytes. It is useful for carrying binary data between byte-swapped and non-byte-swapped machines.
HP C/iX Library Function Descriptions system system Executes an MPE/iX command. Syntax #include int system (const char *string); Parameters string A pointer to a string containing an MPE/iX command. Return Values 0 Success. <0 An error occurred. The value returned is the negated value of the error code returned by the HPCICOMMAND intrinsic. >0 A warning occurred. Description The system function executes an MPE/iX command pointed to by string.
HP C/iX Library Function Descriptions tan tan Computes a tangent value. Syntax #include double tan (double x) Parameters x A real number giving the angle measured in radians. Return Values n The tangent of the angle. 0 Indicates a complete loss of accuracy for large values of x. A TLOSS error message is printed on the standard error output. errno is set to ERANGE. Description The tan function returns the tangent of its argument x, measured in radians.
HP C/iX Library Function Descriptions tanh tanh Computes the hyperbolic tangent value for a given angle. Syntax #include double tanh (double x); Parameters x A real number giving the angle measured in radians. Return Values n The hyperbolic tangent of the angle. Description This function returns the hyperbolic tangent of its argument (x) in radians. See Also sin(), cos(), ANSI C 4.5.3.3, POSIX.1 8.
HP C/iX Library Function Descriptions tdelete tdelete Deletes a specified node from a binary search tree. Syntax #include void *tdelete (void *key, void **rootp, int (*compar)()); Parameters key A pointer to an item to be searched for and deleted. rootp A pointer to the variable at the root of the tree. compar A pointer to a comparison function supplied by the user. Return Values x A pointer to the parent node of the deleted entry. NULL Entry not found or rootp is NULL on entry.
HP C/iX Library Function Descriptions tdelete If the calling function alters the pointer to the root, results are unpredictable. NOTE The tdelete function and the header file are not part of ANSI C. Using them may make your program less portable. Examples Refer to the example located in the tsearch() function description.
HP C/iX Library Function Descriptions tfind tfind Searches for a specified entry in a binary search tree. Syntax #include void *tfind (void *key, void **rootp, int (*compar)()); Parameters key A pointer to an item to be searched for. If there is an item in the tree equal to *key (the value pointed to by key), a pointer to the item found is returned. Otherwise, a null pointer is returned. Only pointers are copied, so the calling function must store the data.
HP C/iX Library Function Descriptions tfind NOTE The tfind function and the header file are not part of ANSI C. Using them may make your program less portable. Examples Refer to the example located in the tsearch function description.
HP C/iX Library Function Descriptions time time Returns the current calendar time. Syntax #include time_t time (time_t *timer); Parameters If not NULL, a pointer to where the returned time is stored. timer Return Values x Specifies the time elapsed seconds since the Epoch (00:00:00 Coordinated Universal Time, January 1, 1970). 0 An error occurred and errno is set to EFAULT.
HP C/iX Library Function Descriptions tmpfile tmpfile Creates a temporary file. Syntax #include FILE *tmpfile (void); Parameters None. Return Values x A pointer to a stream associated with the temporary file. NULL The file cannot be opened. Description The tmpfile function creates a temporary file using a name generated by tmpnam() and returns a pointer to the resulting stream. The file is automatically deleted when the process using it terminates.
HP C/iX Library Function Descriptions tmpnam tmpnam Creates a name for a temporary file. Syntax #include char *tmpnam (char *s); Parameters s Either NULL or a pointer to an array of at least L_tmpnam bytes, where L_tmpnam is a constant defined in stdio.h>. Return Values x If s is NULL, a pointer to a static buffer which contains a file name. If s is not NULL, the value of the argument s. Description The tmpnam function generates a file name that can safely be used as a temporary file.
HP C/iX Library Function Descriptions toascii toascii Converts an integer to 7-bit ASCII. Syntax #include int toascii (int c); Parameters c The integer to convert to ASCII. Return Values x Is returned with all bits turned off that are not part of the standard 7-bit ASCII character. Description The toascii function returns its argument with all bits turned off that are not part of a standard 7-bit ASCII character. It is intended for compatibility with other systems.
HP C/iX Library Function Descriptions tolower, _tolower tolower, _tolower Converts an uppercase letter to lowercase. Syntax #include int tolower (int c); Parameters An argument to be converted to lowercase. c Return Values x The lowercase letter that corresponds with c. If c is not an uppercase letter and the function is called, c is returned unchanged. If c is not an uppercase letter and the macro is called, the results are undefined.
HP C/iX Library Function Descriptions toupper, _toupper toupper, _toupper Converts a lowercase letter to uppercase. Syntax #include int toupper (int c); Parameters An argument to be converted to uppercase. c Return Values x The uppercase letter that corresponds with c. If c is not a lowercase letter and the function is called, c is returned unchanged. If c is not a lowercase letter and the macro is called, the results are undefined.
HP C/iX Library Function Descriptions tsearch tsearch Builds and provides access to a binary search tree. Syntax #include void *tsearch (void *key, void **rootp, int (*compar)()); Parameters key A pointer to an item to be accessed or stored. rootp A pointer to a variable that points to the root of the tree. compar A pointer to a comparison function supplied by the programmer. Return Values x A pointer to the value pointed to by key.
HP C/iX Library Function Descriptions tsearch NOTE The tsearch() function and the header file are not part of ANSI C. Using them makes your program less portable. Examples The following code reads in strings and stores structures containing a pointer to each string and a count of its length. It then walks the tree, printing out the stored strings and their lengths in alphabetical order. #include #include
HP C/iX Library Function Descriptions tsearch return strcmp(node1->string, node2->string); } /* This function prints out a node, the first time twalk encounters it.
HP C/iX Library Function Descriptions twalk twalk Traverses a binary search tree and returns the value at the specified node. Syntax #include void *twalk (void *root, void *(action)( )); Parameters root A pointer to the starting node for the tree traversal. action The name of a user-supplied function to be invoked at each node. Return Values None. Description The twalk function performs a depth-first, left-to-right traversal of a binary search tree.
HP C/iX Library Function Descriptions twalk a node before any of its children, after its left child and before its right, and after both its children. The alternate nomenclature uses preorder, inorder, and postorder to refer to the same visits, which results in some confusion over the meaning of postorder. The third argument is the level of the node in the tree, with the root being level zero. NOTE The twalk function and the header file are not part of ANSI C.
HP C/iX Library Function Descriptions tzset tzset Sets time zone conversion information. Syntax #include /* proto */ void tzset (void); Parameters None. Return Values None. Description The tzset function uses the value of the user-defined environment variable TZ to set time conversion information used by localtime(), ctime(), strftime(), and mktime().
HP C/iX Library Function Descriptions ungetc ungetc Pushes back a single character onto an open stream. Syntax #include int ungetc (int c, FILE *stream); Parameters c A single character to push back. stream A pointer to an open stream. Return Values x The value of the argument c, indicating success. EOF An error occurred. Description The ungetc function pushes the character specified by c (converted to an unsigned char) back onto the input stream pointed to by stream.
HP C/iX Library Function Descriptions ungetc of the comparison. #include main() { int c1, c2; c1 = getchar(); ungetc(c1, stdin); c2 = getchar(); if(c1 == c2) printf("They're the same!\n"); else printf("Oops! They're different!\n"); } At least one character may be pushed back if data has been read from the stream prior to the push-back attempt and if the stream is buffered.
HP C/iX Library Function Descriptions va_arg va_arg Initializes a variable to the beginning of an argument list. Syntax #include type va_arg (va_list ap, type); Parameters ap A pointer to a double, as defined by type va_list in . This variable must be initialized with the macro va_start. type A data type, either built-in or user-defined. Return Values x The value of the next argument in the call, returned as a variable of type type.
HP C/iX Library Function Descriptions va_arg Examples Refer to the example located in the va_start macro description. See Also va_start, va_end, ANSI C 4.8.1.
HP C/iX Library Function Descriptions va_end va_end Terminates access to a variable argument list. Syntax #include void va_end (va_list ap); Parameters A pointer to a double, as defined by type va_list in . This variable must be initialized with the macro va_start. ap Return Values None. Description The va_end macro terminates access to the variable argument list by making ap unusable. It must be called at the end of accessing the variable argument list.
HP C/iX Library Function Descriptions va_start va_start Initializes a variable to the beginning of an argument list. Syntax #include void va_start (va_list ap, parmN); Parameters ap A pointer to a double, as defined by type va_list in . parmN The identifier of the rightmost parameter in the variable parameter list in the function definition. This is the identifier just before the horizontal ellipsis. Return Values None.
HP C/iX Library Function Descriptions va_start char c; double d; printf ("arg count = %d\n", a1); if (a2 == VAR_LIST_PRESENT) { /* Initialize the varargs mechanism */ va_start(ap, a2); /* pass a2 as an anchor */ /* pick up all the arguments */ do { /* get the type of the argument */ ptype = va_arg (ap, enum argtype); /* retrieve the argument based on the type */ switch (ptype) { case CHAR: c = va_arg (ap, char); printf ("char = %c\n", c); break; case DOUB: d = va_arg (ap, double); printf ("double = %f\n", d
HP C/iX Library Function Descriptions va_start See Also va_arg, va_end, ANSI C 4.8.1.
HP C/iX Library Function Descriptions vfprintf vfprintf Writes data in formatted form to an open stream using a variable argument list. Syntax #include #include int vfprintf (FILE *stream, const char *format, va_list arg); Parameters stream A pointer to an open stream where data is to be written. format A pointer to a character string defining the format (or the character string itself enclosed in double quotes).
HP C/iX Library Function Descriptions vfprintf 4. An optional precision consisting of a dot (.) followed by a decimal digit string. 5. An optional l, h, or L indicating that the argument is of an alternate type. When used in conjunction with an integer conversion character, an l or h indicates a long or short integer argument, respectively. When used in conjunction with a floating-point conversion character, an L indicates a long double argument. 6.
HP C/iX Library Function Descriptions vfprintf Conversion Characters Conversion characters specify the type of data to expect in the item list and cause the data to be formatted and printed appropriately. The integer conversion characters are: d, i An integer item is converted to signed decimal. The precision, if given, specifies the minimum number of digits to appear. If the value has fewer digits than that specified by the precision, the value is expanded with leading zeros. The default precision is 1.
HP C/iX Library Function Descriptions vfprintf e The float or double item is converted to scientific notation in style e; that is, in the form [-]d.ddde±ddd where there is always one digit before the decimal point. The number of digits after the decimal point is equal to the precision. If precision is not given, six digits are written after the decimal point. If the precision is explicitly zero, the decimal point is eliminated entirely. The exponent always contains exactly three digits.
HP C/iX Library Function Descriptions vprintf vprintf Writes data in formatted form to the standard output stream stdout using a variable argument list. Syntax #include #include int vprintf (const char *format, va_list arg); Parameters format A pointer to a character string defining the format (or the character string itself enclosed in double quotes). arg A variable argument list initialized by va_start() (defined in the header .
HP C/iX Library Function Descriptions vprintf 5. An optional l, h, or L indicating that the argument is of an alternate type. When used in conjunction with an integer conversion character, an l or h indicates a long or short integer argument, respectively. When used in conjunction with a floating-point conversion character, an L indicates a long double argument. 6. A conversion character, which indicates the type of data to be converted and printed.
HP C/iX Library Function Descriptions vprintf to be formatted and printed appropriately. The integer conversion characters are: d, i An integer item is converted to signed decimal. The precision, if given, specifies the minimum number of digits to appear. If the value has fewer digits than that specified by the precision, the value is expanded with leading zeros. The default precision is 1. A null string results if a zero value is printed with a zero precision. The # flag has no effect.
HP C/iX Library Function Descriptions vprintf that is, in the form [-]d.ddde±ddd where there is always one digit before the decimal point. The number of digits after the decimal point is equal to the precision. If no precision is given, six digits are printed after the decimal point. If the precision is explicitly zero, the decimal point is eliminated entirely. The exponent always contains exactly three digits.
HP C/iX Library Function Descriptions vsprintf vsprintf Writes formatted data to a character string in memory using a variable argument list. Syntax #include #include int vsprintf (char *string, const char *format, va_list arg); Parameters string A pointer to a buffer in memory where the data is to be written. format A pointer to a character string defining the format (or the character string itself enclosed in double quotes).
HP C/iX Library Function Descriptions vsprintf 5. An optional l, h, or L, indicating that the argument is of an alternate type. When used in conjunction with an integer conversion character, an l or h indicates a long or short integer argument, respectively. When used in conjunction with a floating-point conversion character, an L indicates a long double argument. 6. A conversion character, which indicates the type of data to be converted and written.
HP C/iX Library Function Descriptions vsprintf to be formatted and written appropriately. The integer conversion characters are: d An integer item is converted to signed decimal. The precision, if given, specifies the minimum number of digits to appear. If the value has fewer digits than that specified by the precision, the value is expanded with leading zeros. The default precision is 1. A null string results if a zero value is written with a zero precision. The # flag has no effect.
HP C/iX Library Function Descriptions vsprintf where there is always one digit before the decimal point. The number of digits after the decimal point is equal to the precision. If precision is not given, six digits are written after the decimal point. If the precision is explicitly zero, the decimal point is eliminated entirely. The exponent always contains exactly three digits. If the # flag is specified, the result always contains a decimal point, even if no digits follow the decimal point.
HP C/iX Library Function Descriptions wcstombs wcstombs Converts a sequence of wide character codes to a sequence of multibyte characters. Syntax #include size_t wcstombs(char *s, const wchar_t *pwcs, size_t n); Parameters s A pointer to a character array to which the converted multibyte characters are returned. pwcs A pointer to the sequence of wide characters to be converted. n A variable of type size_t indicating the maximum number of bytes to return.
HP C/iX Library Function Descriptions wctomb wctomb Converts a single wide character value to its multibyte character representation. Syntax #include int wctomb(char *s, wchar_t wchar); Parameters s A pointer to a character array to which the multibyte character is returned. wchar The wide character value to be converted. Return Values >0 The length of the multibyte character in bytes. −1 The wchar parameter does not point to a valid wide character.
HP C/iX Library Function Descriptions write write Writes data to a file. Syntax int write (int fildes, char *buffer, unsigned nbyte); Parameters fildes The file descriptor of the file to write to. buffer A pointer to a buffer containing data to write. nbyte The number of bytes to write. Return Values ≥0 The number of bytes written. −1 An error occurred.
HP C/iX Library Function Descriptions write See Also read(), open() Chapter 5 401
HP C/iX Library Function Descriptions write 402 Chapter 5
Time Zones A Time Zones This appendix contains a list of commonly used time zones and the TZ environment variable strings that correspond to these time zones. The TZ strings are used by the time and date library functions for adjustment to specific time zones. Refer to the description of the ctime function in chapter 5 for details. The first line of each entry contains the time zone name followed by the Daylight Savings Time zone name, if appropriate.
Time Zones Canada: Manitoba, Ontario (parts), Saskatchewan (parts). CST6CDT - Canada Central Standard Time, Central Daylight Time United States: Alabama, Arkansas, Florida (parts), Illinois, Iowa, Kansas, Kentucky (parts), Louisiana, Michigan (parts), Minnesota, Mississippi, Missouri, Nebraska, North Dakota, Oklahoma, South Dakota, Tennessee (parts), Texas, Wisconsin.
Time Zones Middle European Time, Middle European Time Daylight Savings Time Belgium, Luxembourg, Netherlands, Denmark, Norway, Austria, Poland, Czechoslovakia, Sweden, Switzerland, DDR, DBR, France, Spain, Hungary, Italy, Yugoslavia MET-1METDST South Africa Standard Time, South Africa Daylight Time SAST-2SADT Japan Standard Time Japan JST-9 Australian Western Standard Time Australia: Western Australia WST-8:00 Australian Central Standard Time Australia: Northern Territory CST-9:30 Australian Central Standa
Time Zones TZTAB Time Zone Adjustment Table TZTAB Time Zone Adjustment Table The differences between Coordinated Universal Time (UTC) and local time are described in table form in the file TZTAB.LIB.SYS. This table can be used in conjunction with historical information to represent several local areas simultaneously. This file is also used by mktime() to compute the UTC from the local time. The TZTAB file contains one or more time zone adjustment entries.
Time Zones TZTAB Time Zone Adjustment Table tzname An alphabetic string containing the time zone name or abbreviation. The tzname value must match either the tzname field in the first line of the time zone adjustment entry or the dstzname field in the first line of the entry. diff The difference in hours from GMT. Any fractional value of diff is shown in minutes. Comments are allowed within time zone adjustment entries. They begin with a pound sign (#) and include all characters up to a new line.
Restrictions and Special Considerations Identifier Names B Restrictions and Special Considerations This appendix addresses restrictions and considerations that are not in the range of this manual. Identifier Names Function names beginning with an underscore (_) are reserved for library use. Therefore, you should not specify identifiers that begin with an underscore.
Restrictions and Special Considerations Mixed I/O from the C System and Other Systems to an output routine is made, you must call the fflush function immediately after the call or change the buffering scheme for the stdout and stderr streams to completely unbuffered or line buffered by calling the C library function setvbuf. Refer to the description of the setvbuf function in chapter 5 for details.
System-Dependent Information C System-Dependent Information This appendix briefly summarizes the differences between the HP C/iX library as it is implemented on HP 3000 Series 900 computers and HP 9000 Series 700/800 computers. Because the HP 9000 Series 700/800 are UNIX-based systems, the summary of differences given will usually apply to other UNIX-based systems as well. Refer to chapter 5 for detailed descriptions of the HP C/iX library functions.
System-Dependent Information current process identification number. HP 3000 Series 900: The string of X's in the argument to mktemp are replaced by a randomly generated number. open HP 9000 Series 700/800: The following options are available: O_NDELAY: This option controls whether a process blocks on an I/O request until the request is completed. O_EXCL: If O_EXCL and O_CREAT are set, open() fails if the file exists.
System-Dependent Information HP 3000 Series 900: The sleep function is implemented by calling the PAUSE intrinsic. Signals will not interfere with the amount of time slept. Sleep returns its argument if an error occurs, zero if no error occurs. Seconds must be less than 2,147,485. write HP 9000 Series 700/800: If a write requests more bytes to be written than there is room for, the write fails and -1 is returned.