]> git.sesse.net Git - ffmpeg/blob - libavformat/os_support.c
* Fixing a bug with incorrect bits set in AAUX source pack
[ffmpeg] / libavformat / os_support.c
1 /*
2  * Various utilities for ffmpeg system
3  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4  * copyright (c) 2002 Francois Revol
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #include "config.h"
23 #include "avformat.h"
24 #if defined(CONFIG_WINCE)
25 /* Skip includes on WinCE. */
26 #elif defined(__MINGW32__)
27 #include <sys/types.h>
28 #include <sys/timeb.h>
29 #elif defined(CONFIG_OS2)
30 #include <string.h>
31 #include <sys/time.h>
32 #else
33 #include <unistd.h>
34 #include <fcntl.h>
35 #include <sys/time.h>
36 #endif
37 #include <time.h>
38
39 /**
40  * gets the current time in micro seconds.
41  */
42 int64_t av_gettime(void)
43 {
44 #if defined(CONFIG_WINCE)
45     return timeGetTime() * INT64_C(1000);
46 #elif defined(__MINGW32__)
47     struct timeb tb;
48     _ftime(&tb);
49     return ((int64_t)tb.time * INT64_C(1000) + (int64_t)tb.millitm) * INT64_C(1000);
50 #else
51     struct timeval tv;
52     gettimeofday(&tv,NULL);
53     return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
54 #endif
55 }
56
57 #if !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R)
58 struct tm *localtime_r(const time_t *t, struct tm *tp)
59 {
60     struct tm *l;
61
62     l = localtime(t);
63     if (!l)
64         return 0;
65     *tp = *l;
66     return tp;
67 }
68 #endif /* !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R) */
69
70 #if !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK)
71 #include <stdlib.h>
72 #include <strings.h>
73 #include "barpainet.h"
74
75 int inet_aton (const char * str, struct in_addr * add)
76 {
77     const char * pch = str;
78     unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0;
79
80     add1 = atoi(pch);
81     pch = strpbrk(pch,".");
82     if (pch == 0 || ++pch == 0) goto done;
83     add2 = atoi(pch);
84     pch = strpbrk(pch,".");
85     if (pch == 0 || ++pch == 0) goto done;
86     add3 = atoi(pch);
87     pch = strpbrk(pch,".");
88     if (pch == 0 || ++pch == 0) goto done;
89     add4 = atoi(pch);
90
91 done:
92     add->s_addr=(add4<<24)+(add3<<16)+(add2<<8)+add1;
93
94     return 1;
95 }
96 #endif /* !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK) */