| 1 | /* $Id: helpers.c 51 2003-04-07 01:30:32Z bird $ | 
|---|
| 2 | * | 
|---|
| 3 | * Helpers. | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright (c) 2003 knut st. osmundsen <bird@anduin.net> | 
|---|
| 6 | * | 
|---|
| 7 | */ | 
|---|
| 8 |  | 
|---|
| 9 | /******************************************************************************* | 
|---|
| 10 | *   Header Files                                                               * | 
|---|
| 11 | *******************************************************************************/ | 
|---|
| 12 | #ifdef USE_KLIB | 
|---|
| 13 | #include <kLib/kLib.h> | 
|---|
| 14 | #endif | 
|---|
| 15 | #include <stdlib.h> | 
|---|
| 16 | #include <io.h> | 
|---|
| 17 | #include <sys/types.h> | 
|---|
| 18 | #include <sys/stat.h> | 
|---|
| 19 | #include <stdarg.h> | 
|---|
| 20 | #include <stdio.h> | 
|---|
| 21 | #include <err.h> | 
|---|
| 22 |  | 
|---|
| 23 | #ifdef OS2 | 
|---|
| 24 | #define INCL_BASE | 
|---|
| 25 | #include <os2.h> | 
|---|
| 26 | #endif | 
|---|
| 27 |  | 
|---|
| 28 |  | 
|---|
| 29 | #ifdef OS2 | 
|---|
| 30 | /** | 
|---|
| 31 | * Resolve pszFileName to a full name. | 
|---|
| 32 | * @return pszResolvedName on success. | 
|---|
| 33 | * @returns NULL if not found. | 
|---|
| 34 | */ | 
|---|
| 35 | char *realpath(const char *pszFileName, char *pszResolvedName) | 
|---|
| 36 | { | 
|---|
| 37 | #ifdef USE_KLIB | 
|---|
| 38 | if (kPathCanonifyEx(pszFileName, NULL, '/', '/', pszResolvedName, KFILE_LENGTH)) | 
|---|
| 39 | if (kPathExist(pszFileName)) | 
|---|
| 40 | return pszResolvedName; | 
|---|
| 41 | #else | 
|---|
| 42 | if (_fullpath(pszResolvedName, pszFileName, _MAX_PATH)) | 
|---|
| 43 | { | 
|---|
| 44 | struct stat s; | 
|---|
| 45 | if (!stat(pszResolvedName, &s)) | 
|---|
| 46 | return pszResolvedName; | 
|---|
| 47 | } | 
|---|
| 48 | #endif | 
|---|
| 49 | return NULL; | 
|---|
| 50 | } | 
|---|
| 51 | #endif | 
|---|
| 52 |  | 
|---|
| 53 | #ifdef OS2 | 
|---|
| 54 | void    err(int flags, const char *pszFormat, ...) | 
|---|
| 55 | { | 
|---|
| 56 | va_list args; | 
|---|
| 57 | va_start(args, pszFormat); | 
|---|
| 58 | vfprintf(stderr, pszFormat, args); | 
|---|
| 59 | va_end(args); | 
|---|
| 60 | fprintf(stderr, "\n"); | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 | void    errx(int flags, const char *pszFormat, ...) | 
|---|
| 64 | { | 
|---|
| 65 | va_list args; | 
|---|
| 66 | va_start(args, pszFormat); | 
|---|
| 67 | vfprintf(stderr, pszFormat, args); | 
|---|
| 68 | va_end(args); | 
|---|
| 69 | fprintf(stderr, "\n"); | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | void    warnx(const char *pszFormat, ...) | 
|---|
| 73 | { | 
|---|
| 74 | va_list args; | 
|---|
| 75 | va_start(args, pszFormat); | 
|---|
| 76 | vfprintf(stderr, pszFormat, args); | 
|---|
| 77 | va_end(args); | 
|---|
| 78 | fprintf(stderr, "\n"); | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | void    warn(const char *pszFormat, ...) | 
|---|
| 82 | { | 
|---|
| 83 | va_list args; | 
|---|
| 84 | va_start(args, pszFormat); | 
|---|
| 85 | vfprintf(stderr, pszFormat, args); | 
|---|
| 86 | va_end(args); | 
|---|
| 87 | fprintf(stderr, "\n"); | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | #endif | 
|---|