]>
iEval git - fdkaac.git/blob - src/compat_posix.c
2 * Copyright (C) 2013 nu774
3 * For conditions of distribution and use, see copyright notice in COPYING
18 int64_t aacenc_timer(void)
20 struct timeval tv
= { 0 };
22 return (int64_t)tv
.tv_sec
* 1000 + tv
.tv_usec
/ 1000;
25 FILE *aacenc_fopen(const char *name
, const char *mode
)
28 if (strcmp(name
, "-") == 0)
29 fp
= (mode
[0] == 'r') ? stdin
: stdout
;
31 fp
= fopen(name
, mode
);
35 int aacenc_seekable(FILE *fp
)
37 return fseek(fp
, 0, SEEK_CUR
) == 0;
41 * Different from POSIX basename() when path ends with /.
42 * Since we use this only for a regular file, the difference doesn't matter.
44 const char *aacenc_basename(const char *path
)
46 const char *p
= strrchr(path
, '/');
47 return p
? p
+ 1: path
;
51 char *aacenc_to_utf8(const char *s
)
55 #else /* HAVE_ICONV */
57 #include <sys/types.h>
62 #if HAVE_LOCALCHARSET_H
63 #include <localcharset.h>
66 static const char *locale_charset(void)
68 return nl_langinfo(CODESET
);
71 static const char *locale_charset(void)
78 int utf8_from_charset(const char *charset
, const char *from
, char **to
)
81 size_t fromlen
, obsize
, ibleft
, obleft
;
84 cd
= iconv_open("UTF-8", charset
);
85 if (cd
== (iconv_t
)-1)
88 fromlen
= strlen(from
);
97 if (iconv(cd
, &ip
, &ibleft
, &op
, &obleft
) != (size_t)-1)
100 if (errno
== E2BIG
|| obleft
== 0) {
101 ptrdiff_t offset
= op
- *to
;
103 *to
= realloc(*to
, obsize
);
105 obleft
= obsize
- offset
- 1;
107 if (errno
== EILSEQ
) {
113 if (errno
!= E2BIG
&& errno
!= EILSEQ
)
119 if (fromlen
> 0 && op
== *to
) {
126 char *aacenc_to_utf8(const char *s
)
131 if ((charset
= locale_charset()) == 0)
132 charset
= "US-ASCII";
133 if (utf8_from_charset(charset
, s
, &result
) < 0)
137 #endif /* HAVE_ICONV */
This page took 0.058344 seconds and 4 git commands to generate.