Function Prototypes Flashcards
memcpy
void *memcpy(void *restrict dst, const void *restrict src, size_t n);
• Copies n bytes from memory area src to memory area dst
strcpy
char *stpcpy(char *dst, const char *src);
• Copies string src to dst
malloc
void *malloc(size_t size);
• Allocates block of memory and returns pointer
calloc
void *calloc(size_t count, size_t size);
• Allocates space for count objects, fills with zero
realloc
void *realloc(void *ptr, size_t size);
• Change the size of memory pointed to by ptr to size, returns ptr
free
void free(void *ptr);
• Deallocates memory allocation pointed to by ptr
strdup
char *strdup(const char *s1);
• Allocates sufficient memory for a copy of the string s1, does the copy, and returns a pointer to it
fopen
FILE *fopen(const char *restrict filename, const char *restrict mode);
• Opens file from filename and returns pointer to file stream
fdopen
FILE *fdopen(int fildes, const char *mode);
• Opens file from filedes and returns pointer to file stream
open
int open(const char *pathname, int flags);
• Open file at pathname for reading/writing, returns file descriptor
close
int close(int fildes);
• Close file associated with file destination, returns 0 or -1
read
ssize_t read(int fildes, void *buf, size_t nbyte);
• Read nbyte bytes of data from fildes into the buffer pointed to by buf. Returns number of bytes read or -1
write
ssize_t write(int fildes, const void *buf, size_t nbyte);
• Write nbyte bytes of data from buffer pointed to by buf into the filedes file. Returns number of bytes written or -1
lseek
off_t lseek(int fildes, off_t offset, int whence);
• Repositions the offset of the file descriptor fildes to the argument offset, according to the directive whence.
whence SEEK_SET = set to offset bytes
whence SEEK_CUR = current location plus bytes
whence SEEK_END = size of file plus bytes
stat
int stat(const char *path, struct stat *buf);
• Obtains information about the file pointed to by path.