New answers tagged

7

Error handling The way you handle error is quite unusual. Why use write() instead of fprintf(stderr, ...)? Why have some error messages stored in a variable like g_empty_string, but other errors messages are passes as literals, like "pipex: "? Why try to open() first and only if it fails check if filename is empty? On Linux, I recommend you use err(...


2

Print errors to stderr Error messages should be sent to stderr. This is especially important if regular messages are sent to stdout and the standard output is redirected to a file or a pipe. On Linux, I recommend you use the err() function to report errors, like so: if ((server_fd = socket(...)) == -1) err(EXIT_FAILURE, "failed to open socket");...


1

In this part: struct connection *con_obj=malloc(sizeof(struct connection)); if(con_obj!=NULL) You have checked if malloc succeeded, but then you print a warning and continue on. Consider using assert to test: struct connection *con_obj=malloc(sizeof(struct connection)); assert(con_obj != NULL); Why are you sleeping for 10 seconds? sleep(10); Here you are ...


2

Aside from your self-review, I noticed a few (very minor) things I thought may be worth pointing out First, a design opinion rather than a comment on the code. I'm not sure putting the lists of editors in variables in the file is the best approach - it has its advantages, but allowing it to be managed separately in configuration files may have advantages. ...


1

The print error function is only useful to a point, I have rather removed it and used direct in-place constructs instead, so this function has been removed: sudoedit_err () { ... ; exit 1; } and the code had changed to this: printf >&2 '%s\n' '...' return 1 So, it is now without the useless headline, and also we eliminated the exit keyword ...


Top 50 recent answers are included