Skip Navigation Links | |
Exit Print View | |
man pages section 3: Basic Library Functions Oracle Solaris 11.1 Information Library |
enable_extended_FILE_stdio(3C)
posix_spawnattr_getschedparam(3C)
posix_spawnattr_getschedpolicy(3C)
posix_spawnattr_getsigdefault(3C)
posix_spawnattr_getsigignore_np(3C)
posix_spawnattr_getsigmask(3C)
posix_spawnattr_setschedparam(3C)
posix_spawnattr_setschedpolicy(3C)
posix_spawnattr_setsigdefault(3C)
posix_spawnattr_setsigignore_np(3C)
posix_spawnattr_setsigmask(3C)
posix_spawn_file_actions_addclose(3C)
posix_spawn_file_actions_addclosefrom_np(3C)
posix_spawn_file_actions_adddup2(3C)
posix_spawn_file_actions_addopen(3C)
posix_spawn_file_actions_destroy(3C)
posix_spawn_file_actions_init(3C)
pthread_attr_getdetachstate(3C)
pthread_attr_getinheritsched(3C)
pthread_attr_getschedparam(3C)
pthread_attr_getschedpolicy(3C)
pthread_attr_setdetachstate(3C)
pthread_attr_setinheritsched(3C)
pthread_attr_setschedparam(3C)
pthread_attr_setschedpolicy(3C)
pthread_barrierattr_destroy(3C)
pthread_barrierattr_getpshared(3C)
pthread_barrierattr_setpshared(3C)
pthread_condattr_getpshared(3C)
pthread_condattr_setpshared(3C)
pthread_cond_reltimedwait_np(3C)
pthread_key_create_once_np(3C)
pthread_mutexattr_getprioceiling(3C)
pthread_mutexattr_getprotocol(3C)
pthread_mutexattr_getpshared(3C)
pthread_mutexattr_getrobust(3C)
pthread_mutexattr_setprioceiling(3C)
pthread_mutexattr_setprotocol(3C)
pthread_mutexattr_setpshared(3C)
pthread_mutexattr_setrobust(3C)
pthread_mutex_getprioceiling(3C)
pthread_mutex_reltimedlock_np(3C)
pthread_mutex_setprioceiling(3C)
pthread_rwlockattr_destroy(3C)
pthread_rwlockattr_getpshared(3C)
pthread_rwlockattr_setpshared(3C)
pthread_rwlock_reltimedrdlock_np(3C)
pthread_rwlock_reltimedwrlock_np(3C)
pthread_rwlock_timedrdlock(3C)
pthread_rwlock_timedwrlock(3C)
rctlblk_get_enforced_value(3C)
- delimited string input
#include <stdio.h> ssize_t getline(char **restrict lineptr, size_t *restrict n, FILE *restrict stream);
ssize_t getdelim(char **restrict lineptr, size_t *restrict n, int delimiter, FILE *restrict stream);
The getline() function reads an entire line from stream, storing the address of the buffer containing the line in *lineptr. The buffer is null-terminated and includes the NEWLINE character if one was found.
If *lineptr is a null pointer, getline() allocates a buffer for storing the line. Alternatively, before the call to getline(), *lineptr can contain a pointer to a buffer allocated by malloc(3C) whose size is *n bytes. If the buffer is not large enough to store the line, getline() resizes the buffer with realloc(3C). In either case, a successful call to getline() updates *lineptr and *n to reflect the buffer address and size, respectively. The buffer should be freed with a call to free(3C).
The getdelim() function is identical to getline(), except a line delimiter other than NEWLINE can be specified as the delimiter argument. As with getline(), a delimiter character is not added if one was not present in stream before end-of-file was reached.
Upon successful completion, the getline() and getdelim() functions return the number of characters written into the buffer, including the delimiter character but excluding the terminating null character. Upon failure to read a line (including end of file condition), these function return -1 and set errno to indicate the error.
The getline() and getdelim() functions will fail if:
Either lineptr or n is a null pointer.
Insufficient memory is available.
The getline() and getdelim() functions may fail if:
More than {SSIZE_MAX} characters were read without encountering the delimiter character.
See fgetc(3C) for other conditions under which these functions will and may fail.
Example 1 Retrieve a line length.
#include <stdio.h> #include <stdlib.h> int main(void) { FILE *fp; char *line = NULL; size_t len = 0; ssize_t read; fp = fopen("/etc/motd", "r"); if (fp == NULL) exit(1); while ((read = getline(&line, &len, fp)) != -1) { printf("Retrieved line of length %zu :\n", read); printf("%s", line); } if (ferror(fp)) { /* handle error */ } free(line); fclose(fp); return 0; }
See attributes(5) for descriptions of the following attributes:
|
fgetc(3C), fgets(3C), free(3C), malloc(3C), realloc(3C), attributes(5)