| 1 |
#include "lng.common.h" |
| 2 |
#include <stdarg.h> |
| 3 |
#include <sys/stat.h> |
| 4 |
|
| 5 |
void TrimEnd(char *lpStr) |
| 6 |
{ |
| 7 |
char *Ptr = lpStr + strlen(lpStr) - 1; |
| 8 |
|
| 9 |
while (Ptr >= lpStr && (*Ptr == ' ' || *Ptr == '\t')) |
| 10 |
*Ptr = 0; |
| 11 |
} |
| 12 |
|
| 13 |
void TrimStart(char *lpStr) |
| 14 |
{ |
| 15 |
char *Ptr = lpStr; |
| 16 |
|
| 17 |
while (*Ptr && (*Ptr == ' ' || *Ptr == '\t')) |
| 18 |
Ptr++; |
| 19 |
|
| 20 |
memmove(lpStr, Ptr, strlen(Ptr) + 1); |
| 21 |
} |
| 22 |
|
| 23 |
void Trim(char *lpStr) |
| 24 |
{ |
| 25 |
TrimEnd(lpStr); |
| 26 |
TrimStart(lpStr); |
| 27 |
} |
| 28 |
|
| 29 |
#define _tchartodigit(c) ((c) >= '0' && (c) <= '9' ? (c) - '0' : -1) |
| 30 |
|
| 31 |
unsigned long CRC32(unsigned long crc, const char *buf, unsigned int len) |
| 32 |
{ |
| 33 |
static unsigned long crc_table[256]; |
| 34 |
|
| 35 |
if (!crc_table[1]) { |
| 36 |
unsigned long c; |
| 37 |
int n, k; |
| 38 |
|
| 39 |
for (n = 0; n < 256; n++) { |
| 40 |
c = (unsigned long)n; |
| 41 |
for (k = 0; k < 8; k++) |
| 42 |
c = (c >> 1) ^ (c & 1 ? 0xedb88320L : 0); |
| 43 |
crc_table[n] = c; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
crc = crc ^ 0xffffffffL; |
| 48 |
while (len-- > 0) { |
| 49 |
crc = crc_table[(crc ^ (*buf++)) & 0xff] ^ (crc >> 8); |
| 50 |
} |
| 51 |
|
| 52 |
return crc ^ 0xffffffffL; |
| 53 |
} |
| 54 |
|
| 55 |
void strmove(char *dst, const char *src) |
| 56 |
{ |
| 57 |
memmove(dst, src, strlen(src) + 1); |
| 58 |
} |
| 59 |
|
| 60 |
int OpenInputFile(const char *path) |
| 61 |
{ |
| 62 |
return open(path, O_RDONLY, 0644); |
| 63 |
} |
| 64 |
|
| 65 |
int CreateOutputFile(const char *path) |
| 66 |
{ |
| 67 |
return open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); |
| 68 |
} |
| 69 |
|
| 70 |
size_t QueryFileSize(int fd) |
| 71 |
{ |
| 72 |
struct stat s |
| 73 |
{}; |
| 74 |
if (fstat(fd, &s) == -1) |
| 75 |
return 0; |
| 76 |
|
| 77 |
return (size_t)s.st_size; |
| 78 |
} |