| 1 | /* |
| 2 | * PuTTY miscellaneous Unix stuff |
| 3 | */ |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | #include <unistd.h> |
| 7 | #include <sys/time.h> |
| 8 | |
| 9 | #include "putty.h" |
| 10 | |
| 11 | unsigned long getticks(void) |
| 12 | { |
| 13 | struct timeval tv; |
| 14 | gettimeofday(&tv, NULL); |
| 15 | /* |
| 16 | * This will wrap around approximately every 4000 seconds, i.e. |
| 17 | * just over an hour, which is more than enough. |
| 18 | */ |
| 19 | return tv.tv_sec * 1000000 + tv.tv_usec; |
| 20 | } |
| 21 | |
| 22 | Filename filename_from_str(const char *str) |
| 23 | { |
| 24 | Filename ret; |
| 25 | strncpy(ret.path, str, sizeof(ret.path)); |
| 26 | ret.path[sizeof(ret.path)-1] = '\0'; |
| 27 | return ret; |
| 28 | } |
| 29 | |
| 30 | const char *filename_to_str(const Filename *fn) |
| 31 | { |
| 32 | return fn->path; |
| 33 | } |
| 34 | |
| 35 | int filename_equal(Filename f1, Filename f2) |
| 36 | { |
| 37 | return !strcmp(f1.path, f2.path); |
| 38 | } |
| 39 | |
| 40 | int filename_is_null(Filename fn) |
| 41 | { |
| 42 | return !*fn.path; |
| 43 | } |
| 44 | |
| 45 | #ifdef DEBUG |
| 46 | static FILE *debug_fp = NULL; |
| 47 | |
| 48 | void dputs(char *buf) |
| 49 | { |
| 50 | if (!debug_fp) { |
| 51 | debug_fp = fopen("debug.log", "w"); |
| 52 | } |
| 53 | |
| 54 | write(1, buf, strlen(buf)); |
| 55 | |
| 56 | fputs(buf, debug_fp); |
| 57 | fflush(debug_fp); |
| 58 | } |
| 59 | #endif |