Manual
The C functions, system calls and commands the articles cite.
C library
- atoi(3)Converts the start of a string to an int. atoi reports no errors: “abc” and “0” both give 0, and an overflow is undefined behavior.
- calloc(3)Allocates an array of nmemb elements of size bytes, sets every byte to zero and checks that nmemb * size does not overflow. Returns NULL on failure.
- execvp(3)Replaces the program in the current process with a command looked up in PATH, its arguments passed in an array terminated by NULL.
- fflush(3)Forces an output stream to write the bytes it is holding in memory. Needed before a possible crash or a fork, with no guaranteed effect on stdin.
- fgets(3)Reads a line into an array without going past its size, keeps the \n and always terminates the string. Returns NULL at end of file or on error.
- free(3)Returns a block from malloc, calloc or realloc to the heap. free(NULL) is safe; freeing twice, or a pointer that was never allocated, is undefined behavior.
- malloc(3)Reserves a block of memory on the heap and returns its address, or NULL if the allocation fails. The contents are uninitialized; the block is yours until free.
- memcpy(3)Copies n bytes from one memory area to another and returns the destination. The two areas must not overlap, or the result is undefined.
- memmove(3)Copies n bytes from one area to another and gets the right result even when the two overlap. Returns the destination, like memcpy.
- memset(3)Fills the first n bytes of a memory area with one byte value and returns the address of the area. Handy for setting a buffer to zero.
- printf(3)Writes formatted text to standard output. The formats to know (%d, %ld, %zu, %p, %s), what printf returns and the -Wformat warnings.
- putchar(3)Writes one character to standard output, converted to unsigned char. Returns that character or EOF, and goes through the stdout buffer like printf.
- puts(3)Writes a string to standard output, then a newline. No format is interpreted, which makes it simpler than printf for printing fixed text.
- realloc(3)Resizes a heap block and keeps its contents up to the smaller of the two sizes. On failure it returns NULL and leaves the old block allocated.
- scanf(3)Reads standard input according to a format and stores the values at the addresses you pass. Returns the number of values read, to check on every call.
- strcmp(3)Compares two strings byte by byte and returns a negative, zero or positive int. Why == does not compare strings, and why only the sign counts.
- strcpy(3)Copies a string, null byte included, into a buffer you provide. strcpy ignores the size of the destination: guaranteeing it is your job.
- strdup(3)Allocates a copy of a string with malloc and returns its address, or NULL. Part of standard C since C23; the copy must be released with free.
- strlen(3)Returns the number of bytes in a C string, not counting the final null byte. How it differs from sizeof, bytes versus characters, the size_t trap.
- strncpy(3)Copies at most n bytes and pads with null bytes. If the source is too long, the destination is left unterminated: strncpy is not a safe strcpy.
- strtol(3)Converts the start of a string to a long in the base you choose, tells you where parsing stopped through endptr and reports overflow with errno.
System calls
- dup2(2)Makes one file descriptor a copy of another. It is the call that redirects standard output to a file or a pipe before an exec.
- fork(2)Duplicates the calling process. The child gets a copy of the memory and of the open descriptors, and the return value tells which one is which.
- pipe(2)Creates a one-way channel in the kernel and returns two descriptors, one for reading and one for writing. Combined with fork, it connects two processes.
- waitpid(2)Waits for a child process to end and collects its status: exit code or the signal that killed it. Without this call, the dead child stays a zombie.
- write(2)System call that hands bytes to a file descriptor (1 for stdout, 2 for stderr), with no buffering and no formatting. Returns the number of bytes written.
Shell commands
Development tools
- gcc(1)The GNU compiler: compile and link a C program, turn on warnings, keep debugging information, pick the language standard, link a library.
- gdb(1)The GNU debugger: start a program, stop it on a line, read its variables and the call stack at the moment it crashes.
- make(1)Reads a Makefile and only reruns the commands whose target is older than its prerequisites. The useful options: -n, -j, -B, -C, -f.
- nm(1)Lists the symbols of a .o or a library: defined functions (T), symbols expected from elsewhere (U), variables (D, B). The tool for undefined reference errors.
- valgrind(1)Runs your program while watching every memory access: invalid reads, uninitialized values, blocks that are never freed.