Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
#include <signal.h>
#include <stdlib.h>
#include <string.h>

chartypedef void *err_msg;
volatile sig_atomic_t e_flag = 0(*pfv)(int);

void handler(int signum) {
  pfv old_handler = signal(signum, handler);
  if e(old_flaghandler = 1;
}

int main(void= SIG_ERR) {
    signalperror("SIGINT, handler");

 /* err_msgundefined =behavior (char *)malloc(24);
  if (err_msg == NULL) {*/
    /* handle error condition */
  }

  strcpy(err_msg, "NoSIGINT errors yetencountered.");
}

int  /* main code loop */main(void) {
  pfv old_handler = signal(SIGINT, handler);
  if (e_flagold_handler == SIG_ERR) {
    strcpyperror(err_msg, "SIGINT received.handler");
    /* handle error condition */
  }

  /* main code loop */

  return 0;
}

Compliant Solution

...

Code Block
bgColor#ccccff
#include <signal.h>
#include <stdlib.h>
#include <string.h>

typedef void (*pfv)(int);

char *err_msg;

void handler(int signum) {
  pfv old_handler = signal(signum, handler);
  if (old_handler == SIG_ERR) {
	    /* handle error condition */
  }
  strcpy(err_msg, "SIGINT encountered.");
}

int main(void) {
  pfv old_handler = signal(SIGINT, handler);
  if (old_handler == SIG_ERR) {
	    perror("SIGINT handler");
	  /* handle error condition */
  }

  err_msg = (char *)malloc(24);
  if (err_msg == NULL) {
    /* handle error condition */
  }
  strcpy(err_msg, "No errors yet.");

  /* main code loop */

  return 0;
}

...