Mercurial > hg
comparison mcabber/src/utils.c @ 77:32f54ad6d729
[/trunk] Changeset 91 by mikael
* Some more cleaning
* Create log in user's home dir if possible (more confidential...)
author | mikael |
---|---|
date | Sat, 16 Apr 2005 18:24:01 +0000 |
parents | a8f8492abd44 |
children | 0bd578421ce9 |
comparison
equal
deleted
inserted
replaced
76:a8f8492abd44 | 77:32f54ad6d729 |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 #include <string.h> | |
3 #include <stdarg.h> | 4 #include <stdarg.h> |
4 #include <time.h> | 5 #include <time.h> |
5 | 6 |
6 /* Variables globales a UTILS.C */ | 7 /* Variables globales a UTILS.C */ |
7 static int DebugEnabled; | 8 static int DebugEnabled; |
9 static char *FName; | |
8 | 10 |
9 void ut_InitDebug(int level) | 11 void ut_InitDebug(int level) |
10 { | 12 { |
11 FILE *fp = fopen("/tmp/mcabberlog", "w"); | 13 FILE *fp; |
14 | |
15 FName = getenv("HOME"); | |
16 if (!FName) | |
17 FName = "/tmp/mcabberlog"; | |
18 else { | |
19 char *tmpname = malloc(strlen(FName) + 12); | |
20 strcpy(tmpname, FName); | |
21 strcat(tmpname, "/mcabberlog"); | |
22 FName = tmpname; | |
23 } | |
12 | 24 |
13 DebugEnabled = level; | 25 DebugEnabled = level; |
14 | 26 |
27 fp = fopen(FName, "w"); | |
15 if (!fp) return; | 28 if (!fp) return; |
16 fprintf(fp, "Debugging mode started...\n" | 29 fprintf(fp, "Debugging mode started...\n" |
17 "-----------------------------------\n"); | 30 "-----------------------------------\n"); |
18 fclose(fp); | 31 fclose(fp); |
19 } | 32 } |
24 time_t ahora; | 37 time_t ahora; |
25 va_list ap; | 38 va_list ap; |
26 char *buffer = NULL; | 39 char *buffer = NULL; |
27 | 40 |
28 if (DebugEnabled) { | 41 if (DebugEnabled) { |
29 fp = fopen("/tmp/mcabberlog", "a+"); | 42 fp = fopen(FName, "a+"); |
30 if (!fp) return; | 43 if (!fp) return; |
31 buffer = (char *) calloc(1, 64); | 44 buffer = (char *) calloc(1, 64); |
32 | 45 |
33 ahora = time(NULL); | 46 ahora = time(NULL); |
34 strftime(buffer, 64, "[%H:%M:%S] ", localtime(&ahora)); | 47 strftime(buffer, 64, "[%H:%M:%S] ", localtime(&ahora)); |