redrust/
util.rs

1extern crate c2rust_bitfields;
2extern crate libc;
3extern crate core;
4
5extern "C" {
6    pub type _IO_wide_data;
7    pub type _IO_codecvt;
8    pub type _IO_marker;
9    pub type __dirstream;
10    fn strtod(_: *const libc::c_char, _: *mut *mut libc::c_char) -> libc::c_double;
11    fn strtold(_: *const libc::c_char, _: *mut *mut libc::c_char) -> f64;
12    fn strtoull(
13        _: *const libc::c_char,
14        _: *mut *mut libc::c_char,
15        _: libc::c_int,
16    ) -> libc::c_ulonglong;
17    fn rand() -> libc::c_int;
18    fn fclose(__stream: *mut FILE) -> libc::c_int;
19    fn fopen(_: *const libc::c_char, _: *const libc::c_char) -> *mut FILE;
20    fn snprintf(
21        _: *mut libc::c_char,
22        _: libc::c_ulong,
23        _: *const libc::c_char,
24        _: ...
25    ) -> libc::c_int;
26    fn fread(
27        _: *mut libc::c_void,
28        _: libc::c_ulong,
29        _: libc::c_ulong,
30        _: *mut FILE,
31    ) -> libc::c_ulong;
32    fn memcpy(
33        _: *mut libc::c_void,
34        _: *const libc::c_void,
35        _: libc::c_ulong,
36    ) -> *mut libc::c_void;
37    fn memset(
38        _: *mut libc::c_void,
39        _: libc::c_int,
40        _: libc::c_ulong,
41    ) -> *mut libc::c_void;
42    fn strcmp(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_int;
43    fn strchr(_: *const libc::c_char, _: libc::c_int) -> *mut libc::c_char;
44    fn strcasecmp(__s1: *const libc::c_char, __s2: *const libc::c_char) -> libc::c_int;
45    fn strlen(_: *const libc::c_char) -> libc::c_ulong;
46    fn __ctype_b_loc() -> *mut *const libc::c_ushort;
47    fn __ctype_tolower_loc() -> *mut *const __int32_t;
48    fn llrint(_: libc::c_double) -> libc::c_longlong;
49    fn close(__fd: libc::c_int) -> libc::c_int;
50    fn getcwd(__buf: *mut libc::c_char, __size: size_t) -> *mut libc::c_char;
51    fn getpid() -> __pid_t;
52    fn unlink(__name: *const libc::c_char) -> libc::c_int;
53    fn rmdir(__path: *const libc::c_char) -> libc::c_int;
54    fn fdatasync(__fildes: libc::c_int) -> libc::c_int;
55    fn gettimeofday(__tv: *mut timeval, __tz: *mut libc::c_void) -> libc::c_int;
56    fn __errno_location() -> *mut libc::c_int;
57    static mut timezone: libc::c_long;
58    fn mkdir(__path: *const libc::c_char, __mode: __mode_t) -> libc::c_int;
59    fn __xstat(
60        __ver: libc::c_int,
61        __filename: *const libc::c_char,
62        __stat_buf: *mut stat,
63    ) -> libc::c_int;
64    fn __fxstat(
65        __ver: libc::c_int,
66        __fildes: libc::c_int,
67        __stat_buf: *mut stat,
68    ) -> libc::c_int;
69    fn opendir(__name: *const libc::c_char) -> *mut DIR;
70    fn closedir(__dirp: *mut DIR) -> libc::c_int;
71    fn readdir(__dirp: *mut DIR) -> *mut dirent;
72    fn open(__file: *const libc::c_char, __oflag: libc::c_int, _: ...) -> libc::c_int;
73    fn dirname(__path: *mut libc::c_char) -> *mut libc::c_char;
74    fn sdsnew(init: *const libc::c_char) -> sds;
75    fn sdsempty() -> sds;
76    fn sdsfree(s: sds);
77    fn sdscat(s: sds, t: *const libc::c_char) -> sds;
78    fn sdscatsds(s: sds, t: sds) -> sds;
79    fn sdscatfmt(s: sds, fmt: *const libc::c_char, _: ...) -> sds;
80    fn sdstrim(s: sds, cset: *const libc::c_char) -> sds;
81    fn sdsrange(s: sds, start: ssize_t, end: ssize_t);
82    fn sha256_init(ctx: *mut SHA256_CTX);
83    fn sha256_update(ctx: *mut SHA256_CTX, data: *const BYTE, len: size_t);
84    fn sha256_final(ctx: *mut SHA256_CTX, hash: *mut BYTE);
85}
86pub type size_t = libc::c_ulong;
87pub type __uint8_t = libc::c_uchar;
88pub type __uint16_t = libc::c_ushort;
89pub type __int32_t = libc::c_int;
90pub type __uint32_t = libc::c_uint;
91pub type __int64_t = libc::c_long;
92pub type __uint64_t = libc::c_ulong;
93pub type __dev_t = libc::c_ulong;
94pub type __uid_t = libc::c_uint;
95pub type __gid_t = libc::c_uint;
96pub type __ino64_t = libc::c_ulong;
97pub type __mode_t = libc::c_uint;
98pub type __nlink_t = libc::c_uint;
99pub type __off_t = libc::c_long;
100pub type __off64_t = libc::c_long;
101pub type __pid_t = libc::c_int;
102pub type __time_t = libc::c_long;
103pub type __suseconds_t = libc::c_long;
104pub type __blksize_t = libc::c_int;
105pub type __blkcnt64_t = libc::c_long;
106pub type __ssize_t = libc::c_long;
107pub type __syscall_slong_t = libc::c_long;
108pub type pid_t = __pid_t;
109pub type ssize_t = __ssize_t;
110pub type int64_t = __int64_t;
111#[derive(Copy, Clone)]
112#[repr(C)]
113pub struct timeval {
114    pub tv_sec: __time_t,
115    pub tv_usec: __suseconds_t,
116}
117#[derive(Copy, Clone)]
118#[repr(C)]
119pub struct timespec {
120    pub tv_sec: __time_t,
121    pub tv_nsec: __syscall_slong_t,
122}
123#[derive(Copy, Clone)]
124#[repr(C)]
125pub struct _IO_FILE {
126    pub _flags: libc::c_int,
127    pub _IO_read_ptr: *mut libc::c_char,
128    pub _IO_read_end: *mut libc::c_char,
129    pub _IO_read_base: *mut libc::c_char,
130    pub _IO_write_base: *mut libc::c_char,
131    pub _IO_write_ptr: *mut libc::c_char,
132    pub _IO_write_end: *mut libc::c_char,
133    pub _IO_buf_base: *mut libc::c_char,
134    pub _IO_buf_end: *mut libc::c_char,
135    pub _IO_save_base: *mut libc::c_char,
136    pub _IO_backup_base: *mut libc::c_char,
137    pub _IO_save_end: *mut libc::c_char,
138    pub _markers: *mut _IO_marker,
139    pub _chain: *mut _IO_FILE,
140    pub _fileno: libc::c_int,
141    pub _flags2: libc::c_int,
142    pub _old_offset: __off_t,
143    pub _cur_column: libc::c_ushort,
144    pub _vtable_offset: libc::c_schar,
145    pub _shortbuf: [libc::c_char; 1],
146    pub _lock: *mut libc::c_void,
147    pub _offset: __off64_t,
148    pub _codecvt: *mut _IO_codecvt,
149    pub _wide_data: *mut _IO_wide_data,
150    pub _freeres_list: *mut _IO_FILE,
151    pub _freeres_buf: *mut libc::c_void,
152    pub __pad5: size_t,
153    pub _mode: libc::c_int,
154    pub _unused2: [libc::c_char; 20],
155}
156pub type _IO_lock_t = ();
157pub type FILE = _IO_FILE;
158pub type C2RustUnnamed = libc::c_uint;
159pub const _ISalnum: C2RustUnnamed = 8;
160pub const _ISpunct: C2RustUnnamed = 4;
161pub const _IScntrl: C2RustUnnamed = 2;
162pub const _ISblank: C2RustUnnamed = 1;
163pub const _ISgraph: C2RustUnnamed = 32768;
164pub const _ISprint: C2RustUnnamed = 16384;
165pub const _ISspace: C2RustUnnamed = 8192;
166pub const _ISxdigit: C2RustUnnamed = 4096;
167pub const _ISdigit: C2RustUnnamed = 2048;
168pub const _ISalpha: C2RustUnnamed = 1024;
169pub const _ISlower: C2RustUnnamed = 512;
170pub const _ISupper: C2RustUnnamed = 256;
171pub type uint8_t = __uint8_t;
172pub type uint16_t = __uint16_t;
173pub type uint32_t = __uint32_t;
174pub type uint64_t = __uint64_t;
175#[derive(Copy, Clone)]
176#[repr(C)]
177pub struct stat {
178    pub st_dev: __dev_t,
179    pub st_ino: __ino64_t,
180    pub st_mode: __mode_t,
181    pub st_nlink: __nlink_t,
182    pub st_uid: __uid_t,
183    pub st_gid: __gid_t,
184    pub st_rdev: __dev_t,
185    pub __pad1: __dev_t,
186    pub st_size: __off64_t,
187    pub st_blksize: __blksize_t,
188    pub __pad2: libc::c_int,
189    pub st_blocks: __blkcnt64_t,
190    pub st_atim: timespec,
191    pub st_mtim: timespec,
192    pub st_ctim: timespec,
193    pub __glibc_reserved: [libc::c_int; 2],
194}
195#[derive(Copy, Clone)]
196#[repr(C)]
197pub struct dirent {
198    pub d_ino: __ino64_t,
199    pub d_off: __off64_t,
200    pub d_reclen: libc::c_ushort,
201    pub d_type: libc::c_uchar,
202    pub d_name: [libc::c_char; 256],
203}
204pub type DIR = __dirstream;
205pub type sds = *mut libc::c_char;
206#[derive(Copy, Clone)]
207#[repr(C, packed)]
208pub struct sdshdr8 {
209    pub len: uint8_t,
210    pub alloc: uint8_t,
211    pub flags: libc::c_uchar,
212    pub buf: [libc::c_char; 0],
213}
214#[derive(Copy, Clone)]
215#[repr(C, packed)]
216pub struct sdshdr16 {
217    pub len: uint16_t,
218    pub alloc: uint16_t,
219    pub flags: libc::c_uchar,
220    pub buf: [libc::c_char; 0],
221}
222#[derive(Copy, Clone)]
223#[repr(C, packed)]
224pub struct sdshdr32 {
225    pub len: uint32_t,
226    pub alloc: uint32_t,
227    pub flags: libc::c_uchar,
228    pub buf: [libc::c_char; 0],
229}
230#[derive(Copy, Clone)]
231#[repr(C, packed)]
232pub struct sdshdr64 {
233    pub len: uint64_t,
234    pub alloc: uint64_t,
235    pub flags: libc::c_uchar,
236    pub buf: [libc::c_char; 0],
237}
238pub type ld2string_mode = libc::c_uint;
239pub const LD_STR_HEX: ld2string_mode = 2;
240pub const LD_STR_HUMAN: ld2string_mode = 1;
241pub const LD_STR_AUTO: ld2string_mode = 0;
242pub type BYTE = uint8_t;
243pub type WORD = uint32_t;
244#[derive(Copy, Clone)]
245#[repr(C)]
246pub struct SHA256_CTX {
247    pub data: [BYTE; 64],
248    pub datalen: WORD,
249    pub bitlen: libc::c_ulonglong,
250    pub state: [WORD; 8],
251}
252#[inline]
253unsafe extern "C" fn tolower(mut __c: libc::c_int) -> libc::c_int {
254    return if __c >= -(128 as libc::c_int) && __c < 256 as libc::c_int {
255        *(*__ctype_tolower_loc()).offset(__c as isize)
256    } else {
257        __c
258    };
259}
260#[inline]
261unsafe extern "C" fn stat(
262    mut __path: *const libc::c_char,
263    mut __statbuf: *mut stat,
264) -> libc::c_int {
265    return __xstat(0 as libc::c_int, __path, __statbuf);
266}
267#[inline]
268unsafe extern "C" fn fstat(
269    mut __fd: libc::c_int,
270    mut __statbuf: *mut stat,
271) -> libc::c_int {
272    return __fxstat(0 as libc::c_int, __fd, __statbuf);
273}
274#[inline]
275unsafe extern "C" fn sdslen(s: sds) -> size_t {
276    let mut flags: libc::c_uchar = *s.offset(-(1 as libc::c_int) as isize)
277        as libc::c_uchar;
278    match flags as libc::c_int & 7 as libc::c_int {
279        0 => return (flags as libc::c_int >> 3 as libc::c_int) as size_t,
280        1 => {
281            return (*(s
282                .offset(-(core::mem::size_of::<sdshdr8>() as libc::c_ulong as isize))
283                as *mut sdshdr8))
284                .len as size_t;
285        }
286        2 => {
287            return (*(s
288                .offset(-(core::mem::size_of::<sdshdr16>() as libc::c_ulong as isize))
289                as *mut sdshdr16))
290                .len as size_t;
291        }
292        3 => {
293            return (*(s
294                .offset(-(core::mem::size_of::<sdshdr32>() as libc::c_ulong as isize))
295                as *mut sdshdr32))
296                .len as size_t;
297        }
298        4 => {
299            return (*(s
300                .offset(-(core::mem::size_of::<sdshdr64>() as libc::c_ulong as isize))
301                as *mut sdshdr64))
302                .len;
303        }
304        _ => {}
305    }
306    return 0 as libc::c_int as size_t;
307}
308#[no_mangle]
309pub unsafe extern "C" fn stringmatchlen(
310    mut pattern: *const libc::c_char,
311    mut patternLen: libc::c_int,
312    mut string: *const libc::c_char,
313    mut stringLen: libc::c_int,
314    mut nocase: libc::c_int,
315) -> libc::c_int {
316    while patternLen != 0 && stringLen != 0 {
317        let mut current_block_74: u64;
318        match *pattern.offset(0 as libc::c_int as isize) as libc::c_int {
319            42 => {
320                while patternLen != 0
321                    && *pattern.offset(1 as libc::c_int as isize) as libc::c_int
322                        == '*' as i32
323                {
324                    pattern = pattern.offset(1);
325                    patternLen -= 1;
326                }
327                if patternLen == 1 as libc::c_int {
328                    return 1 as libc::c_int;
329                }
330                while stringLen != 0 {
331                    if stringmatchlen(
332                        pattern.offset(1 as libc::c_int as isize),
333                        patternLen - 1 as libc::c_int,
334                        string,
335                        stringLen,
336                        nocase,
337                    ) != 0
338                    {
339                        return 1 as libc::c_int;
340                    }
341                    string = string.offset(1);
342                    stringLen -= 1;
343                }
344                return 0 as libc::c_int;
345            }
346            63 => {
347                string = string.offset(1);
348                stringLen -= 1;
349                current_block_74 = 5028470053297453708;
350            }
351            91 => {
352                let mut not: libc::c_int = 0;
353                let mut match_0: libc::c_int = 0;
354                pattern = pattern.offset(1);
355                patternLen -= 1;
356                not = (*pattern.offset(0 as libc::c_int as isize) as libc::c_int
357                    == '^' as i32) as libc::c_int;
358                if not != 0 {
359                    pattern = pattern.offset(1);
360                    patternLen -= 1;
361                }
362                match_0 = 0 as libc::c_int;
363                loop {
364                    if *pattern.offset(0 as libc::c_int as isize) as libc::c_int
365                        == '\\' as i32 && patternLen >= 2 as libc::c_int
366                    {
367                        pattern = pattern.offset(1);
368                        patternLen -= 1;
369                        if *pattern.offset(0 as libc::c_int as isize) as libc::c_int
370                            == *string.offset(0 as libc::c_int as isize) as libc::c_int
371                        {
372                            match_0 = 1 as libc::c_int;
373                        }
374                    } else {
375                        if *pattern.offset(0 as libc::c_int as isize) as libc::c_int
376                            == ']' as i32
377                        {
378                            break;
379                        }
380                        if patternLen == 0 as libc::c_int {
381                            pattern = pattern.offset(-1);
382                            patternLen += 1;
383                            break;
384                        } else if patternLen >= 3 as libc::c_int
385                            && *pattern.offset(1 as libc::c_int as isize) as libc::c_int
386                                == '-' as i32
387                        {
388                            let mut start: libc::c_int = *pattern
389                                .offset(0 as libc::c_int as isize) as libc::c_int;
390                            let mut end: libc::c_int = *pattern
391                                .offset(2 as libc::c_int as isize) as libc::c_int;
392                            let mut c: libc::c_int = *string
393                                .offset(0 as libc::c_int as isize) as libc::c_int;
394                            if start > end {
395                                let mut t: libc::c_int = start;
396                                start = end;
397                                end = t;
398                            }
399                            if nocase != 0 {
400                                start = ({
401                                    let mut __res: libc::c_int = 0;
402                                    if core::mem::size_of::<libc::c_int>() as libc::c_ulong
403                                        > 1 as libc::c_int as libc::c_ulong
404                                    {
405                                        if 0 != 0 {
406                                            let mut __c: libc::c_int = start;
407                                            __res = if __c < -(128 as libc::c_int)
408                                                || __c > 255 as libc::c_int
409                                            {
410                                                __c
411                                            } else {
412                                                *(*__ctype_tolower_loc()).offset(__c as isize)
413                                            };
414                                        } else {
415                                            __res = tolower(start);
416                                        }
417                                    } else {
418                                        __res = *(*__ctype_tolower_loc()).offset(start as isize);
419                                    }
420                                    __res
421                                });
422                                end = ({
423                                    let mut __res: libc::c_int = 0;
424                                    if core::mem::size_of::<libc::c_int>() as libc::c_ulong
425                                        > 1 as libc::c_int as libc::c_ulong
426                                    {
427                                        if 0 != 0 {
428                                            let mut __c: libc::c_int = end;
429                                            __res = if __c < -(128 as libc::c_int)
430                                                || __c > 255 as libc::c_int
431                                            {
432                                                __c
433                                            } else {
434                                                *(*__ctype_tolower_loc()).offset(__c as isize)
435                                            };
436                                        } else {
437                                            __res = tolower(end);
438                                        }
439                                    } else {
440                                        __res = *(*__ctype_tolower_loc()).offset(end as isize);
441                                    }
442                                    __res
443                                });
444                                c = ({
445                                    let mut __res: libc::c_int = 0;
446                                    if core::mem::size_of::<libc::c_int>() as libc::c_ulong
447                                        > 1 as libc::c_int as libc::c_ulong
448                                    {
449                                        if 0 != 0 {
450                                            let mut __c: libc::c_int = c;
451                                            __res = if __c < -(128 as libc::c_int)
452                                                || __c > 255 as libc::c_int
453                                            {
454                                                __c
455                                            } else {
456                                                *(*__ctype_tolower_loc()).offset(__c as isize)
457                                            };
458                                        } else {
459                                            __res = tolower(c);
460                                        }
461                                    } else {
462                                        __res = *(*__ctype_tolower_loc()).offset(c as isize);
463                                    }
464                                    __res
465                                });
466                            }
467                            pattern = pattern.offset(2 as libc::c_int as isize);
468                            patternLen -= 2 as libc::c_int;
469                            if c >= start && c <= end {
470                                match_0 = 1 as libc::c_int;
471                            }
472                        } else if nocase == 0 {
473                            if *pattern.offset(0 as libc::c_int as isize) as libc::c_int
474                                == *string.offset(0 as libc::c_int as isize) as libc::c_int
475                            {
476                                match_0 = 1 as libc::c_int;
477                            }
478                        } else if ({
479                            let mut __res: libc::c_int = 0;
480                            if core::mem::size_of::<libc::c_int>() as libc::c_ulong
481                                > 1 as libc::c_int as libc::c_ulong
482                            {
483                                if 0 != 0 {
484                                    let mut __c: libc::c_int = *pattern
485                                        .offset(0 as libc::c_int as isize) as libc::c_int;
486                                    __res = (if __c < -(128 as libc::c_int)
487                                        || __c > 255 as libc::c_int
488                                    {
489                                        __c
490                                    } else {
491                                        *(*__ctype_tolower_loc()).offset(__c as isize)
492                                    });
493                                } else {
494                                    __res = tolower(
495                                        *pattern.offset(0 as libc::c_int as isize) as libc::c_int,
496                                    );
497                                }
498                            } else {
499                                __res = *(*__ctype_tolower_loc())
500                                    .offset(
501                                        *pattern.offset(0 as libc::c_int as isize) as libc::c_int
502                                            as isize,
503                                    );
504                            }
505                            __res
506                        })
507                            == ({
508                                let mut __res: libc::c_int = 0;
509                                if core::mem::size_of::<libc::c_int>() as libc::c_ulong
510                                    > 1 as libc::c_int as libc::c_ulong
511                                {
512                                    if 0 != 0 {
513                                        let mut __c: libc::c_int = *string
514                                            .offset(0 as libc::c_int as isize) as libc::c_int;
515                                        __res = (if __c < -(128 as libc::c_int)
516                                            || __c > 255 as libc::c_int
517                                        {
518                                            __c
519                                        } else {
520                                            *(*__ctype_tolower_loc()).offset(__c as isize)
521                                        });
522                                    } else {
523                                        __res = tolower(
524                                            *string.offset(0 as libc::c_int as isize) as libc::c_int,
525                                        );
526                                    }
527                                } else {
528                                    __res = *(*__ctype_tolower_loc())
529                                        .offset(
530                                            *string.offset(0 as libc::c_int as isize) as libc::c_int
531                                                as isize,
532                                        );
533                                }
534                                __res
535                            })
536                        {
537                            match_0 = 1 as libc::c_int;
538                        }
539                    }
540                    pattern = pattern.offset(1);
541                    patternLen -= 1;
542                }
543                if not != 0 {
544                    match_0 = (match_0 == 0) as libc::c_int;
545                }
546                if match_0 == 0 {
547                    return 0 as libc::c_int;
548                }
549                string = string.offset(1);
550                stringLen -= 1;
551                current_block_74 = 5028470053297453708;
552            }
553            92 => {
554                if patternLen >= 2 as libc::c_int {
555                    pattern = pattern.offset(1);
556                    patternLen -= 1;
557                }
558                current_block_74 = 3929285555421377241;
559            }
560            _ => {
561                current_block_74 = 3929285555421377241;
562            }
563        }
564        match current_block_74 {
565            3929285555421377241 => {
566                if nocase == 0 {
567                    if *pattern.offset(0 as libc::c_int as isize) as libc::c_int
568                        != *string.offset(0 as libc::c_int as isize) as libc::c_int
569                    {
570                        return 0 as libc::c_int;
571                    }
572                } else if ({
573                    let mut __res: libc::c_int = 0;
574                    if core::mem::size_of::<libc::c_int>() as libc::c_ulong
575                        > 1 as libc::c_int as libc::c_ulong
576                    {
577                        if 0 != 0 {
578                            let mut __c: libc::c_int = *pattern
579                                .offset(0 as libc::c_int as isize) as libc::c_int;
580                            __res = (if __c < -(128 as libc::c_int)
581                                || __c > 255 as libc::c_int
582                            {
583                                __c
584                            } else {
585                                *(*__ctype_tolower_loc()).offset(__c as isize)
586                            });
587                        } else {
588                            __res = tolower(
589                                *pattern.offset(0 as libc::c_int as isize) as libc::c_int,
590                            );
591                        }
592                    } else {
593                        __res = *(*__ctype_tolower_loc())
594                            .offset(
595                                *pattern.offset(0 as libc::c_int as isize) as libc::c_int
596                                    as isize,
597                            );
598                    }
599                    __res
600                })
601                    != ({
602                        let mut __res: libc::c_int = 0;
603                        if core::mem::size_of::<libc::c_int>() as libc::c_ulong
604                            > 1 as libc::c_int as libc::c_ulong
605                        {
606                            if 0 != 0 {
607                                let mut __c: libc::c_int = *string
608                                    .offset(0 as libc::c_int as isize) as libc::c_int;
609                                __res = (if __c < -(128 as libc::c_int)
610                                    || __c > 255 as libc::c_int
611                                {
612                                    __c
613                                } else {
614                                    *(*__ctype_tolower_loc()).offset(__c as isize)
615                                });
616                            } else {
617                                __res = tolower(
618                                    *string.offset(0 as libc::c_int as isize) as libc::c_int,
619                                );
620                            }
621                        } else {
622                            __res = *(*__ctype_tolower_loc())
623                                .offset(
624                                    *string.offset(0 as libc::c_int as isize) as libc::c_int
625                                        as isize,
626                                );
627                        }
628                        __res
629                    })
630                {
631                    return 0 as libc::c_int
632                }
633                string = string.offset(1);
634                stringLen -= 1;
635            }
636            _ => {}
637        }
638        pattern = pattern.offset(1);
639        patternLen -= 1;
640        if !(stringLen == 0 as libc::c_int) {
641            continue;
642        }
643        while *pattern as libc::c_int == '*' as i32 {
644            pattern = pattern.offset(1);
645            patternLen -= 1;
646        }
647        break;
648    }
649    if patternLen == 0 as libc::c_int && stringLen == 0 as libc::c_int {
650        return 1 as libc::c_int;
651    }
652    return 0 as libc::c_int;
653}
654#[no_mangle]
655pub unsafe extern "C" fn stringmatch(
656    mut pattern: *const libc::c_char,
657    mut string: *const libc::c_char,
658    mut nocase: libc::c_int,
659) -> libc::c_int {
660    return stringmatchlen(
661        pattern,
662        strlen(pattern) as libc::c_int,
663        string,
664        strlen(string) as libc::c_int,
665        nocase,
666    );
667}
668#[no_mangle]
669pub unsafe extern "C" fn stringmatchlen_fuzz_test() -> libc::c_int {
670    let mut str: [libc::c_char; 32] = [0; 32];
671    let mut pat: [libc::c_char; 32] = [0; 32];
672    let mut cycles: libc::c_int = 10000000 as libc::c_int;
673    let mut total_matches: libc::c_int = 0 as libc::c_int;
674    loop {
675        let fresh0 = cycles;
676        cycles = cycles - 1;
677        if !(fresh0 != 0) {
678            break;
679        }
680        let mut strlen_0: libc::c_int = (rand() as libc::c_ulong)
681            .wrapping_rem(core::mem::size_of::<[libc::c_char; 32]>() as libc::c_ulong)
682            as libc::c_int;
683        let mut patlen: libc::c_int = (rand() as libc::c_ulong)
684            .wrapping_rem(core::mem::size_of::<[libc::c_char; 32]>() as libc::c_ulong)
685            as libc::c_int;
686        let mut j: libc::c_int = 0 as libc::c_int;
687        while j < strlen_0 {
688            str[j as usize] = (rand() % 128 as libc::c_int) as libc::c_char;
689            j += 1;
690        }
691        let mut j_0: libc::c_int = 0 as libc::c_int;
692        while j_0 < patlen {
693            pat[j_0 as usize] = (rand() % 128 as libc::c_int) as libc::c_char;
694            j_0 += 1;
695        }
696        total_matches
697            += stringmatchlen(
698                pat.as_mut_ptr(),
699                patlen,
700                str.as_mut_ptr(),
701                strlen_0,
702                0 as libc::c_int,
703            );
704    }
705    return total_matches;
706}
707#[no_mangle]
708pub unsafe extern "C" fn memtoull(
709    mut p: *const libc::c_char,
710    mut err: *mut libc::c_int,
711) -> libc::c_ulonglong {
712    let mut u: *const libc::c_char = 0 as *const libc::c_char;
713    let mut buf: [libc::c_char; 128] = [0; 128];
714    let mut mul: libc::c_long = 0;
715    let mut val: libc::c_ulonglong = 0;
716    let mut digits: libc::c_uint = 0;
717    if !err.is_null() {
718        *err = 0 as libc::c_int;
719    }
720    u = p;
721    if *u as libc::c_int == '-' as i32 {
722        if !err.is_null() {
723            *err = 1 as libc::c_int;
724        }
725        return 0 as libc::c_int as libc::c_ulonglong;
726    }
727    while *u as libc::c_int != 0
728        && *(*__ctype_b_loc()).offset(*u as libc::c_int as isize) as libc::c_int
729            & _ISdigit as libc::c_int as libc::c_ushort as libc::c_int != 0
730    {
731        u = u.offset(1);
732    }
733    if *u as libc::c_int == '\0' as i32
734        || strcasecmp(u, b"b\0" as *const u8 as *const libc::c_char) == 0
735    {
736        mul = 1 as libc::c_int as libc::c_long;
737    } else if strcasecmp(u, b"k\0" as *const u8 as *const libc::c_char) == 0 {
738        mul = 1000 as libc::c_int as libc::c_long;
739    } else if strcasecmp(u, b"kb\0" as *const u8 as *const libc::c_char) == 0 {
740        mul = 1024 as libc::c_int as libc::c_long;
741    } else if strcasecmp(u, b"m\0" as *const u8 as *const libc::c_char) == 0 {
742        mul = (1000 as libc::c_int * 1000 as libc::c_int) as libc::c_long;
743    } else if strcasecmp(u, b"mb\0" as *const u8 as *const libc::c_char) == 0 {
744        mul = (1024 as libc::c_int * 1024 as libc::c_int) as libc::c_long;
745    } else if strcasecmp(u, b"g\0" as *const u8 as *const libc::c_char) == 0 {
746        mul = 1000 as libc::c_long * 1000 as libc::c_int as libc::c_long
747            * 1000 as libc::c_int as libc::c_long;
748    } else if strcasecmp(u, b"gb\0" as *const u8 as *const libc::c_char) == 0 {
749        mul = 1024 as libc::c_long * 1024 as libc::c_int as libc::c_long
750            * 1024 as libc::c_int as libc::c_long;
751    } else {
752        if !err.is_null() {
753            *err = 1 as libc::c_int;
754        }
755        return 0 as libc::c_int as libc::c_ulonglong;
756    }
757    digits = u.offset_from(p) as libc::c_long as libc::c_uint;
758    if digits as libc::c_ulong
759        >= core::mem::size_of::<[libc::c_char; 128]>() as libc::c_ulong
760    {
761        if !err.is_null() {
762            *err = 1 as libc::c_int;
763        }
764        return 0 as libc::c_int as libc::c_ulonglong;
765    }
766    memcpy(
767        buf.as_mut_ptr() as *mut libc::c_void,
768        p as *const libc::c_void,
769        digits as libc::c_ulong,
770    );
771    buf[digits as usize] = '\0' as i32 as libc::c_char;
772    let mut endptr: *mut libc::c_char = 0 as *mut libc::c_char;
773    *__errno_location() = 0 as libc::c_int;
774    val = strtoull(buf.as_mut_ptr(), &mut endptr, 10 as libc::c_int);
775    if val == 0 as libc::c_int as libc::c_ulonglong
776        && *__errno_location() == 22 as libc::c_int
777        || *endptr as libc::c_int != '\0' as i32
778    {
779        if !err.is_null() {
780            *err = 1 as libc::c_int;
781        }
782        return 0 as libc::c_int as libc::c_ulonglong;
783    }
784    return val.wrapping_mul(mul as libc::c_ulonglong);
785}
786#[no_mangle]
787pub unsafe extern "C" fn mempbrk(
788    mut s: *const libc::c_char,
789    mut len: size_t,
790    mut chars: *const libc::c_char,
791    mut charslen: size_t,
792) -> *const libc::c_char {
793    let mut j: size_t = 0 as libc::c_int as size_t;
794    while j < len {
795        let mut n: size_t = 0 as libc::c_int as size_t;
796        while n < charslen {
797            if *s.offset(j as isize) as libc::c_int
798                == *chars.offset(n as isize) as libc::c_int
799            {
800                return &*s.offset(j as isize) as *const libc::c_char;
801            }
802            n = n.wrapping_add(1);
803        }
804        j = j.wrapping_add(1);
805    }
806    return 0 as *const libc::c_char;
807}
808#[no_mangle]
809pub unsafe extern "C" fn memmapchars(
810    mut s: *mut libc::c_char,
811    mut len: size_t,
812    mut from: *const libc::c_char,
813    mut to: *const libc::c_char,
814    mut setlen: size_t,
815) -> *mut libc::c_char {
816    let mut j: size_t = 0 as libc::c_int as size_t;
817    while j < len {
818        let mut i: size_t = 0 as libc::c_int as size_t;
819        while i < setlen {
820            if *s.offset(j as isize) as libc::c_int
821                == *from.offset(i as isize) as libc::c_int
822            {
823                *s.offset(j as isize) = *to.offset(i as isize);
824                break;
825            } else {
826                i = i.wrapping_add(1);
827            }
828        }
829        j = j.wrapping_add(1);
830    }
831    return s;
832}
833#[no_mangle]
834pub unsafe extern "C" fn digits10(mut v: uint64_t) -> uint32_t {
835    if v < 10 as libc::c_int as libc::c_ulong {
836        return 1 as libc::c_int as uint32_t;
837    }
838    if v < 100 as libc::c_int as libc::c_ulong {
839        return 2 as libc::c_int as uint32_t;
840    }
841    if v < 1000 as libc::c_int as libc::c_ulong {
842        return 3 as libc::c_int as uint32_t;
843    }
844    if v < 1000000000000 as libc::c_ulong {
845        if v < 100000000 as libc::c_ulong {
846            if v < 1000000 as libc::c_int as libc::c_ulong {
847                if v < 10000 as libc::c_int as libc::c_ulong {
848                    return 4 as libc::c_int as uint32_t;
849                }
850                return (5 as libc::c_int
851                    + (v >= 100000 as libc::c_int as libc::c_ulong) as libc::c_int)
852                    as uint32_t;
853            }
854            return (7 as libc::c_int + (v >= 10000000 as libc::c_ulong) as libc::c_int)
855                as uint32_t;
856        }
857        if v < 10000000000 as libc::c_ulong {
858            return (9 as libc::c_int + (v >= 1000000000 as libc::c_ulong) as libc::c_int)
859                as uint32_t;
860        }
861        return (11 as libc::c_int + (v >= 100000000000 as libc::c_ulong) as libc::c_int)
862            as uint32_t;
863    }
864    return (12 as libc::c_int as libc::c_uint)
865        .wrapping_add(digits10(v.wrapping_div(1000000000000 as libc::c_ulong)));
866}
867#[no_mangle]
868pub unsafe extern "C" fn sdigits10(mut v: int64_t) -> uint32_t {
869    if v < 0 as libc::c_int as libc::c_long {
870        let mut uv: uint64_t = if v as libc::c_longlong
871            != -(9223372036854775807 as libc::c_longlong) - 1 as libc::c_longlong
872        {
873            -v as uint64_t
874        } else {
875            (9223372036854775807 as libc::c_longlong as uint64_t)
876                .wrapping_add(1 as libc::c_int as libc::c_ulong)
877        };
878        return (digits10(uv)).wrapping_add(1 as libc::c_int as libc::c_uint);
879    } else {
880        return digits10(v as uint64_t)
881    };
882}
883#[no_mangle]
884pub unsafe extern "C" fn ll2string(
885    mut dst: *mut libc::c_char,
886    mut dstlen: size_t,
887    mut svalue: libc::c_longlong,
888) -> libc::c_int {
889    let mut value: libc::c_ulonglong = 0;
890    let mut negative: libc::c_int = 0 as libc::c_int;
891    if svalue < 0 as libc::c_int as libc::c_longlong {
892        if svalue != -(9223372036854775807 as libc::c_longlong) - 1 as libc::c_longlong {
893            value = -svalue as libc::c_ulonglong;
894        } else {
895            value = (9223372036854775807 as libc::c_longlong as libc::c_ulonglong)
896                .wrapping_add(1 as libc::c_int as libc::c_ulonglong);
897        }
898        if dstlen < 2 as libc::c_int as libc::c_ulong {
899            return 0 as libc::c_int;
900        }
901        negative = 1 as libc::c_int;
902        *dst.offset(0 as libc::c_int as isize) = '-' as i32 as libc::c_char;
903        dst = dst.offset(1);
904        dstlen = dstlen.wrapping_sub(1);
905    } else {
906        value = svalue as libc::c_ulonglong;
907    }
908    let mut length: libc::c_int = ull2string(dst, dstlen, value);
909    if length == 0 as libc::c_int {
910        return 0 as libc::c_int;
911    }
912    return length + negative;
913}
914#[no_mangle]
915pub unsafe extern "C" fn ull2string(
916    mut dst: *mut libc::c_char,
917    mut dstlen: size_t,
918    mut value: libc::c_ulonglong,
919) -> libc::c_int {
920    static mut digits: [libc::c_char; 201] = unsafe {
921        *core::mem::transmute::<
922            &[u8; 201],
923            &[libc::c_char; 201],
924        >(
925            b"00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899\0",
926        )
927    };
928    let mut length: uint32_t = digits10(value as uint64_t);
929    if length as libc::c_ulong >= dstlen {
930        return 0 as libc::c_int;
931    }
932    let mut next: uint32_t = length.wrapping_sub(1 as libc::c_int as libc::c_uint);
933    *dst
934        .offset(
935            next.wrapping_add(1 as libc::c_int as libc::c_uint) as isize,
936        ) = '\0' as i32 as libc::c_char;
937    while value >= 100 as libc::c_int as libc::c_ulonglong {
938        let i: libc::c_int = value
939            .wrapping_rem(100 as libc::c_int as libc::c_ulonglong)
940            .wrapping_mul(2 as libc::c_int as libc::c_ulonglong) as libc::c_int;
941        value = value.wrapping_div(100 as libc::c_int as libc::c_ulonglong);
942        *dst.offset(next as isize) = digits[(i + 1 as libc::c_int) as usize];
943        *dst
944            .offset(
945                next.wrapping_sub(1 as libc::c_int as libc::c_uint) as isize,
946            ) = digits[i as usize];
947        next = (next as libc::c_uint).wrapping_sub(2 as libc::c_int as libc::c_uint)
948            as uint32_t as uint32_t;
949    }
950    if value < 10 as libc::c_int as libc::c_ulonglong {
951        *dst
952            .offset(
953                next as isize,
954            ) = ('0' as i32 as libc::c_uint).wrapping_add(value as uint32_t)
955            as libc::c_char;
956    } else {
957        let mut i_0: libc::c_int = (value as uint32_t)
958            .wrapping_mul(2 as libc::c_int as libc::c_uint) as libc::c_int;
959        *dst.offset(next as isize) = digits[(i_0 + 1 as libc::c_int) as usize];
960        *dst
961            .offset(
962                next.wrapping_sub(1 as libc::c_int as libc::c_uint) as isize,
963            ) = digits[i_0 as usize];
964    }
965    return length as libc::c_int;
966}
967#[no_mangle]
968pub unsafe extern "C" fn string2ll(
969    mut s: *const libc::c_char,
970    mut slen: size_t,
971    mut value: *mut libc::c_longlong,
972) -> libc::c_int {
973    let mut p: *const libc::c_char = s;
974    let mut plen: size_t = 0 as libc::c_int as size_t;
975    let mut negative: libc::c_int = 0 as libc::c_int;
976    let mut v: libc::c_ulonglong = 0;
977    if plen == slen || slen >= 21 as libc::c_int as libc::c_ulong {
978        return 0 as libc::c_int;
979    }
980    if slen == 1 as libc::c_int as libc::c_ulong
981        && *p.offset(0 as libc::c_int as isize) as libc::c_int == '0' as i32
982    {
983        if !value.is_null() {
984            *value = 0 as libc::c_int as libc::c_longlong;
985        }
986        return 1 as libc::c_int;
987    }
988    if *p.offset(0 as libc::c_int as isize) as libc::c_int == '-' as i32 {
989        negative = 1 as libc::c_int;
990        p = p.offset(1);
991        plen = plen.wrapping_add(1);
992        if plen == slen {
993            return 0 as libc::c_int;
994        }
995    }
996    if *p.offset(0 as libc::c_int as isize) as libc::c_int >= '1' as i32
997        && *p.offset(0 as libc::c_int as isize) as libc::c_int <= '9' as i32
998    {
999        v = (*p.offset(0 as libc::c_int as isize) as libc::c_int - '0' as i32)
1000            as libc::c_ulonglong;
1001        p = p.offset(1);
1002        plen = plen.wrapping_add(1);
1003    } else {
1004        return 0 as libc::c_int
1005    }
1006    while plen < slen
1007        && *p.offset(0 as libc::c_int as isize) as libc::c_int >= '0' as i32
1008        && *p.offset(0 as libc::c_int as isize) as libc::c_int <= '9' as i32
1009    {
1010        if v
1011            > (9223372036854775807 as libc::c_longlong as libc::c_ulonglong)
1012                .wrapping_mul(2 as libc::c_ulonglong)
1013                .wrapping_add(1 as libc::c_ulonglong)
1014                .wrapping_div(10 as libc::c_int as libc::c_ulonglong)
1015        {
1016            return 0 as libc::c_int;
1017        }
1018        v = v.wrapping_mul(10 as libc::c_int as libc::c_ulonglong);
1019        if v
1020            > (9223372036854775807 as libc::c_longlong as libc::c_ulonglong)
1021                .wrapping_mul(2 as libc::c_ulonglong)
1022                .wrapping_add(1 as libc::c_ulonglong)
1023                .wrapping_sub(
1024                    (*p.offset(0 as libc::c_int as isize) as libc::c_int - '0' as i32)
1025                        as libc::c_ulonglong,
1026                )
1027        {
1028            return 0 as libc::c_int;
1029        }
1030        v = v
1031            .wrapping_add(
1032                (*p.offset(0 as libc::c_int as isize) as libc::c_int - '0' as i32)
1033                    as libc::c_ulonglong,
1034            );
1035        p = p.offset(1);
1036        plen = plen.wrapping_add(1);
1037    }
1038    if plen < slen {
1039        return 0 as libc::c_int;
1040    }
1041    if negative != 0 {
1042        if v
1043            > (-(-(9223372036854775807 as libc::c_longlong) - 1 as libc::c_longlong
1044                + 1 as libc::c_int as libc::c_longlong) as libc::c_ulonglong)
1045                .wrapping_add(1 as libc::c_int as libc::c_ulonglong)
1046        {
1047            return 0 as libc::c_int;
1048        }
1049        if !value.is_null() {
1050            *value = v.wrapping_neg() as libc::c_longlong;
1051        }
1052    } else {
1053        if v > 9223372036854775807 as libc::c_longlong as libc::c_ulonglong {
1054            return 0 as libc::c_int;
1055        }
1056        if !value.is_null() {
1057            *value = v as libc::c_longlong;
1058        }
1059    }
1060    return 1 as libc::c_int;
1061}
1062#[no_mangle]
1063pub unsafe extern "C" fn string2ull(
1064    mut s: *const libc::c_char,
1065    mut value: *mut libc::c_ulonglong,
1066) -> libc::c_int {
1067    let mut ll: libc::c_longlong = 0;
1068    if string2ll(s, strlen(s), &mut ll) != 0 {
1069        if ll < 0 as libc::c_int as libc::c_longlong {
1070            return 0 as libc::c_int;
1071        }
1072        *value = ll as libc::c_ulonglong;
1073        return 1 as libc::c_int;
1074    }
1075    *__errno_location() = 0 as libc::c_int;
1076    let mut endptr: *mut libc::c_char = 0 as *mut libc::c_char;
1077    *value = strtoull(s, &mut endptr, 10 as libc::c_int);
1078    if *__errno_location() == 22 as libc::c_int
1079        || *__errno_location() == 34 as libc::c_int
1080        || !(*s as libc::c_int != '\0' as i32 && *endptr as libc::c_int == '\0' as i32)
1081    {
1082        return 0 as libc::c_int;
1083    }
1084    return 1 as libc::c_int;
1085}
1086#[no_mangle]
1087pub unsafe extern "C" fn string2l(
1088    mut s: *const libc::c_char,
1089    mut slen: size_t,
1090    mut lval: *mut libc::c_long,
1091) -> libc::c_int {
1092    let mut llval: libc::c_longlong = 0;
1093    if string2ll(s, slen, &mut llval) == 0 {
1094        return 0 as libc::c_int;
1095    }
1096    if llval
1097        < (-(9223372036854775807 as libc::c_long) - 1 as libc::c_long)
1098            as libc::c_longlong
1099        || llval > 9223372036854775807 as libc::c_long as libc::c_longlong
1100    {
1101        return 0 as libc::c_int;
1102    }
1103    *lval = llval as libc::c_long;
1104    return 1 as libc::c_int;
1105}
1106#[no_mangle]
1107pub unsafe extern "C" fn double2ll(
1108    mut d: libc::c_double,
1109    mut out: *mut libc::c_longlong,
1110) -> libc::c_int {
1111    if d
1112        < (-(9223372036854775807 as libc::c_longlong)
1113            / 2 as libc::c_int as libc::c_longlong) as libc::c_double
1114        || d
1115            > (9223372036854775807 as libc::c_longlong
1116                / 2 as libc::c_int as libc::c_longlong) as libc::c_double
1117    {
1118        return 0 as libc::c_int;
1119    }
1120    let mut ll: libc::c_longlong = d as libc::c_longlong;
1121    if ll as libc::c_double == d {
1122        *out = ll;
1123        return 1 as libc::c_int;
1124    }
1125    return 0 as libc::c_int;
1126}
1127#[no_mangle]
1128pub unsafe extern "C" fn d2string(
1129    mut buf: *mut libc::c_char,
1130    mut len: size_t,
1131    mut value: libc::c_double,
1132) -> libc::c_int {
1133    if value.is_nan() as i32 != 0 {
1134        len = snprintf(buf, len, b"nan\0" as *const u8 as *const libc::c_char) as size_t;
1135    } else if if value.is_infinite() {
1136        if value.is_sign_positive() { 1 } else { -1 }
1137    } else {
1138        0
1139    } != 0
1140    {
1141        if value < 0 as libc::c_int as libc::c_double {
1142            len = snprintf(buf, len, b"-inf\0" as *const u8 as *const libc::c_char)
1143                as size_t;
1144        } else {
1145            len = snprintf(buf, len, b"inf\0" as *const u8 as *const libc::c_char)
1146                as size_t;
1147        }
1148    } else if value == 0 as libc::c_int as libc::c_double {
1149        if 1.0f64 / value < 0 as libc::c_int as libc::c_double {
1150            len = snprintf(buf, len, b"-0\0" as *const u8 as *const libc::c_char)
1151                as size_t;
1152        } else {
1153            len = snprintf(buf, len, b"0\0" as *const u8 as *const libc::c_char)
1154                as size_t;
1155        }
1156    } else {
1157        let mut lvalue: libc::c_longlong = 0;
1158        if double2ll(value, &mut lvalue) != 0 {
1159            len = ll2string(buf, len, lvalue) as size_t;
1160        } else {
1161            len = snprintf(
1162                buf,
1163                len,
1164                b"%.17g\0" as *const u8 as *const libc::c_char,
1165                value,
1166            ) as size_t;
1167        }
1168    }
1169    return len as libc::c_int;
1170}
1171#[no_mangle]
1172pub unsafe extern "C" fn fixedpoint_d2string(
1173    mut dst: *mut libc::c_char,
1174    mut dstlen: size_t,
1175    mut dvalue: libc::c_double,
1176    mut fractional_digits: libc::c_int,
1177) -> libc::c_int {
1178    static mut powers_of_ten: [libc::c_double; 18] = [
1179        1.0f64,
1180        10.0f64,
1181        100.0f64,
1182        1000.0f64,
1183        10000.0f64,
1184        100000.0f64,
1185        1000000.0f64,
1186        10000000.0f64,
1187        100000000.0f64,
1188        1000000000.0f64,
1189        10000000000.0f64,
1190        100000000000.0f64,
1191        1000000000000.0f64,
1192        10000000000000.0f64,
1193        100000000000000.0f64,
1194        1000000000000000.0f64,
1195        10000000000000000.0f64,
1196        100000000000000000.0f64,
1197    ];
1198    let mut svalue: libc::c_longlong = 0;
1199    let mut value: libc::c_ulonglong = 0;
1200    let mut negative: libc::c_int = 0;
1201    static mut digitsd: [libc::c_char; 201] = unsafe {
1202        *core::mem::transmute::<
1203            &[u8; 201],
1204            &[libc::c_char; 201],
1205        >(
1206            b"00010203040506070809101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899\0",
1207        )
1208    };
1209    let mut ndigits: uint32_t = 0;
1210    let mut integer_digits: libc::c_int = 0;
1211    let mut size: libc::c_int = 0;
1212    let mut next: libc::c_int = 0;
1213    let mut current_block: u64;
1214    if !(fractional_digits < 1 as libc::c_int || fractional_digits > 17 as libc::c_int) {
1215        if !((dstlen as libc::c_int) < fractional_digits + 3 as libc::c_int) {
1216            if dvalue == 0 as libc::c_int as libc::c_double {
1217                *dst.offset(0 as libc::c_int as isize) = '0' as i32 as libc::c_char;
1218                *dst.offset(1 as libc::c_int as isize) = '.' as i32 as libc::c_char;
1219                memset(
1220                    dst.offset(2 as libc::c_int as isize) as *mut libc::c_void,
1221                    '0' as i32,
1222                    fractional_digits as libc::c_ulong,
1223                );
1224                *dst
1225                    .offset(
1226                        (fractional_digits + 2 as libc::c_int) as isize,
1227                    ) = '\0' as i32 as libc::c_char;
1228                return fractional_digits + 2 as libc::c_int;
1229            }
1230            svalue = llrint(dvalue * powers_of_ten[fractional_digits as usize]);
1231            value = 0;
1232            negative = 0 as libc::c_int;
1233            if svalue < 0 as libc::c_int as libc::c_longlong {
1234                if svalue
1235                    != -(9223372036854775807 as libc::c_longlong) - 1 as libc::c_longlong
1236                {
1237                    value = -svalue as libc::c_ulonglong;
1238                } else {
1239                    value = (9223372036854775807 as libc::c_longlong
1240                        as libc::c_ulonglong)
1241                        .wrapping_add(1 as libc::c_int as libc::c_ulonglong);
1242                }
1243                if dstlen < 2 as libc::c_int as libc::c_ulong {
1244                    current_block = 2556275553776289657;
1245                } else {
1246                    negative = 1 as libc::c_int;
1247                    *dst.offset(0 as libc::c_int as isize) = '-' as i32 as libc::c_char;
1248                    dst = dst.offset(1);
1249                    dstlen = dstlen.wrapping_sub(1);
1250                    current_block = 5689001924483802034;
1251                }
1252            } else {
1253                value = svalue as libc::c_ulonglong;
1254                current_block = 5689001924483802034;
1255            }
1256            match current_block {
1257                2556275553776289657 => {}
1258                _ => {
1259                    ndigits = digits10(value as uint64_t);
1260                    if !(ndigits as libc::c_ulong >= dstlen) {
1261                        integer_digits = ndigits
1262                            .wrapping_sub(fractional_digits as libc::c_uint)
1263                            as libc::c_int;
1264                        if integer_digits < 1 as libc::c_int {
1265                            *dst
1266                                .offset(
1267                                    0 as libc::c_int as isize,
1268                                ) = '0' as i32 as libc::c_char;
1269                            integer_digits = 1 as libc::c_int;
1270                        }
1271                        *dst
1272                            .offset(
1273                                integer_digits as isize,
1274                            ) = '.' as i32 as libc::c_char;
1275                        size = integer_digits + 1 as libc::c_int + fractional_digits;
1276                        memset(
1277                            dst
1278                                .offset(integer_digits as isize)
1279                                .offset(1 as libc::c_int as isize) as *mut libc::c_void,
1280                            '0' as i32,
1281                            fractional_digits as libc::c_ulong,
1282                        );
1283                        next = size - 1 as libc::c_int;
1284                        while value >= 100 as libc::c_int as libc::c_ulonglong {
1285                            let i: libc::c_int = value
1286                                .wrapping_rem(100 as libc::c_int as libc::c_ulonglong)
1287                                .wrapping_mul(2 as libc::c_int as libc::c_ulonglong)
1288                                as libc::c_int;
1289                            value = value
1290                                .wrapping_div(100 as libc::c_int as libc::c_ulonglong);
1291                            *dst
1292                                .offset(
1293                                    next as isize,
1294                                ) = digitsd[(i + 1 as libc::c_int) as usize];
1295                            *dst
1296                                .offset(
1297                                    (next - 1 as libc::c_int) as isize,
1298                                ) = digitsd[i as usize];
1299                            next -= 2 as libc::c_int;
1300                            if next == integer_digits {
1301                                next -= 1;
1302                            }
1303                        }
1304                        if value < 10 as libc::c_int as libc::c_ulonglong {
1305                            *dst
1306                                .offset(
1307                                    next as isize,
1308                                ) = ('0' as i32 as libc::c_uint)
1309                                .wrapping_add(value as uint32_t) as libc::c_char;
1310                        } else {
1311                            let mut i_0: libc::c_int = (value as uint32_t)
1312                                .wrapping_mul(2 as libc::c_int as libc::c_uint)
1313                                as libc::c_int;
1314                            *dst
1315                                .offset(
1316                                    next as isize,
1317                                ) = digitsd[(i_0 + 1 as libc::c_int) as usize];
1318                            *dst
1319                                .offset(
1320                                    (next - 1 as libc::c_int) as isize,
1321                                ) = digitsd[i_0 as usize];
1322                        }
1323                        *dst.offset(size as isize) = '\0' as i32 as libc::c_char;
1324                        return size + negative;
1325                    }
1326                }
1327            }
1328        }
1329    }
1330    if dstlen > 0 as libc::c_int as libc::c_ulong {
1331        *dst.offset(0 as libc::c_int as isize) = '\0' as i32 as libc::c_char;
1332    }
1333    return 0 as libc::c_int;
1334}
1335#[no_mangle]
1336pub unsafe extern "C" fn trimDoubleString(
1337    mut buf: *mut libc::c_char,
1338    mut len: size_t,
1339) -> libc::c_int {
1340    if !(strchr(buf, '.' as i32)).is_null() {
1341        let mut p: *mut libc::c_char = buf
1342            .offset(len as isize)
1343            .offset(-(1 as libc::c_int as isize));
1344        while *p as libc::c_int == '0' as i32 {
1345            p = p.offset(-1);
1346            len = len.wrapping_sub(1);
1347        }
1348        if *p as libc::c_int == '.' as i32 {
1349            len = len.wrapping_sub(1);
1350        }
1351    }
1352    *buf.offset(len as isize) = '\0' as i32 as libc::c_char;
1353    return len as libc::c_int;
1354}
1355#[no_mangle]
1356pub unsafe extern "C" fn ld2string(
1357    mut buf: *mut libc::c_char,
1358    mut len: size_t,
1359    mut value: f64,
1360    mut mode: ld2string_mode,
1361) -> libc::c_int {
1362    let mut l: size_t = 0 as libc::c_int as size_t;
1363    if if value.is_infinite() {
1364        if value.is_sign_positive() { 1 } else { -1 }
1365    } else {
1366        0
1367    } != 0
1368    {
1369        if len < 5 as libc::c_int as libc::c_ulong {
1370            return 0 as libc::c_int;
1371        }
1372        if value > (0 as libc::c_int) as f64 {
1373            memcpy(
1374                buf as *mut libc::c_void,
1375                b"inf\0" as *const u8 as *const libc::c_char as *const libc::c_void,
1376                3 as libc::c_int as libc::c_ulong,
1377            );
1378            l = 3 as libc::c_int as size_t;
1379        } else {
1380            memcpy(
1381                buf as *mut libc::c_void,
1382                b"-inf\0" as *const u8 as *const libc::c_char as *const libc::c_void,
1383                4 as libc::c_int as libc::c_ulong,
1384            );
1385            l = 4 as libc::c_int as size_t;
1386        }
1387    } else {
1388        match mode as libc::c_uint {
1389            0 => {
1390                l = snprintf(
1391                    buf,
1392                    len,
1393                    b"%.17Lg\0" as *const u8 as *const libc::c_char,
1394                    value,
1395                ) as size_t;
1396                if l.wrapping_add(1 as libc::c_int as libc::c_ulong) > len {
1397                    return 0 as libc::c_int;
1398                }
1399            }
1400            2 => {
1401                l = snprintf(
1402                    buf,
1403                    len,
1404                    b"%La\0" as *const u8 as *const libc::c_char,
1405                    value,
1406                ) as size_t;
1407                if l.wrapping_add(1 as libc::c_int as libc::c_ulong) > len {
1408                    return 0 as libc::c_int;
1409                }
1410            }
1411            1 => {
1412                l = snprintf(
1413                    buf,
1414                    len,
1415                    b"%.17Lf\0" as *const u8 as *const libc::c_char,
1416                    value,
1417                ) as size_t;
1418                if l.wrapping_add(1 as libc::c_int as libc::c_ulong) > len {
1419                    return 0 as libc::c_int;
1420                }
1421                if !(strchr(buf, '.' as i32)).is_null() {
1422                    let mut p: *mut libc::c_char = buf
1423                        .offset(l as isize)
1424                        .offset(-(1 as libc::c_int as isize));
1425                    while *p as libc::c_int == '0' as i32 {
1426                        p = p.offset(-1);
1427                        l = l.wrapping_sub(1);
1428                    }
1429                    if *p as libc::c_int == '.' as i32 {
1430                        l = l.wrapping_sub(1);
1431                    }
1432                }
1433                if l == 2 as libc::c_int as libc::c_ulong
1434                    && *buf.offset(0 as libc::c_int as isize) as libc::c_int
1435                        == '-' as i32
1436                    && *buf.offset(1 as libc::c_int as isize) as libc::c_int
1437                        == '0' as i32
1438                {
1439                    *buf.offset(0 as libc::c_int as isize) = '0' as i32 as libc::c_char;
1440                    l = 1 as libc::c_int as size_t;
1441                }
1442            }
1443            _ => return 0 as libc::c_int,
1444        }
1445    }
1446    *buf.offset(l as isize) = '\0' as i32 as libc::c_char;
1447    return l as libc::c_int;
1448}
1449#[no_mangle]
1450pub unsafe extern "C" fn getRandomBytes(mut p: *mut libc::c_uchar, mut len: size_t) {
1451    static mut seed_initialized: libc::c_int = 0 as libc::c_int;
1452    static mut seed: [libc::c_uchar; 64] = [0; 64];
1453    static mut counter: uint64_t = 0 as libc::c_int as uint64_t;
1454    if seed_initialized == 0 {
1455        let mut fp: *mut FILE = fopen(
1456            b"/dev/urandom\0" as *const u8 as *const libc::c_char,
1457            b"r\0" as *const u8 as *const libc::c_char,
1458        );
1459        if fp.is_null()
1460            || fread(
1461                seed.as_mut_ptr() as *mut libc::c_void,
1462                core::mem::size_of::<[libc::c_uchar; 64]>() as libc::c_ulong,
1463                1 as libc::c_int as libc::c_ulong,
1464                fp,
1465            ) != 1 as libc::c_int as libc::c_ulong
1466        {
1467            let mut j: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1468            while (j as libc::c_ulong)
1469                < core::mem::size_of::<[libc::c_uchar; 64]>() as libc::c_ulong
1470            {
1471                let mut tv: timeval = timeval { tv_sec: 0, tv_usec: 0 };
1472                gettimeofday(&mut tv, 0 as *mut libc::c_void);
1473                let mut pid: pid_t = getpid();
1474                seed[j
1475                    as usize] = (tv.tv_sec ^ tv.tv_usec ^ pid as libc::c_long
1476                    ^ fp as libc::c_long) as libc::c_uchar;
1477                j = j.wrapping_add(1);
1478            }
1479        } else {
1480            seed_initialized = 1 as libc::c_int;
1481        }
1482        if !fp.is_null() {
1483            fclose(fp);
1484        }
1485    }
1486    while len != 0 {
1487        let mut digest: [libc::c_uchar; 32] = [0; 32];
1488        let mut kxor: [libc::c_uchar; 64] = [0; 64];
1489        let mut copylen: libc::c_uint = (if len > 32 as libc::c_int as libc::c_ulong {
1490            32 as libc::c_int as libc::c_ulong
1491        } else {
1492            len
1493        }) as libc::c_uint;
1494        memcpy(
1495            kxor.as_mut_ptr() as *mut libc::c_void,
1496            seed.as_mut_ptr() as *const libc::c_void,
1497            core::mem::size_of::<[libc::c_uchar; 64]>() as libc::c_ulong,
1498        );
1499        let mut i: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1500        while (i as libc::c_ulong)
1501            < core::mem::size_of::<[libc::c_uchar; 64]>() as libc::c_ulong
1502        {
1503            kxor[i
1504                as usize] = (kxor[i as usize] as libc::c_int ^ 0x36 as libc::c_int)
1505                as libc::c_uchar;
1506            i = i.wrapping_add(1);
1507        }
1508        let mut ctx: SHA256_CTX = SHA256_CTX {
1509            data: [0; 64],
1510            datalen: 0,
1511            bitlen: 0,
1512            state: [0; 8],
1513        };
1514        sha256_init(&mut ctx);
1515        sha256_update(
1516            &mut ctx,
1517            kxor.as_mut_ptr() as *const BYTE,
1518            core::mem::size_of::<[libc::c_uchar; 64]>() as libc::c_ulong,
1519        );
1520        sha256_update(
1521            &mut ctx,
1522            &mut counter as *mut uint64_t as *mut libc::c_uchar as *const BYTE,
1523            core::mem::size_of::<uint64_t>() as libc::c_ulong,
1524        );
1525        sha256_final(&mut ctx, digest.as_mut_ptr());
1526        memcpy(
1527            kxor.as_mut_ptr() as *mut libc::c_void,
1528            seed.as_mut_ptr() as *const libc::c_void,
1529            core::mem::size_of::<[libc::c_uchar; 64]>() as libc::c_ulong,
1530        );
1531        let mut i_0: libc::c_uint = 0 as libc::c_int as libc::c_uint;
1532        while (i_0 as libc::c_ulong)
1533            < core::mem::size_of::<[libc::c_uchar; 64]>() as libc::c_ulong
1534        {
1535            kxor[i_0
1536                as usize] = (kxor[i_0 as usize] as libc::c_int ^ 0x5c as libc::c_int)
1537                as libc::c_uchar;
1538            i_0 = i_0.wrapping_add(1);
1539        }
1540        sha256_init(&mut ctx);
1541        sha256_update(
1542            &mut ctx,
1543            kxor.as_mut_ptr() as *const BYTE,
1544            core::mem::size_of::<[libc::c_uchar; 64]>() as libc::c_ulong,
1545        );
1546        sha256_update(
1547            &mut ctx,
1548            digest.as_mut_ptr() as *const BYTE,
1549            32 as libc::c_int as size_t,
1550        );
1551        sha256_final(&mut ctx, digest.as_mut_ptr());
1552        counter = counter.wrapping_add(1);
1553        memcpy(
1554            p as *mut libc::c_void,
1555            digest.as_mut_ptr() as *const libc::c_void,
1556            copylen as libc::c_ulong,
1557        );
1558        len = (len as libc::c_ulong).wrapping_sub(copylen as libc::c_ulong) as size_t
1559            as size_t;
1560        p = p.offset(copylen as isize);
1561    }
1562}
1563#[no_mangle]
1564pub unsafe extern "C" fn getRandomHexChars(mut p: *mut libc::c_char, mut len: size_t) {
1565    let mut charset: *mut libc::c_char = b"0123456789abcdef\0" as *const u8
1566        as *const libc::c_char as *mut libc::c_char;
1567    let mut j: size_t = 0;
1568    getRandomBytes(p as *mut libc::c_uchar, len);
1569    j = 0 as libc::c_int as size_t;
1570    while j < len {
1571        *p
1572            .offset(
1573                j as isize,
1574            ) = *charset
1575            .offset(
1576                (*p.offset(j as isize) as libc::c_int & 0xf as libc::c_int) as isize,
1577            );
1578        j = j.wrapping_add(1);
1579    }
1580}
1581#[no_mangle]
1582pub unsafe extern "C" fn getAbsolutePath(mut filename: *mut libc::c_char) -> sds {
1583    let mut cwd: [libc::c_char; 1024] = [0; 1024];
1584    let mut abspath: sds = 0 as *mut libc::c_char;
1585    let mut relpath: sds = sdsnew(filename);
1586    relpath = sdstrim(relpath, b" \r\n\t\0" as *const u8 as *const libc::c_char);
1587    if *relpath.offset(0 as libc::c_int as isize) as libc::c_int == '/' as i32 {
1588        return relpath;
1589    }
1590    if (getcwd(
1591        cwd.as_mut_ptr(),
1592        core::mem::size_of::<[libc::c_char; 1024]>() as libc::c_ulong,
1593    ))
1594        .is_null()
1595    {
1596        sdsfree(relpath);
1597        return 0 as sds;
1598    }
1599    abspath = sdsnew(cwd.as_mut_ptr());
1600    if sdslen(abspath) != 0
1601        && *abspath
1602            .offset(
1603                (sdslen(abspath)).wrapping_sub(1 as libc::c_int as libc::c_ulong)
1604                    as isize,
1605            ) as libc::c_int != '/' as i32
1606    {
1607        abspath = sdscat(abspath, b"/\0" as *const u8 as *const libc::c_char);
1608    }
1609    while sdslen(relpath) >= 3 as libc::c_int as libc::c_ulong
1610        && *relpath.offset(0 as libc::c_int as isize) as libc::c_int == '.' as i32
1611        && *relpath.offset(1 as libc::c_int as isize) as libc::c_int == '.' as i32
1612        && *relpath.offset(2 as libc::c_int as isize) as libc::c_int == '/' as i32
1613    {
1614        sdsrange(relpath, 3 as libc::c_int as ssize_t, -(1 as libc::c_int) as ssize_t);
1615        if sdslen(abspath) > 1 as libc::c_int as libc::c_ulong {
1616            let mut p: *mut libc::c_char = abspath
1617                .offset(sdslen(abspath) as isize)
1618                .offset(-(2 as libc::c_int as isize));
1619            let mut trimlen: libc::c_int = 1 as libc::c_int;
1620            while *p as libc::c_int != '/' as i32 {
1621                p = p.offset(-1);
1622                trimlen += 1;
1623            }
1624            sdsrange(
1625                abspath,
1626                0 as libc::c_int as ssize_t,
1627                -(trimlen + 1 as libc::c_int) as ssize_t,
1628            );
1629        }
1630    }
1631    abspath = sdscatsds(abspath, relpath);
1632    sdsfree(relpath);
1633    return abspath;
1634}
1635#[no_mangle]
1636pub unsafe extern "C" fn getTimeZone() -> libc::c_long {
1637    return timezone;
1638}
1639#[no_mangle]
1640pub unsafe extern "C" fn pathIsBaseName(mut path: *mut libc::c_char) -> libc::c_int {
1641    return ((strchr(path, '/' as i32)).is_null()
1642        && (strchr(path, '\\' as i32)).is_null()) as libc::c_int;
1643}
1644#[no_mangle]
1645pub unsafe extern "C" fn fileExist(mut filename: *mut libc::c_char) -> libc::c_int {
1646    let mut statbuf: stat = stat {
1647        st_dev: 0,
1648        st_ino: 0,
1649        st_mode: 0,
1650        st_nlink: 0,
1651        st_uid: 0,
1652        st_gid: 0,
1653        st_rdev: 0,
1654        __pad1: 0,
1655        st_size: 0,
1656        st_blksize: 0,
1657        __pad2: 0,
1658        st_blocks: 0,
1659        st_atim: timespec { tv_sec: 0, tv_nsec: 0 },
1660        st_mtim: timespec { tv_sec: 0, tv_nsec: 0 },
1661        st_ctim: timespec { tv_sec: 0, tv_nsec: 0 },
1662        __glibc_reserved: [0; 2],
1663    };
1664    return (stat(filename, &mut statbuf) == 0 as libc::c_int
1665        && statbuf.st_mode & 0o170000 as libc::c_int as libc::c_uint
1666            == 0o100000 as libc::c_int as libc::c_uint) as libc::c_int;
1667}
1668#[no_mangle]
1669pub unsafe extern "C" fn dirExists(mut dname: *mut libc::c_char) -> libc::c_int {
1670    let mut statbuf: stat = stat {
1671        st_dev: 0,
1672        st_ino: 0,
1673        st_mode: 0,
1674        st_nlink: 0,
1675        st_uid: 0,
1676        st_gid: 0,
1677        st_rdev: 0,
1678        __pad1: 0,
1679        st_size: 0,
1680        st_blksize: 0,
1681        __pad2: 0,
1682        st_blocks: 0,
1683        st_atim: timespec { tv_sec: 0, tv_nsec: 0 },
1684        st_mtim: timespec { tv_sec: 0, tv_nsec: 0 },
1685        st_ctim: timespec { tv_sec: 0, tv_nsec: 0 },
1686        __glibc_reserved: [0; 2],
1687    };
1688    return (stat(dname, &mut statbuf) == 0 as libc::c_int
1689        && statbuf.st_mode & 0o170000 as libc::c_int as libc::c_uint
1690            == 0o40000 as libc::c_int as libc::c_uint) as libc::c_int;
1691}
1692#[no_mangle]
1693pub unsafe extern "C" fn dirCreateIfMissing(
1694    mut dname: *mut libc::c_char,
1695) -> libc::c_int {
1696    if mkdir(dname, 0o755 as libc::c_int as __mode_t) != 0 as libc::c_int {
1697        if *__errno_location() != 17 as libc::c_int {
1698            return -(1 as libc::c_int)
1699        } else {
1700            if dirExists(dname) == 0 {
1701                *__errno_location() = 20 as libc::c_int;
1702                return -(1 as libc::c_int);
1703            }
1704        }
1705    }
1706    return 0 as libc::c_int;
1707}
1708#[no_mangle]
1709pub unsafe extern "C" fn dirRemove(mut dname: *mut libc::c_char) -> libc::c_int {
1710    let mut dir: *mut DIR = 0 as *mut DIR;
1711    let mut stat_entry: stat = stat {
1712        st_dev: 0,
1713        st_ino: 0,
1714        st_mode: 0,
1715        st_nlink: 0,
1716        st_uid: 0,
1717        st_gid: 0,
1718        st_rdev: 0,
1719        __pad1: 0,
1720        st_size: 0,
1721        st_blksize: 0,
1722        __pad2: 0,
1723        st_blocks: 0,
1724        st_atim: timespec { tv_sec: 0, tv_nsec: 0 },
1725        st_mtim: timespec { tv_sec: 0, tv_nsec: 0 },
1726        st_ctim: timespec { tv_sec: 0, tv_nsec: 0 },
1727        __glibc_reserved: [0; 2],
1728    };
1729    let mut entry: *mut dirent = 0 as *mut dirent;
1730    let mut full_path: [libc::c_char; 4097] = [0; 4097];
1731    dir = opendir(dname);
1732    if dir.is_null() {
1733        return -(1 as libc::c_int);
1734    }
1735    loop {
1736        entry = readdir(dir);
1737        if entry.is_null() {
1738            break;
1739        }
1740        if strcmp(
1741            ((*entry).d_name).as_mut_ptr(),
1742            b".\0" as *const u8 as *const libc::c_char,
1743        ) == 0
1744            || strcmp(
1745                ((*entry).d_name).as_mut_ptr(),
1746                b"..\0" as *const u8 as *const libc::c_char,
1747            ) == 0
1748        {
1749            continue;
1750        }
1751        snprintf(
1752            full_path.as_mut_ptr(),
1753            core::mem::size_of::<[libc::c_char; 4097]>() as libc::c_ulong,
1754            b"%s/%s\0" as *const u8 as *const libc::c_char,
1755            dname,
1756            ((*entry).d_name).as_mut_ptr(),
1757        );
1758        let mut fd: libc::c_int = open(
1759            full_path.as_mut_ptr(),
1760            0 as libc::c_int | 0o4000 as libc::c_int,
1761        );
1762        if fd == -(1 as libc::c_int) {
1763            closedir(dir);
1764            return -(1 as libc::c_int);
1765        }
1766        if fstat(fd, &mut stat_entry) == -(1 as libc::c_int) {
1767            close(fd);
1768            closedir(dir);
1769            return -(1 as libc::c_int);
1770        }
1771        close(fd);
1772        if (stat_entry.st_mode & 0o170000 as libc::c_int as libc::c_uint
1773            == 0o40000 as libc::c_int as libc::c_uint) as libc::c_int != 0 as libc::c_int
1774        {
1775            if dirRemove(full_path.as_mut_ptr()) == -(1 as libc::c_int) {
1776                return -(1 as libc::c_int);
1777            }
1778        } else if unlink(full_path.as_mut_ptr()) != 0 as libc::c_int {
1779            closedir(dir);
1780            return -(1 as libc::c_int);
1781        }
1782    }
1783    if rmdir(dname) != 0 as libc::c_int {
1784        closedir(dir);
1785        return -(1 as libc::c_int);
1786    }
1787    closedir(dir);
1788    return 0 as libc::c_int;
1789}
1790#[no_mangle]
1791pub unsafe extern "C" fn makePath(
1792    mut path: *mut libc::c_char,
1793    mut filename: *mut libc::c_char,
1794) -> sds {
1795    return sdscatfmt(
1796        sdsempty(),
1797        b"%s/%s\0" as *const u8 as *const libc::c_char,
1798        path,
1799        filename,
1800    );
1801}
1802#[no_mangle]
1803pub unsafe extern "C" fn fsyncFileDir(mut filename: *const libc::c_char) -> libc::c_int {
1804    let mut temp_filename: [libc::c_char; 4097] = [0; 4097];
1805    let mut dname: *mut libc::c_char = 0 as *mut libc::c_char;
1806    let mut dir_fd: libc::c_int = 0;
1807    if strlen(filename) > 4096 as libc::c_int as libc::c_ulong {
1808        *__errno_location() = 36 as libc::c_int;
1809        return -(1 as libc::c_int);
1810    }
1811    memcpy(
1812        temp_filename.as_mut_ptr() as *mut libc::c_void,
1813        filename as *const libc::c_void,
1814        (strlen(filename)).wrapping_add(1 as libc::c_int as libc::c_ulong),
1815    );
1816    dname = dirname(temp_filename.as_mut_ptr());
1817    dir_fd = open(dname, 0 as libc::c_int);
1818    if dir_fd == -(1 as libc::c_int) {
1819        if *__errno_location() == 21 as libc::c_int {
1820            return 0 as libc::c_int;
1821        }
1822        return -(1 as libc::c_int);
1823    }
1824    if fdatasync(dir_fd) == -(1 as libc::c_int)
1825        && !(*__errno_location() == 9 as libc::c_int
1826            || *__errno_location() == 22 as libc::c_int)
1827    {
1828        let mut save_errno: libc::c_int = *__errno_location();
1829        close(dir_fd);
1830        *__errno_location() = save_errno;
1831        return -(1 as libc::c_int);
1832    }
1833    close(dir_fd);
1834    return 0 as libc::c_int;
1835}