7 void *malloc_nf_impl(size_t sz, const char *file, int line)
10 if(!(p = malloc(sz))) {
11 fprintf(stderr, "%s:%d failed to allocate %lu bytes\n", file, line, (unsigned long)sz);
17 void *calloc_nf_impl(size_t num, size_t sz, const char *file, int line)
20 if(!(p = calloc(num, sz))) {
21 fprintf(stderr, "%s:%d failed to allocate %lu bytes\n", file, line, (unsigned long)(sz * num));
27 void *realloc_nf_impl(void *p, size_t sz, const char *file, int line)
29 if(!(p = realloc(p, sz))) {
30 fprintf(stderr, "%s:%d failed to realloc %lu bytes\n", file, line, (unsigned long)sz);
36 char *strdup_nf_impl(const char *s, const char *file, int line)
39 if(!(res = strdup(s))) {
40 fprintf(stderr, "%s:%d failed to duplicate string\n", file, line);
47 int match_prefix(const char *str, const char *prefix)
49 while(*str && *prefix) {
50 if(*str++ != *prefix++) {
54 return *prefix ? 0 : 1;
59 static void closelog(void)
64 static void logmsg(const char *tag, const char *fmt, va_list ap)
67 if(!(logfile = fopen("oftp.log", "w"))) {
70 setvbuf(logfile, 0, _IOLBF, 0);
73 fprintf(logfile, "%s: ", tag);
74 vfprintf(logfile, fmt, ap);
77 void errmsg(const char *fmt, ...)
82 tui_vmsgbox(TUI_ERROR, "error", fmt, ap);
86 logmsg("error", fmt, ap);
90 void warnmsg(const char *fmt, ...)
95 tui_status(TUI_WARN, fmt, ap);
99 logmsg("warning", fmt, ap);
103 void infomsg(const char *fmt, ...)
108 tui_status(TUI_INFO, fmt, ap);
112 logmsg("info", fmt, ap);