]> FriiDump Source - friidump.git/blob - libfriidump/win32compat.c
FriiDump 0.5.3.16 candidate: add native reports and Linux Xbox support
[friidump.git] / libfriidump / win32compat.c
1 /***************************************************************************
2  *   Copyright (C) 2007 by Arep                                            *
3  *   Support is provided through the forums at                             *
4  *   http://www.console-tribe.com                                          *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  *   This program is distributed in the hope that it will be useful,       *
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14  *   GNU General Public License for more details.                          *
15  *                                                                         *
16  *   You should have received a copy of the GNU General Public License     *
17  *   along with this program; if not, write to the                         *
18  *   Free Software Foundation, Inc.,                                       *
19  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
20  ***************************************************************************/
21
22
23 #ifdef WIN32
24
25 #include "win32compat.h"
26 #include <stdio.h>
27 #include <windows.h>
28 #include <io.h>
29 #include <sys/timeb.h>
30
31
32 char *strndup (const char *src, int c) {
33     char *dest;
34
35     if ((dest = (char *) malloc ((c + 1) * sizeof (char)))) {
36         memcpy (dest, src, c);
37         dest[c] = '\0';
38     }
39
40     return (dest);
41 }
42
43
44 int ftruncate (int fd, __int64 size) {
45         return (_chsize_s (fd, size));
46 }
47
48
49
50 /* The following gettimeofday() replacement function was taken from Snort, GPLv2 */
51 /****************************************************************************
52  *
53  * Function: gettimeofday(struct timeval *, struct timezone *)
54  *
55  * Purpose:  Get current time of day.
56  *
57  * Arguments: tv => Place to store the curent time of day.
58  *            tz => Ignored.
59  *
60  * Returns: 0 => Success.
61  *
62  ****************************************************************************/
63 int gettimeofday(struct timeval *tv, struct timezone *tz) {
64     struct _timeb tb;
65
66     if (tv == NULL) {
67         return -1;
68     }
69     _ftime(&tb);
70     tv->tv_sec = (long) tb.time;
71     tv->tv_usec = ((int) tb.millitm) * 1000;
72     return 0;
73 }
74
75 #endif