/* Author: Ram Samudrala (me@ram.org) * Version: O1.0 * Detail: * November 22, 1995; Copyright (c) 1995 by Ram Samudrala. * * See the URL above for terms of use and general help. * * This is a set of general purpose error functions I use in my CGI * programs. */ #include "cgi_common.h" #include "cgi_display.h" #include "cgi_defines.h" /******************************************************************/ void display_error(char error_string[]) { display_content_type(error_string); printf("

%s

\n", error_string); printf("
\n"); printf("

If this is not the expected result, please notify\n"); printf("%s of this error. Thank you.

\n", CARETAKER, CARETAKER); display_signature(); exit(FALSE); } /******************************************************************/ void check_method(char method[], char routine_name[]) { if(strcmp(getenv("REQUEST_METHOD"), method) != 0) { char buf[200]; sprintf(buf, "%s(): access method error!", routine_name); display_error(buf); } return; } /******************************************************************/ void check_content_type(char routine_name[]) { if(strcmp(getenv("CONTENT_TYPE"), "application/x-www-form-urlencoded")) { char buf[200]; sprintf(buf, "%s(): content type error!", routine_name); display_error(buf); } return; } /******************************************************************/ void check_eof(int status, char routine_name[]) { if (status == EOF) { char buf[200]; sprintf(buf, "check_eof(): EOF returned in %s()!", routine_name); display_error(buf); } return; } /******************************************************************/ void check_max_count(int count, int max_count, char routine_name[]) { if (count>= max_count) { char buf[200]; sprintf(buf, "check_max_count(): max_count (%d) exceeded in %s()!", max_count, routine_name); display_error(buf); } return; } /******************************************************************/ void open_file(FILE **fp, char filename[], char status[], char routine_name[]) { char buf[20]; switch (status[0]) { case 'r': strcpy(buf, "reading"); break; case 'a': strcpy(buf, "appending"); break; case 'w': strcpy(buf, "writing"); break; default: strcpy(buf, "error!"); break; } if ((*fp = fopen(filename, status)) == NULL) { char buf2[200]; sprintf(buf2, "%s(): couldn't open %s for %s!\n", routine_name, filename, buf); display_error(buf2); } /* Lock the file */ if ((flock(fileno(*fp), LOCK_EX)) == -1) display_error("open_file(): error locking file!"); return; } /******************************************************************/ void close_file(FILE **fp, char filename[], char routine_name[]) { if ((flock(fileno(*fp), LOCK_UN)) == -1) display_error("open_file(): error unlocking file!"); if (fclose(*fp) == EOF) { char buf[200]; sprintf(buf, "%s(): couldn't close %s!", routine_name, filename); display_error(buf); } return; } /******************************************************************/

AltStyle によって変換されたページ (->オリジナル) /