]>
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 void aacenc_getmainargs(int *argc
, char ***argv
)
40 int aacenc_fprintf(FILE *fp
, const char *fmt
, ...)
46 cnt
= vfprintf(fp
, fmt
, ap
);
52 * Different from POSIX basename() when path ends with /.
53 * Since we use this only for a regular file, the difference doesn't matter.
55 const char *aacenc_basename(const char *path
)
57 const char *p
= strrchr(path
, '/');
58 return p
? p
+ 1: path
;
62 char *aacenc_to_utf8(const char *s
)
66 #else /* HAVE_ICONV */
68 #include <sys/types.h>
73 #if HAVE_LOCALCHARSET_H
74 #include <localcharset.h>
77 static const char *locale_charset(void)
79 return nl_langinfo(CODESET
);
82 static const char *locale_charset(void)
89 int utf8_from_charset(const char *charset
, const char *from
, char **to
)
92 size_t fromlen
, obsize
, ibleft
, obleft
;
95 cd
= iconv_open("UTF-8", charset
);
96 if (cd
== (iconv_t
)-1)
99 fromlen
= strlen(from
);
103 *to
= malloc(obsize
);
108 if (iconv(cd
, &ip
, &ibleft
, &op
, &obleft
) != (size_t)-1)
111 if (errno
== E2BIG
|| obleft
== 0) {
112 ptrdiff_t offset
= op
- *to
;
114 *to
= realloc(*to
, obsize
);
116 obleft
= obsize
- offset
- 1;
118 if (errno
== EILSEQ
) {
124 if (errno
!= E2BIG
&& errno
!= EILSEQ
)
130 if (fromlen
> 0 && op
== *to
) {
137 char *aacenc_to_utf8(const char *s
)
142 if ((charset
= locale_charset()) == 0)
143 charset
= "US-ASCII";
144 if (utf8_from_charset(charset
, s
, &result
) < 0)
148 #endif /* HAVE_ICONV */
This page took 0.049248 seconds and 4 git commands to generate.