3.3.14. Library functions

The precise attributes of a C library are specific to a particular implementation of it. The generic ARM C library has or supports the following features:

The following functions usually test only for characters whose values are in the range 0 to 127 (inclusive):

Characters with values greater than 127 return a result of 0 for all these functions except iscntrl() which returns non-zero for 0 to 31, and 128 to 255.

Setlocale call

After the call setlocale(LC_CTYPE, "ISO8859-1"), the statements in Table 3.4 apply to character codes and affect the results returned by the ctype() functions:

Table 3.4. Character codes

CodeDescription
128 to 159control characters
160 to 191punctuation
192 to 214uppercase
215punctuation
216 to 223uppercase
224 to 246lowercase
247punctuation
248 to 255lowercase

Mathematical functions

The mathematical functions return the values in Table 3.5.

Table 3.5. Mathematical functions

FunctionConditionReturned value
log(x)x <= 0–HUGE_VAL
log10(x)x <= 0–HUGE_VAL
sqrt(x)x < 0–HUGE_VAL
atan2(x,y)x = y = 0–HUGE_VAL
asin(x)

abs(x) > 1

–HUGE_VAL

acos(x)

abs(x) > 1

–HUGE_VAL

pow(x,y)

x=y=0

–HUGE_VAL

Where –HUGE_VAL is returned, a number is returned which is defined in the header math.h. Consult the errno variable for the error number.

The mathematical functions set errno to ERANGE on underflow range errors.

A domain error occurs if the second argument of fmod() is zero, and –HUGE_VAL is returned.

Signal function

The set of signals for the generic signal() function shown in Table 3.6.

Table 3.6. Signal function signals

SignalDescription

SIGABRT

abort

SIGFPE

arithmetic exception

SIGILL

illegal instruction

SIGINT

attention request from user

SIGSEGV

bad memory access

SIGTERM

termination request

SIGSTAK

stack overflow

The default handling of all recognized signals is to print a diagnostic message and call exit(). This default behavior applies at program startup.

When a signal occurs, if func points to a function, the equivalent of signal(sig, SIG_DFL) is first executed. If the SIGILL signal is received by a handler specified to the signal() function, the default handling is reset.

Generic ARM C library

The generic ARM C library also has the following characteristics relating to I/O. Note that a given targeting of the ARM C library may not have the same characteristics:

  • The last line of a text stream does not require a terminating newline character.

  • Space characters written out to a text stream immediately before a newline character do appear when read back in.

  • No null characters are appended to a binary output stream.

  • The file position indicator of an append mode stream is initially placed at the end of the file.

  • A write to a text stream does not cause the associated file to be truncated beyond that point (device dependent).

  • The characteristics of file buffering are as intended by section 4.9.3 of the ANSI C standard. The maximum number of open files is set in stdio.h as:


    #define _SYS_OPEN 16

    if Angel is in use.

  • A zero-length file (in which no characters have been written by an output stream) does exist.

  • The same file can be opened many times for reading, but only once for writing or updating. A file cannot be open simultaneously for reading on one stream and for writing or updating on another.

  • Local time zones and Daylight Saving Time are not implemented. The values returned will always indicate that the information is not available.

  • The status returned by exit() is the same value that was passed to it. For definitions of EXIT_SUCCESS and EXIT_FAILURE, refer to the header file stdlib.h.

  • The error messages returned by the strerror() function are identical to those given by the perror() function.

  • If the size of area requested is zero, calloc(), malloc() and realloc() return NULL.

  • abort() closes all open files, and deletes all temporary files.

  • fprintf() prints %p arguments in hexadecimal format (lowercase) as if a precision of 8 had been specified. If the variant form (%#p) is used, the number is preceded by the character @.

  • fscanf() treats %p arguments identically to %x arguments.

  • fscanf() always treats the character "-" in a %...[...] argument as a literal character.

  • ftell() and fgetpos() set errno to the value of EDOM on failure.

  • perror() generates the messages in Table 3.7.

    Table 3.7. perror() messages

    ErrorMessage
    0No error (errno = 0)
    EDOM

    EDOM - function argument out of range

    ERANGE

    ERANGE - function result not representable

    ESIGNUM

    ESIGNUM - illegal signal number to signal() or raise()

    others

    Error code number has no associated message

The following characteristics, required to be specified in an ANSI-compliant implementation, are unspecified in the generic ARM C library:

  • the validity of a filename

  • whether remove() can remove an open file

  • the effect of calling the rename() function when the new name already exists

  • the effect of calling getenv() (the default is to return NULL, no value available)

  • the effect of calling system()

  • the value returned by clock().

Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0041C