-Wall
for this course)
and make sure your program compiles without warnings (and of course without errors).
Note that warnings are intended to make you aware of potential issues in your code,
even if syntactically correct. In almost all cases, these warnings should be heeded and fixed.
Missing files will be handled with a 5 point deduction (possibly per
file) if you need to supply one or more new files in order for us to
build your solution.
char * message = "Hello!\n"; write(STDOUT_FILENO, message, 7);Here, the use of the hard-coded length is problematic. It introduces the possibility of error (what if you miscounted?) and makes maintainability difficult (what if you need to change the message, or make it dynamic?). Instead, use code like:
char * message = "Hello!\n"; write(STDOUT_FILENO, message, strlen(message));
enum return_vals { SUCCESS, ERROR_OPEN, ERROR_WRITE } int main(int argc, char * argv[]) { ... fd = open(filename, O_APPEND); if(fd == -1) { return -ERROR_OPEN; } result = write(fd, buf, count); if (result == -1) { return -ERROR_WRITE; } return SUCCESS; }
malloc
). Don't forget that in
addition to cleaning up memory, networking ports need to be unbound,
files and sockets need to be closed, etc.
#pragma once
or use precompilation include guards as the following code illustrates, to avoid duplicate inclusion:
#if ! defined (MY_FILE_H)
#define MY_FILE_H
// body of the header file
#endif /* MY_FILE_H */
malloc
)
#define
macros