summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2009-06-12 16:35:34 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2009-06-12 16:35:34 +0000
commit11fa12c366a0d33b198fea657dca18bc9d658b61 (patch)
tree11ea8b241b5c4b962ad3b7f1d6a4fc072aa0c82a
parent1240216a7581adf9dd018282e33bd6261934f4c2 (diff)
downloadrockbox-11fa12c366a0d33b198fea657dca18bc9d658b61.tar.gz
rockbox-11fa12c366a0d33b198fea657dca18bc9d658b61.zip
Implement sendfirm functionality in beastpatcher. Set svn:eol-style properties.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21260 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--utils/MTP/beastpatcher/Makefile12
-rw-r--r--utils/MTP/beastpatcher/README.pstdint14
-rw-r--r--utils/MTP/beastpatcher/beastpatcher.c41
-rw-r--r--utils/MTP/beastpatcher/beastpatcher.h45
-rw-r--r--utils/MTP/beastpatcher/main.c93
-rw-r--r--utils/MTP/beastpatcher/mtp_common.h1
-rw-r--r--utils/MTP/beastpatcher/mtp_libmtp.c58
-rw-r--r--utils/MTP/beastpatcher/mtp_win32.c410
-rw-r--r--utils/MTP/beastpatcher/pstdint.h1598
-rw-r--r--utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj8
10 files changed, 1241 insertions, 1039 deletions
diff --git a/utils/MTP/beastpatcher/Makefile b/utils/MTP/beastpatcher/Makefile
index 9c3ed571ee..5f3951d8be 100644
--- a/utils/MTP/beastpatcher/Makefile
+++ b/utils/MTP/beastpatcher/Makefile
@@ -30,22 +30,22 @@ CC = $(CROSS)gcc
30 30
31all: $(OUTPUT) 31all: $(OUTPUT)
32 32
33beastpatcher: beastpatcher.c bootimg.c mtp_common.h mtp_libmtp.c 33beastpatcher: beastpatcher.c bootimg.c mtp_common.h mtp_libmtp.c main.c
34 gcc $(CFLAGS) -o beastpatcher beastpatcher.c bootimg.c mtp_libmtp.c $(LIBS) 34 gcc $(CFLAGS) -o beastpatcher beastpatcher.c bootimg.c mtp_libmtp.c main.c $(LIBS)
35 strip beastpatcher 35 strip beastpatcher
36 36
37beastpatcher.exe: beastpatcher.c bootimg.c mtp_common.h mtp_win32.c $(WINLIBS) 37beastpatcher.exe: beastpatcher.c bootimg.c mtp_common.h mtp_win32.c main.c $(WINLIBS)
38 $(CC) $(CFLAGS) -o beastpatcher.exe beastpatcher.c bootimg.c mtp_win32.c $(WINLIBS) 38 $(CC) $(CFLAGS) -o beastpatcher.exe beastpatcher.c bootimg.c mtp_win32.c main.c $(WINLIBS)
39 $(CROSS)strip beastpatcher.exe 39 $(CROSS)strip beastpatcher.exe
40 40
41beastpatcher-mac: beastpatcher-i386 beastpatcher-ppc 41beastpatcher-mac: beastpatcher-i386 beastpatcher-ppc
42 lipo -create beastpatcher-ppc beastpatcher-i386 -output beastpatcher-mac 42 lipo -create beastpatcher-ppc beastpatcher-i386 -output beastpatcher-mac
43 43
44beastpatcher-i386: beastpatcher.c bootimg.c usb.h libusb-i386.a 44beastpatcher-i386: beastpatcher.c bootimg.c usb.h main.c libusb-i386.a
45 $(CC) -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -framework iokit -framework coreservices -arch i386 $(CFLAGS) -o beastpatcher-i386 beastpatcher.c bootimg.c -I. libusb-i386.a 45 $(CC) -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -framework iokit -framework coreservices -arch i386 $(CFLAGS) -o beastpatcher-i386 beastpatcher.c bootimg.c -I. libusb-i386.a
46 strip beastpatcher-i386 46 strip beastpatcher-i386
47 47
48beastpatcher-ppc: beastpatcher.c bootimg.c usb.h libusb-ppc.a 48beastpatcher-ppc: beastpatcher.c bootimg.c usb.h main.c libusb-ppc.a
49 $(CC) -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -framework iokit -framework coreservices -arch ppc $(CFLAGS) -o beastpatcher-ppc beastpatcher.c bootimg.c -I. libusb-ppc.a 49 $(CC) -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -framework iokit -framework coreservices -arch ppc $(CFLAGS) -o beastpatcher-ppc beastpatcher.c bootimg.c -I. libusb-ppc.a
50 strip beastpatcher-ppc 50 strip beastpatcher-ppc
51 51
diff --git a/utils/MTP/beastpatcher/README.pstdint b/utils/MTP/beastpatcher/README.pstdint
index 8dacc44fe2..259760f81d 100644
--- a/utils/MTP/beastpatcher/README.pstdint
+++ b/utils/MTP/beastpatcher/README.pstdint
@@ -1,7 +1,7 @@
1pstdint.h: A portable stdint.h 1pstdint.h: A portable stdint.h
2 2
3This file is taken from http://www.azillionmonkeys.com/qed/pstdint.h 3This file is taken from http://www.azillionmonkeys.com/qed/pstdint.h
4 4
5Copyright (c) 2005-2007 Paul Hsieh 5Copyright (c) 2005-2007 Paul Hsieh
6Licensed under the BSD License. See file header for details. 6Licensed under the BSD License. See file header for details.
7 7
diff --git a/utils/MTP/beastpatcher/beastpatcher.c b/utils/MTP/beastpatcher/beastpatcher.c
index 783b11f202..f0d9394f11 100644
--- a/utils/MTP/beastpatcher/beastpatcher.c
+++ b/utils/MTP/beastpatcher/beastpatcher.c
@@ -55,18 +55,6 @@
55#include "mtp_common.h" 55#include "mtp_common.h"
56#include "bootimg.h" 56#include "bootimg.h"
57 57
58#define VERSION "1.0 with v1 bootloader"
59
60void print_usage(void)
61{
62 fprintf(stderr,"Usage: beastpatcher [action]\n");
63 fprintf(stderr,"\n");
64 fprintf(stderr,"Where [action] is one of the following options:\n");
65 fprintf(stderr," --install (default)\n");
66 fprintf(stderr," -?, --help\n");
67 fprintf(stderr,"\n");
68}
69
70/* Code to create a single-boot bootloader. 58/* Code to create a single-boot bootloader.
71 Based on tools/gigabeats.c by Will Robertson. 59 Based on tools/gigabeats.c by Will Robertson.
72*/ 60*/
@@ -139,27 +127,13 @@ static void create_single_boot(unsigned char* boot, int bootlen,
139 return; 127 return;
140} 128}
141 129
142int beastpatcher(int argc, char* argv[]) 130int beastpatcher(void)
143{ 131{
144 char yesno[4]; 132 char yesno[4];
145 unsigned char* fwbuf; 133 unsigned char* fwbuf;
146 int fwsize; 134 int fwsize;
147 struct mtp_info_t mtp_info; 135 struct mtp_info_t mtp_info;
148 136
149 (void)argv;
150
151 fprintf(stderr,"beastpatcher v" VERSION " - (C) 2009 by the Rockbox developers\n");
152 fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n");
153 fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
154
155 /* No options are currently implemented, so just display help if any are
156 provided. */
157
158 if (argc > 1) {
159 print_usage();
160 return 1;
161 }
162
163 if (mtp_init(&mtp_info) < 0) { 137 if (mtp_init(&mtp_info) < 0) {
164 fprintf(stderr,"[ERR] Can not init MTP\n"); 138 fprintf(stderr,"[ERR] Can not init MTP\n");
165 return 1; 139 return 1;
@@ -212,16 +186,3 @@ int beastpatcher(int argc, char* argv[])
212 return 0; 186 return 0;
213} 187}
214 188
215
216int main(int argc, char* argv[])
217{
218 int res;
219 char yesno[4];
220
221 res = beastpatcher(argc, argv);
222
223 printf("\nPress ENTER to exit beastpatcher: ");
224 fgets(yesno,4,stdin);
225
226 return res;
227}
diff --git a/utils/MTP/beastpatcher/beastpatcher.h b/utils/MTP/beastpatcher/beastpatcher.h
new file mode 100644
index 0000000000..c73ae910be
--- /dev/null
+++ b/utils/MTP/beastpatcher/beastpatcher.h
@@ -0,0 +1,45 @@
1/*
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * $Id$
10 *
11 * Copyright (c) 2009, Dave Chapman
12 * All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met:
17 *
18 * * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * * Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials provided
24 * with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 ****************************************************************************/
39
40#ifndef BEASTPATCHER_H
41#define BEASTPATCHER_H
42
43int beastpatcher(void);
44
45#endif
diff --git a/utils/MTP/beastpatcher/main.c b/utils/MTP/beastpatcher/main.c
new file mode 100644
index 0000000000..56d1a1e94c
--- /dev/null
+++ b/utils/MTP/beastpatcher/main.c
@@ -0,0 +1,93 @@
1/*
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * $Id$
10 *
11 * Copyright (c) 2009, Dave Chapman
12 * All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met:
17 *
18 * * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * * Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials provided
24 * with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 ****************************************************************************/
39
40#include <stdio.h>
41#include "beastpatcher.h"
42#include "mtp_common.h"
43
44#if defined(__WIN32__) || defined(_WIN32)
45#include <windows.h>
46#endif
47
48#define VERSION "1.0 with v1 bootloader"
49
50#include "../MTP_DLL/MTP_DLL.h"
51
52static void print_usage(void)
53{
54 fprintf(stderr,"Usage: beastpatcher [action]\n");
55 fprintf(stderr,"\n");
56 fprintf(stderr,"Where [action] is one of the following options:\n");
57 fprintf(stderr," -i, --install (default)\n");
58 fprintf(stderr," -h, --help\n");
59 fprintf(stderr," -s, --send nk.bin\n");
60 fprintf(stderr,"\n");
61}
62
63
64int main(int argc, char* argv[])
65{
66 int res;
67 char yesno[4];
68 struct mtp_info_t mtp_info;
69
70 fprintf(stderr,"beastpatcher v" VERSION " - (C) 2009 by the Rockbox developers\n");
71 fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n");
72 fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
73
74 if(argc == 1 || strcmp(argv[1],"-i")==0 || strcmp(argv[1],"--install")==0) {
75 res = beastpatcher();
76 /* don't ask for enter if started with command line arguments */
77 if(argc == 1) {
78 printf("\nPress ENTER to exit beastpatcher: ");
79 fgets(yesno,4,stdin);
80 }
81 }
82 else if((argc > 2) && ((strcmp(argv[1],"-s")==0) || (strcmp(argv[1],"--send")==0))) {
83 res = mtp_send_file(&mtp_info, argv[2]);
84 }
85 else {
86 print_usage();
87 res = -1;
88 }
89
90 return res;
91}
92
93
diff --git a/utils/MTP/beastpatcher/mtp_common.h b/utils/MTP/beastpatcher/mtp_common.h
index 4b60fa08da..2ca87c7509 100644
--- a/utils/MTP/beastpatcher/mtp_common.h
+++ b/utils/MTP/beastpatcher/mtp_common.h
@@ -66,5 +66,6 @@ int mtp_finished(struct mtp_info_t* mtp_info);
66int mtp_scan(struct mtp_info_t* mtp_info); 66int mtp_scan(struct mtp_info_t* mtp_info);
67int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf, 67int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
68 int fwsize); 68 int fwsize);
69int mtp_send_file(struct mtp_info_t* mtp_info, const char* filename);
69 70
70#endif /* !_MTP_COMMON_H */ 71#endif /* !_MTP_COMMON_H */
diff --git a/utils/MTP/beastpatcher/mtp_libmtp.c b/utils/MTP/beastpatcher/mtp_libmtp.c
index c29e5277b2..90477fb0e7 100644
--- a/utils/MTP/beastpatcher/mtp_libmtp.c
+++ b/utils/MTP/beastpatcher/mtp_libmtp.c
@@ -47,6 +47,8 @@
47#include "libmtp.h" 47#include "libmtp.h"
48#include "mtp_common.h" 48#include "mtp_common.h"
49 49
50static int mtp_send_fileptr(struct mtp_info_t* mtp_info, FILE* fwfile, size_t fwsize);
51
50int mtp_init(struct mtp_info_t* mtp_info) 52int mtp_init(struct mtp_info_t* mtp_info)
51{ 53{
52 /* Fill the info struct with zeros - mainly for the strings */ 54 /* Fill the info struct with zeros - mainly for the strings */
@@ -74,8 +76,8 @@ int mtp_scan(struct mtp_info_t* mtp_info)
74 if (mtp_info->device == NULL) 76 if (mtp_info->device == NULL)
75 { 77 {
76 return -1; 78 return -1;
77 } 79 }
78 else 80 else
79 { 81 {
80 /* NOTE: These strings are filled with zeros in mtp_init() */ 82 /* NOTE: These strings are filled with zeros in mtp_init() */
81#ifndef REALLYOLDMTP 83#ifndef REALLYOLDMTP
@@ -117,7 +119,6 @@ static int progress(uint64_t const sent, uint64_t const total,
117int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf, 119int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
118 int fwsize) 120 int fwsize)
119{ 121{
120 LIBMTP_file_t *genfile;
121 int ret; 122 int ret;
122 size_t n; 123 size_t n;
123 FILE* fwfile; 124 FILE* fwfile;
@@ -142,6 +143,20 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
142 /* Reset file pointer */ 143 /* Reset file pointer */
143 fseek(fwfile, SEEK_SET, 0); 144 fseek(fwfile, SEEK_SET, 0);
144 145
146 ret = mtp_send_fileptr(mtp_info, fwfile, fwsize);
147
148 /* Close the temporary file - this also deletes it. */
149 fclose(fwfile);
150
151 return 0;
152}
153
154
155static int mtp_send_fileptr(struct mtp_info_t* mtp_info, FILE* fwfile, size_t fwsize)
156{
157 LIBMTP_file_t* genfile;
158 int ret;
159
145 /* Prepare for uploading firmware */ 160 /* Prepare for uploading firmware */
146 genfile = LIBMTP_new_file_t(); 161 genfile = LIBMTP_new_file_t();
147 genfile->filetype = LIBMTP_FILETYPE_FIRMWARE; 162 genfile->filetype = LIBMTP_FILETYPE_FIRMWARE;
@@ -149,10 +164,10 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
149 genfile->filesize = fwsize; 164 genfile->filesize = fwsize;
150 165
151#ifdef OLDMTP 166#ifdef OLDMTP
152 ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device, 167 ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device,
153 fileno(fwfile), genfile, progress, NULL, 0); 168 fileno(fwfile), genfile, progress, NULL, 0);
154#else 169#else
155 ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device, 170 ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device,
156 fileno(fwfile), genfile, progress, NULL); 171 fileno(fwfile), genfile, progress, NULL);
157#endif 172#endif
158 173
@@ -167,8 +182,35 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
167 /* Cleanup */ 182 /* Cleanup */
168 LIBMTP_destroy_file_t(genfile); 183 LIBMTP_destroy_file_t(genfile);
169 184
170 /* Close the temporary file - this also deletes it. */ 185 return ret;
171 fclose(fwfile); 186}
172 187
173 return 0; 188
189int mtp_send_file(struct mtp_info_t* mtp_info, const char* filename)
190{
191 FILE* fwfile;
192 int ret;
193#ifdef _LARGEFILE64_SOURCE
194 struct stat64 sb;
195 ret = stat64(filename, &sb);
196#else
197 struct stat sb;
198 ret = stat(filename, &sb);
199#endif
200 if (ret == -1)
201 {
202 perror("[ERR] ");
203 }
204
205 fwfile = fopen(filename, "r");
206 if (fwfile == NULL)
207 {
208 fprintf(stderr,"[ERR] Could not create temporary file.\n");
209 return -1;
210 }
211 ret = mtp_send_fileptr(mtp_info, fwfile, sb.st_size);
212
213 fclose(fwfile);
214 return ret;
174} 215}
216
diff --git a/utils/MTP/beastpatcher/mtp_win32.c b/utils/MTP/beastpatcher/mtp_win32.c
index ced930ab80..1d6105f4fa 100644
--- a/utils/MTP/beastpatcher/mtp_win32.c
+++ b/utils/MTP/beastpatcher/mtp_win32.c
@@ -1,179 +1,231 @@
1/*************************************************************************** 1/***************************************************************************
2 * __________ __ ___. 2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * 8 *
9 * $Id$ 9 * $Id$
10 * 10 *
11 * Copyright (c) 2009, Dave Chapman 11 * Copyright (c) 2009, Dave Chapman
12 * All rights reserved. 12 * All rights reserved.
13 * 13 *
14 * Redistribution and use in source and binary forms, with or without 14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are 15 * modification, are permitted provided that the following conditions are
16 * met: 16 * met:
17 * 17 *
18 * * Redistributions of source code must retain the above copyright 18 * * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer. 19 * notice, this list of conditions and the following disclaimer.
20 * 20 *
21 * * Redistributions in binary form must reproduce the above 21 * * Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following 22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials provided 23 * disclaimer in the documentation and/or other materials provided
24 * with the distribution. 24 * with the distribution.
25 * 25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * 37 *
38 * 38 *
39 ****************************************************************************/ 39 ****************************************************************************/
40 40
41#include <stdio.h> 41#include <stdio.h>
42#include <string.h> 42#include <string.h>
43#include <stddef.h> 43#include <stddef.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <wchar.h> 45#include <wchar.h>
46#include <windows.h> 46#include <windows.h>
47#include <tchar.h> 47#include <sys/types.h>
48 48#include <sys/stat.h>
49#include "mtp_common.h" 49#include <tchar.h>
50 50
51#include "../MTP_DLL/MTP_DLL.h" 51#include "mtp_common.h"
52 52
53int mtp_init(struct mtp_info_t* mtp_info) 53#include "../MTP_DLL/MTP_DLL.h"
54{ 54
55 /* Fill the info struct with zeros - mainly for the strings */ 55
56 memset(mtp_info, 0, sizeof(struct mtp_info_t)); 56static int filesize(const char* filename);
57 57
58 return 0; 58
59 59int mtp_init(struct mtp_info_t* mtp_info)
60} 60{
61 61 /* Fill the info struct with zeros - mainly for the strings */
62int mtp_finished(struct mtp_info_t* mtp_info) 62 memset(mtp_info, 0, sizeof(struct mtp_info_t));
63{ 63
64 (void)mtp_info; 64 return 0;
65 65
66 return 0; 66}
67} 67
68 68int mtp_finished(struct mtp_info_t* mtp_info)
69int mtp_scan(struct mtp_info_t* mtp_info) 69{
70{ 70 (void)mtp_info;
71 wchar_t name[256]; 71
72 wchar_t manufacturer[256]; 72 return 0;
73 DWORD version; 73}
74 int num = 0; 74
75 75int mtp_scan(struct mtp_info_t* mtp_info)
76 num = mtp_description(name, manufacturer, &version); 76{
77 77 wchar_t name[256];
78 wcstombs(mtp_info->manufacturer, manufacturer, 200); 78 wchar_t manufacturer[256];
79 wcstombs(mtp_info->modelname, name, 200); 79 DWORD version;
80 80 int num = 0;
81 sprintf(mtp_info->version, "%x", (unsigned int)version); 81
82 return (num > 0) ? num : -1; 82 num = mtp_description(name, manufacturer, &version);
83 83
84} 84 wcstombs(mtp_info->manufacturer, manufacturer, 200);
85 85 wcstombs(mtp_info->modelname, name, 200);
86static void callback(unsigned int progress, unsigned int max) 86
87{ 87 sprintf(mtp_info->version, "%x", (unsigned int)version);
88 int percent = (progress * 100) / max; 88 return (num > 0) ? num : -1;
89 89
90 printf("Progress: %u of %u (%d%%)\r", progress, max, percent); 90}
91 fflush(stdout); 91
92} 92static void callback(unsigned int progress, unsigned int max)
93 93{
94 94 int percent = (progress * 100) / max;
95int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf, 95
96 int fwsize) 96 printf("[INFO] Progress: %u of %u (%d%%)\r", progress, max, percent);
97{ 97 fflush(stdout);
98 HANDLE hTempFile; 98}
99 DWORD dwRetVal; 99
100 DWORD dwBytesWritten; 100
101 UINT uRetVal; 101int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
102 TCHAR szTempName[1024]; 102 int fwsize)
103 TCHAR lpPathBuffer[1024]; 103{
104 BOOL fSuccess; 104 HANDLE hTempFile;
105 wchar_t *tmp; 105 DWORD dwRetVal;
106 int ret; 106 DWORD dwBytesWritten;
107 107 UINT uRetVal;
108 (void)mtp_info; 108 TCHAR szTempName[1024];
109 109 TCHAR lpPathBuffer[1024];
110 /* Get the path for temporary files */ 110 BOOL fSuccess;
111 dwRetVal = GetTempPath(sizeof(lpPathBuffer), lpPathBuffer); 111 wchar_t *tmp;
112 if (dwRetVal > sizeof(lpPathBuffer) || (dwRetVal == 0)) 112 int ret;
113 { 113
114 fprintf(stderr, "[ERR] GetTempPath failed (%d)\n", (int)GetLastError()); 114 (void)mtp_info;
115 return -1; 115
116 } 116 /* Get the path for temporary files */
117 117 dwRetVal = GetTempPath(sizeof(lpPathBuffer), lpPathBuffer);
118 /* Create the temporary file */ 118 if (dwRetVal > sizeof(lpPathBuffer) || (dwRetVal == 0))
119 uRetVal = GetTempFileName(lpPathBuffer, TEXT("NKBIN"), 0, szTempName); 119 {
120 if (uRetVal == 0) 120 fprintf(stderr, "[ERR] GetTempPath failed (%d)\n", (int)GetLastError());
121 { 121 return -1;
122 fprintf(stderr, "[ERR] GetTempFileName failed (%d)\n", (int)GetLastError()); 122 }
123 return -1; 123
124 } 124 /* Create the temporary file */
125 125 uRetVal = GetTempFileName(lpPathBuffer, TEXT("NKBIN"), 0, szTempName);
126 /* Now create the file */ 126 if (uRetVal == 0)
127 hTempFile = CreateFile((LPTSTR) szTempName, // file name 127 {
128 GENERIC_READ | GENERIC_WRITE, // open r-w 128 fprintf(stderr, "[ERR] GetTempFileName failed (%d)\n", (int)GetLastError());
129 0, // do not share 129 return -1;
130 NULL, // default security 130 }
131 CREATE_ALWAYS, // overwrite existing 131
132 FILE_ATTRIBUTE_NORMAL,// normal file 132 /* Now create the file */
133 NULL); // no template 133 hTempFile = CreateFile((LPTSTR) szTempName, // file name
134 if (hTempFile == INVALID_HANDLE_VALUE) 134 GENERIC_READ | GENERIC_WRITE, // open r-w
135 { 135 0, // do not share
136 fprintf(stderr, "[ERR] Could not create %s\n", szTempName); 136 NULL, // default security
137 return -1; 137 CREATE_ALWAYS, // overwrite existing
138 } 138 FILE_ATTRIBUTE_NORMAL,// normal file
139 139 NULL); // no template
140 fSuccess = WriteFile(hTempFile, fwbuf, fwsize, &dwBytesWritten, NULL); 140 if (hTempFile == INVALID_HANDLE_VALUE)
141 if (!fSuccess) 141 {
142 { 142 fprintf(stderr, "[ERR] Could not create %s\n", szTempName);
143 fprintf(stderr, "[ERR] WriteFile failed (%d)\n", (int)GetLastError()); 143 return -1;
144 return -1; 144 }
145 } 145
146 146 fSuccess = WriteFile(hTempFile, fwbuf, fwsize, &dwBytesWritten, NULL);
147 fSuccess = CloseHandle (hTempFile); 147 if (!fSuccess)
148 if (!fSuccess) 148 {
149 { 149 fprintf(stderr, "[ERR] WriteFile failed (%d)\n", (int)GetLastError());
150 fprintf(stderr, "[ERR] CloseHandle failed (%d)\n", (int)GetLastError()); 150 return -1;
151 return -1; 151 }
152 } 152
153 153 fSuccess = CloseHandle (hTempFile);
154 tmp = (LPWSTR)malloc(_tcslen(szTempName)*2+1); 154 if (!fSuccess)
155 mbstowcs(tmp, (char*)szTempName, _tcslen(szTempName)*2+1); 155 {
156 156 fprintf(stderr, "[ERR] CloseHandle failed (%d)\n", (int)GetLastError());
157 fprintf(stderr, "[INFO] Sending firmware...\n"); 157 return -1;
158 if (mtp_sendnk(tmp, fwsize, &callback)) 158 }
159 { 159
160 fprintf(stderr, "[INFO] Firmware sent successfully\n"); 160 tmp = (LPWSTR)malloc(_tcslen(szTempName)*2+1);
161 ret = 0; 161 mbstowcs(tmp, (char*)szTempName, _tcslen(szTempName)*2+1);
162 } 162
163 else 163 fprintf(stderr, "[INFO] Sending firmware...\n");
164 { 164 if (mtp_sendnk(tmp, fwsize, &callback))
165 fprintf(stderr, "[ERR] Error occured during sending.\n"); 165 {
166 ret = -1; 166 fprintf(stderr, "\n");
167 } 167 fprintf(stderr, "[INFO] Firmware sent successfully\n");
168 168 ret = 0;
169 /* Keep the progress line onscreen */ 169 }
170 printf("\n"); 170 else
171 171 {
172 free(tmp); 172 fprintf(stderr, "\n");
173 173 fprintf(stderr, "[ERR] Error occured during sending.\n");
174 if (!DeleteFile(szTempName)) 174 ret = -1;
175 fprintf(stderr,"[WARN] Could not remove temporary file %s\n",szTempName); 175 }
176 176 free(tmp);
177 return ret; 177
178} 178 if (!DeleteFile(szTempName))
179 179 fprintf(stderr,"[WARN] Could not remove temporary file %s\n",szTempName);
180
181 return ret;
182}
183
184
185int mtp_send_file(struct mtp_info_t* mtp_info, const char* filename)
186{
187 wchar_t *fn;
188
189 fn = (LPWSTR)malloc(strlen(filename)*2+1);
190 mbstowcs(fn, filename, strlen(filename)*2+1);
191
192 if (mtp_init(mtp_info) < 0) {
193 fprintf(stderr,"[ERR] Can not init MTP\n");
194 return 1;
195 }
196 /* Scan for attached MTP devices. */
197 if (mtp_scan(mtp_info) < 0)
198 {
199 fprintf(stderr,"[ERR] No devices found\n");
200 return 1;
201 }
202
203 fprintf(stderr, "[INFO] Sending firmware...\n");
204 if (mtp_sendnk(fn, filesize(filename), &callback))
205 {
206 /* keep progress on screen */
207 printf("\n");
208 fprintf(stderr, "[INFO] Firmware sent successfully\n");
209 return 0;
210 }
211 else
212 {
213 fprintf(stderr, "[ERR] Error occured during sending.\n");
214 return -1;
215 }
216 mtp_finished(mtp_info);
217}
218
219
220static int filesize(const char* filename)
221{
222 struct _stat sb;
223 int res;
224
225 res = _stat(filename, &sb);
226 if(res == -1) {
227 fprintf(stderr, "Error getting filesize!\n");
228 return -1;
229 }
230 return sb.st_size;
231}
diff --git a/utils/MTP/beastpatcher/pstdint.h b/utils/MTP/beastpatcher/pstdint.h
index 12c108a2e9..6a334bae98 100644
--- a/utils/MTP/beastpatcher/pstdint.h
+++ b/utils/MTP/beastpatcher/pstdint.h
@@ -1,799 +1,799 @@
1/* A portable stdint.h 1/* A portable stdint.h
2 **************************************************************************** 2 ****************************************************************************
3 * BSD License: 3 * BSD License:
4 **************************************************************************** 4 ****************************************************************************
5 * 5 *
6 * Copyright (c) 2005-2007 Paul Hsieh 6 * Copyright (c) 2005-2007 Paul Hsieh
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 12 *
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products 18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission. 19 * derived from this software without specific prior written permission.
20 * 20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * 31 *
32 **************************************************************************** 32 ****************************************************************************
33 * 33 *
34 * Version 0.1.11 34 * Version 0.1.11
35 * 35 *
36 * The ANSI C standard committee, for the C99 standard, specified the 36 * The ANSI C standard committee, for the C99 standard, specified the
37 * inclusion of a new standard include file called stdint.h. This is 37 * inclusion of a new standard include file called stdint.h. This is
38 * a very useful and long desired include file which contains several 38 * a very useful and long desired include file which contains several
39 * very precise definitions for integer scalar types that is 39 * very precise definitions for integer scalar types that is
40 * critically important for making portable several classes of 40 * critically important for making portable several classes of
41 * applications including cryptography, hashing, variable length 41 * applications including cryptography, hashing, variable length
42 * integer libraries and so on. But for most developers its likely 42 * integer libraries and so on. But for most developers its likely
43 * useful just for programming sanity. 43 * useful just for programming sanity.
44 * 44 *
45 * The problem is that most compiler vendors have decided not to 45 * The problem is that most compiler vendors have decided not to
46 * implement the C99 standard, and the next C++ language standard 46 * implement the C99 standard, and the next C++ language standard
47 * (which has a lot more mindshare these days) will be a long time in 47 * (which has a lot more mindshare these days) will be a long time in
48 * coming and its unknown whether or not it will include stdint.h or 48 * coming and its unknown whether or not it will include stdint.h or
49 * how much adoption it will have. Either way, it will be a long time 49 * how much adoption it will have. Either way, it will be a long time
50 * before all compilers come with a stdint.h and it also does nothing 50 * before all compilers come with a stdint.h and it also does nothing
51 * for the extremely large number of compilers available today which 51 * for the extremely large number of compilers available today which
52 * do not include this file, or anything comparable to it. 52 * do not include this file, or anything comparable to it.
53 * 53 *
54 * So that's what this file is all about. Its an attempt to build a 54 * So that's what this file is all about. Its an attempt to build a
55 * single universal include file that works on as many platforms as 55 * single universal include file that works on as many platforms as
56 * possible to deliver what stdint.h is supposed to. A few things 56 * possible to deliver what stdint.h is supposed to. A few things
57 * that should be noted about this file: 57 * that should be noted about this file:
58 * 58 *
59 * 1) It is not guaranteed to be portable and/or present an identical 59 * 1) It is not guaranteed to be portable and/or present an identical
60 * interface on all platforms. The extreme variability of the 60 * interface on all platforms. The extreme variability of the
61 * ANSI C standard makes this an impossibility right from the 61 * ANSI C standard makes this an impossibility right from the
62 * very get go. Its really only meant to be useful for the vast 62 * very get go. Its really only meant to be useful for the vast
63 * majority of platforms that possess the capability of 63 * majority of platforms that possess the capability of
64 * implementing usefully and precisely defined, standard sized 64 * implementing usefully and precisely defined, standard sized
65 * integer scalars. Systems which are not intrinsically 2s 65 * integer scalars. Systems which are not intrinsically 2s
66 * complement may produce invalid constants. 66 * complement may produce invalid constants.
67 * 67 *
68 * 2) There is an unavoidable use of non-reserved symbols. 68 * 2) There is an unavoidable use of non-reserved symbols.
69 * 69 *
70 * 3) Other standard include files are invoked. 70 * 3) Other standard include files are invoked.
71 * 71 *
72 * 4) This file may come in conflict with future platforms that do 72 * 4) This file may come in conflict with future platforms that do
73 * include stdint.h. The hope is that one or the other can be 73 * include stdint.h. The hope is that one or the other can be
74 * used with no real difference. 74 * used with no real difference.
75 * 75 *
76 * 5) In the current verison, if your platform can't represent 76 * 5) In the current verison, if your platform can't represent
77 * int32_t, int16_t and int8_t, it just dumps out with a compiler 77 * int32_t, int16_t and int8_t, it just dumps out with a compiler
78 * error. 78 * error.
79 * 79 *
80 * 6) 64 bit integers may or may not be defined. Test for their 80 * 6) 64 bit integers may or may not be defined. Test for their
81 * presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX. 81 * presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
82 * Note that this is different from the C99 specification which 82 * Note that this is different from the C99 specification which
83 * requires the existence of 64 bit support in the compiler. If 83 * requires the existence of 64 bit support in the compiler. If
84 * this is not defined for your platform, yet it is capable of 84 * this is not defined for your platform, yet it is capable of
85 * dealing with 64 bits then it is because this file has not yet 85 * dealing with 64 bits then it is because this file has not yet
86 * been extended to cover all of your system's capabilities. 86 * been extended to cover all of your system's capabilities.
87 * 87 *
88 * 7) (u)intptr_t may or may not be defined. Test for its presence 88 * 7) (u)intptr_t may or may not be defined. Test for its presence
89 * with the test: #ifdef PTRDIFF_MAX. If this is not defined 89 * with the test: #ifdef PTRDIFF_MAX. If this is not defined
90 * for your platform, then it is because this file has not yet 90 * for your platform, then it is because this file has not yet
91 * been extended to cover all of your system's capabilities, not 91 * been extended to cover all of your system's capabilities, not
92 * because its optional. 92 * because its optional.
93 * 93 *
94 * 8) The following might not been defined even if your platform is 94 * 8) The following might not been defined even if your platform is
95 * capable of defining it: 95 * capable of defining it:
96 * 96 *
97 * WCHAR_MIN 97 * WCHAR_MIN
98 * WCHAR_MAX 98 * WCHAR_MAX
99 * (u)int64_t 99 * (u)int64_t
100 * PTRDIFF_MIN 100 * PTRDIFF_MIN
101 * PTRDIFF_MAX 101 * PTRDIFF_MAX
102 * (u)intptr_t 102 * (u)intptr_t
103 * 103 *
104 * 9) The following have not been defined: 104 * 9) The following have not been defined:
105 * 105 *
106 * WINT_MIN 106 * WINT_MIN
107 * WINT_MAX 107 * WINT_MAX
108 * 108 *
109 * 10) The criteria for defining (u)int_least(*)_t isn't clear, 109 * 10) The criteria for defining (u)int_least(*)_t isn't clear,
110 * except for systems which don't have a type that precisely 110 * except for systems which don't have a type that precisely
111 * defined 8, 16, or 32 bit types (which this include file does 111 * defined 8, 16, or 32 bit types (which this include file does
112 * not support anyways). Default definitions have been given. 112 * not support anyways). Default definitions have been given.
113 * 113 *
114 * 11) The criteria for defining (u)int_fast(*)_t isn't something I 114 * 11) The criteria for defining (u)int_fast(*)_t isn't something I
115 * would trust to any particular compiler vendor or the ANSI C 115 * would trust to any particular compiler vendor or the ANSI C
116 * committee. It is well known that "compatible systems" are 116 * committee. It is well known that "compatible systems" are
117 * commonly created that have very different performance 117 * commonly created that have very different performance
118 * characteristics from the systems they are compatible with, 118 * characteristics from the systems they are compatible with,
119 * especially those whose vendors make both the compiler and the 119 * especially those whose vendors make both the compiler and the
120 * system. Default definitions have been given, but its strongly 120 * system. Default definitions have been given, but its strongly
121 * recommended that users never use these definitions for any 121 * recommended that users never use these definitions for any
122 * reason (they do *NOT* deliver any serious guarantee of 122 * reason (they do *NOT* deliver any serious guarantee of
123 * improved performance -- not in this file, nor any vendor's 123 * improved performance -- not in this file, nor any vendor's
124 * stdint.h). 124 * stdint.h).
125 * 125 *
126 * 12) The following macros: 126 * 12) The following macros:
127 * 127 *
128 * PRINTF_INTMAX_MODIFIER 128 * PRINTF_INTMAX_MODIFIER
129 * PRINTF_INT64_MODIFIER 129 * PRINTF_INT64_MODIFIER
130 * PRINTF_INT32_MODIFIER 130 * PRINTF_INT32_MODIFIER
131 * PRINTF_INT16_MODIFIER 131 * PRINTF_INT16_MODIFIER
132 * PRINTF_LEAST64_MODIFIER 132 * PRINTF_LEAST64_MODIFIER
133 * PRINTF_LEAST32_MODIFIER 133 * PRINTF_LEAST32_MODIFIER
134 * PRINTF_LEAST16_MODIFIER 134 * PRINTF_LEAST16_MODIFIER
135 * PRINTF_INTPTR_MODIFIER 135 * PRINTF_INTPTR_MODIFIER
136 * 136 *
137 * are strings which have been defined as the modifiers required 137 * are strings which have been defined as the modifiers required
138 * for the "d", "u" and "x" printf formats to correctly output 138 * for the "d", "u" and "x" printf formats to correctly output
139 * (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t, 139 * (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
140 * (u)least32_t, (u)least16_t and (u)intptr_t types respectively. 140 * (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
141 * PRINTF_INTPTR_MODIFIER is not defined for some systems which 141 * PRINTF_INTPTR_MODIFIER is not defined for some systems which
142 * provide their own stdint.h. PRINTF_INT64_MODIFIER is not 142 * provide their own stdint.h. PRINTF_INT64_MODIFIER is not
143 * defined if INT64_MAX is not defined. These are an extension 143 * defined if INT64_MAX is not defined. These are an extension
144 * beyond what C99 specifies must be in stdint.h. 144 * beyond what C99 specifies must be in stdint.h.
145 * 145 *
146 * In addition, the following macros are defined: 146 * In addition, the following macros are defined:
147 * 147 *
148 * PRINTF_INTMAX_HEX_WIDTH 148 * PRINTF_INTMAX_HEX_WIDTH
149 * PRINTF_INT64_HEX_WIDTH 149 * PRINTF_INT64_HEX_WIDTH
150 * PRINTF_INT32_HEX_WIDTH 150 * PRINTF_INT32_HEX_WIDTH
151 * PRINTF_INT16_HEX_WIDTH 151 * PRINTF_INT16_HEX_WIDTH
152 * PRINTF_INT8_HEX_WIDTH 152 * PRINTF_INT8_HEX_WIDTH
153 * PRINTF_INTMAX_DEC_WIDTH 153 * PRINTF_INTMAX_DEC_WIDTH
154 * PRINTF_INT64_DEC_WIDTH 154 * PRINTF_INT64_DEC_WIDTH
155 * PRINTF_INT32_DEC_WIDTH 155 * PRINTF_INT32_DEC_WIDTH
156 * PRINTF_INT16_DEC_WIDTH 156 * PRINTF_INT16_DEC_WIDTH
157 * PRINTF_INT8_DEC_WIDTH 157 * PRINTF_INT8_DEC_WIDTH
158 * 158 *
159 * Which specifies the maximum number of characters required to 159 * Which specifies the maximum number of characters required to
160 * print the number of that type in either hexadecimal or decimal. 160 * print the number of that type in either hexadecimal or decimal.
161 * These are an extension beyond what C99 specifies must be in 161 * These are an extension beyond what C99 specifies must be in
162 * stdint.h. 162 * stdint.h.
163 * 163 *
164 * Compilers tested (all with 0 warnings at their highest respective 164 * Compilers tested (all with 0 warnings at their highest respective
165 * settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32 165 * settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
166 * bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio 166 * bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
167 * .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3 167 * .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
168 * 168 *
169 * This file should be considered a work in progress. Suggestions for 169 * This file should be considered a work in progress. Suggestions for
170 * improvements, especially those which increase coverage are strongly 170 * improvements, especially those which increase coverage are strongly
171 * encouraged. 171 * encouraged.
172 * 172 *
173 * Acknowledgements 173 * Acknowledgements
174 * 174 *
175 * The following people have made significant contributions to the 175 * The following people have made significant contributions to the
176 * development and testing of this file: 176 * development and testing of this file:
177 * 177 *
178 * Chris Howie 178 * Chris Howie
179 * John Steele Scott 179 * John Steele Scott
180 * Dave Thorup 180 * Dave Thorup
181 * 181 *
182 */ 182 */
183 183
184#include <stddef.h> 184#include <stddef.h>
185#include <limits.h> 185#include <limits.h>
186#include <signal.h> 186#include <signal.h>
187 187
188/* 188/*
189 * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and 189 * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
190 * do nothing else. On the Mac OS X version of gcc this is _STDINT_H_. 190 * do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.
191 */ 191 */
192 192
193#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) )) && !defined (_PSTDINT_H_INCLUDED) 193#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) )) && !defined (_PSTDINT_H_INCLUDED)
194#include <stdint.h> 194#include <stdint.h>
195#define _PSTDINT_H_INCLUDED 195#define _PSTDINT_H_INCLUDED
196# ifndef PRINTF_INT64_MODIFIER 196# ifndef PRINTF_INT64_MODIFIER
197# define PRINTF_INT64_MODIFIER "ll" 197# define PRINTF_INT64_MODIFIER "ll"
198# endif 198# endif
199# ifndef PRINTF_INT32_MODIFIER 199# ifndef PRINTF_INT32_MODIFIER
200# define PRINTF_INT32_MODIFIER "l" 200# define PRINTF_INT32_MODIFIER "l"
201# endif 201# endif
202# ifndef PRINTF_INT16_MODIFIER 202# ifndef PRINTF_INT16_MODIFIER
203# define PRINTF_INT16_MODIFIER "h" 203# define PRINTF_INT16_MODIFIER "h"
204# endif 204# endif
205# ifndef PRINTF_INTMAX_MODIFIER 205# ifndef PRINTF_INTMAX_MODIFIER
206# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER 206# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
207# endif 207# endif
208# ifndef PRINTF_INT64_HEX_WIDTH 208# ifndef PRINTF_INT64_HEX_WIDTH
209# define PRINTF_INT64_HEX_WIDTH "16" 209# define PRINTF_INT64_HEX_WIDTH "16"
210# endif 210# endif
211# ifndef PRINTF_INT32_HEX_WIDTH 211# ifndef PRINTF_INT32_HEX_WIDTH
212# define PRINTF_INT32_HEX_WIDTH "8" 212# define PRINTF_INT32_HEX_WIDTH "8"
213# endif 213# endif
214# ifndef PRINTF_INT16_HEX_WIDTH 214# ifndef PRINTF_INT16_HEX_WIDTH
215# define PRINTF_INT16_HEX_WIDTH "4" 215# define PRINTF_INT16_HEX_WIDTH "4"
216# endif 216# endif
217# ifndef PRINTF_INT8_HEX_WIDTH 217# ifndef PRINTF_INT8_HEX_WIDTH
218# define PRINTF_INT8_HEX_WIDTH "2" 218# define PRINTF_INT8_HEX_WIDTH "2"
219# endif 219# endif
220# ifndef PRINTF_INT64_DEC_WIDTH 220# ifndef PRINTF_INT64_DEC_WIDTH
221# define PRINTF_INT64_DEC_WIDTH "20" 221# define PRINTF_INT64_DEC_WIDTH "20"
222# endif 222# endif
223# ifndef PRINTF_INT32_DEC_WIDTH 223# ifndef PRINTF_INT32_DEC_WIDTH
224# define PRINTF_INT32_DEC_WIDTH "10" 224# define PRINTF_INT32_DEC_WIDTH "10"
225# endif 225# endif
226# ifndef PRINTF_INT16_DEC_WIDTH 226# ifndef PRINTF_INT16_DEC_WIDTH
227# define PRINTF_INT16_DEC_WIDTH "5" 227# define PRINTF_INT16_DEC_WIDTH "5"
228# endif 228# endif
229# ifndef PRINTF_INT8_DEC_WIDTH 229# ifndef PRINTF_INT8_DEC_WIDTH
230# define PRINTF_INT8_DEC_WIDTH "3" 230# define PRINTF_INT8_DEC_WIDTH "3"
231# endif 231# endif
232# ifndef PRINTF_INTMAX_HEX_WIDTH 232# ifndef PRINTF_INTMAX_HEX_WIDTH
233# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH 233# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
234# endif 234# endif
235# ifndef PRINTF_INTMAX_DEC_WIDTH 235# ifndef PRINTF_INTMAX_DEC_WIDTH
236# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH 236# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
237# endif 237# endif
238 238
239/* 239/*
240 * Something really weird is going on with Open Watcom. Just pull some of 240 * Something really weird is going on with Open Watcom. Just pull some of
241 * these duplicated definitions from Open Watcom's stdint.h file for now. 241 * these duplicated definitions from Open Watcom's stdint.h file for now.
242 */ 242 */
243 243
244# if defined (__WATCOMC__) && __WATCOMC__ >= 1250 244# if defined (__WATCOMC__) && __WATCOMC__ >= 1250
245# if !defined (INT64_C) 245# if !defined (INT64_C)
246# define INT64_C(x) (x + (INT64_MAX - INT64_MAX)) 246# define INT64_C(x) (x + (INT64_MAX - INT64_MAX))
247# endif 247# endif
248# if !defined (UINT64_C) 248# if !defined (UINT64_C)
249# define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX)) 249# define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))
250# endif 250# endif
251# if !defined (INT32_C) 251# if !defined (INT32_C)
252# define INT32_C(x) (x + (INT32_MAX - INT32_MAX)) 252# define INT32_C(x) (x + (INT32_MAX - INT32_MAX))
253# endif 253# endif
254# if !defined (UINT32_C) 254# if !defined (UINT32_C)
255# define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX)) 255# define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX))
256# endif 256# endif
257# if !defined (INT16_C) 257# if !defined (INT16_C)
258# define INT16_C(x) (x) 258# define INT16_C(x) (x)
259# endif 259# endif
260# if !defined (UINT16_C) 260# if !defined (UINT16_C)
261# define UINT16_C(x) (x) 261# define UINT16_C(x) (x)
262# endif 262# endif
263# if !defined (INT8_C) 263# if !defined (INT8_C)
264# define INT8_C(x) (x) 264# define INT8_C(x) (x)
265# endif 265# endif
266# if !defined (UINT8_C) 266# if !defined (UINT8_C)
267# define UINT8_C(x) (x) 267# define UINT8_C(x) (x)
268# endif 268# endif
269# if !defined (UINT64_MAX) 269# if !defined (UINT64_MAX)
270# define UINT64_MAX 18446744073709551615ULL 270# define UINT64_MAX 18446744073709551615ULL
271# endif 271# endif
272# if !defined (INT64_MAX) 272# if !defined (INT64_MAX)
273# define INT64_MAX 9223372036854775807LL 273# define INT64_MAX 9223372036854775807LL
274# endif 274# endif
275# if !defined (UINT32_MAX) 275# if !defined (UINT32_MAX)
276# define UINT32_MAX 4294967295UL 276# define UINT32_MAX 4294967295UL
277# endif 277# endif
278# if !defined (INT32_MAX) 278# if !defined (INT32_MAX)
279# define INT32_MAX 2147483647L 279# define INT32_MAX 2147483647L
280# endif 280# endif
281# if !defined (INTMAX_MAX) 281# if !defined (INTMAX_MAX)
282# define INTMAX_MAX INT64_MAX 282# define INTMAX_MAX INT64_MAX
283# endif 283# endif
284# if !defined (INTMAX_MIN) 284# if !defined (INTMAX_MIN)
285# define INTMAX_MIN INT64_MIN 285# define INTMAX_MIN INT64_MIN
286# endif 286# endif
287# endif 287# endif
288#endif 288#endif
289 289
290#ifndef _PSTDINT_H_INCLUDED 290#ifndef _PSTDINT_H_INCLUDED
291#define _PSTDINT_H_INCLUDED 291#define _PSTDINT_H_INCLUDED
292 292
293#ifndef SIZE_MAX 293#ifndef SIZE_MAX
294# define SIZE_MAX (~(size_t)0) 294# define SIZE_MAX (~(size_t)0)
295#endif 295#endif
296 296
297/* 297/*
298 * Deduce the type assignments from limits.h under the assumption that 298 * Deduce the type assignments from limits.h under the assumption that
299 * integer sizes in bits are powers of 2, and follow the ANSI 299 * integer sizes in bits are powers of 2, and follow the ANSI
300 * definitions. 300 * definitions.
301 */ 301 */
302 302
303#ifndef UINT8_MAX 303#ifndef UINT8_MAX
304# define UINT8_MAX 0xff 304# define UINT8_MAX 0xff
305#endif 305#endif
306#ifndef uint8_t 306#ifndef uint8_t
307# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S) 307# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
308 typedef unsigned char uint8_t; 308 typedef unsigned char uint8_t;
309# define UINT8_C(v) ((uint8_t) v) 309# define UINT8_C(v) ((uint8_t) v)
310# else 310# else
311# error "Platform not supported" 311# error "Platform not supported"
312# endif 312# endif
313#endif 313#endif
314 314
315#ifndef INT8_MAX 315#ifndef INT8_MAX
316# define INT8_MAX 0x7f 316# define INT8_MAX 0x7f
317#endif 317#endif
318#ifndef INT8_MIN 318#ifndef INT8_MIN
319# define INT8_MIN INT8_C(0x80) 319# define INT8_MIN INT8_C(0x80)
320#endif 320#endif
321#ifndef int8_t 321#ifndef int8_t
322# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S) 322# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
323 typedef signed char int8_t; 323 typedef signed char int8_t;
324# define INT8_C(v) ((int8_t) v) 324# define INT8_C(v) ((int8_t) v)
325# else 325# else
326# error "Platform not supported" 326# error "Platform not supported"
327# endif 327# endif
328#endif 328#endif
329 329
330#ifndef UINT16_MAX 330#ifndef UINT16_MAX
331# define UINT16_MAX 0xffff 331# define UINT16_MAX 0xffff
332#endif 332#endif
333#ifndef uint16_t 333#ifndef uint16_t
334#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S) 334#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
335 typedef unsigned int uint16_t; 335 typedef unsigned int uint16_t;
336# ifndef PRINTF_INT16_MODIFIER 336# ifndef PRINTF_INT16_MODIFIER
337# define PRINTF_INT16_MODIFIER "" 337# define PRINTF_INT16_MODIFIER ""
338# endif 338# endif
339# define UINT16_C(v) ((uint16_t) (v)) 339# define UINT16_C(v) ((uint16_t) (v))
340#elif (USHRT_MAX == UINT16_MAX) 340#elif (USHRT_MAX == UINT16_MAX)
341 typedef unsigned short uint16_t; 341 typedef unsigned short uint16_t;
342# define UINT16_C(v) ((uint16_t) (v)) 342# define UINT16_C(v) ((uint16_t) (v))
343# ifndef PRINTF_INT16_MODIFIER 343# ifndef PRINTF_INT16_MODIFIER
344# define PRINTF_INT16_MODIFIER "h" 344# define PRINTF_INT16_MODIFIER "h"
345# endif 345# endif
346#else 346#else
347#error "Platform not supported" 347#error "Platform not supported"
348#endif 348#endif
349#endif 349#endif
350 350
351#ifndef INT16_MAX 351#ifndef INT16_MAX
352# define INT16_MAX 0x7fff 352# define INT16_MAX 0x7fff
353#endif 353#endif
354#ifndef INT16_MIN 354#ifndef INT16_MIN
355# define INT16_MIN INT16_C(0x8000) 355# define INT16_MIN INT16_C(0x8000)
356#endif 356#endif
357#ifndef int16_t 357#ifndef int16_t
358#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S) 358#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
359 typedef signed int int16_t; 359 typedef signed int int16_t;
360# define INT16_C(v) ((int16_t) (v)) 360# define INT16_C(v) ((int16_t) (v))
361# ifndef PRINTF_INT16_MODIFIER 361# ifndef PRINTF_INT16_MODIFIER
362# define PRINTF_INT16_MODIFIER "" 362# define PRINTF_INT16_MODIFIER ""
363# endif 363# endif
364#elif (SHRT_MAX == INT16_MAX) 364#elif (SHRT_MAX == INT16_MAX)
365 typedef signed short int16_t; 365 typedef signed short int16_t;
366# define INT16_C(v) ((int16_t) (v)) 366# define INT16_C(v) ((int16_t) (v))
367# ifndef PRINTF_INT16_MODIFIER 367# ifndef PRINTF_INT16_MODIFIER
368# define PRINTF_INT16_MODIFIER "h" 368# define PRINTF_INT16_MODIFIER "h"
369# endif 369# endif
370#else 370#else
371#error "Platform not supported" 371#error "Platform not supported"
372#endif 372#endif
373#endif 373#endif
374 374
375#ifndef UINT32_MAX 375#ifndef UINT32_MAX
376# define UINT32_MAX (0xffffffffUL) 376# define UINT32_MAX (0xffffffffUL)
377#endif 377#endif
378#ifndef uint32_t 378#ifndef uint32_t
379#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S) 379#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
380 typedef unsigned long uint32_t; 380 typedef unsigned long uint32_t;
381# define UINT32_C(v) v ## UL 381# define UINT32_C(v) v ## UL
382# ifndef PRINTF_INT32_MODIFIER 382# ifndef PRINTF_INT32_MODIFIER
383# define PRINTF_INT32_MODIFIER "l" 383# define PRINTF_INT32_MODIFIER "l"
384# endif 384# endif
385#elif (UINT_MAX == UINT32_MAX) 385#elif (UINT_MAX == UINT32_MAX)
386 typedef unsigned int uint32_t; 386 typedef unsigned int uint32_t;
387# ifndef PRINTF_INT32_MODIFIER 387# ifndef PRINTF_INT32_MODIFIER
388# define PRINTF_INT32_MODIFIER "" 388# define PRINTF_INT32_MODIFIER ""
389# endif 389# endif
390# define UINT32_C(v) v ## U 390# define UINT32_C(v) v ## U
391#elif (USHRT_MAX == UINT32_MAX) 391#elif (USHRT_MAX == UINT32_MAX)
392 typedef unsigned short uint32_t; 392 typedef unsigned short uint32_t;
393# define UINT32_C(v) ((unsigned short) (v)) 393# define UINT32_C(v) ((unsigned short) (v))
394# ifndef PRINTF_INT32_MODIFIER 394# ifndef PRINTF_INT32_MODIFIER
395# define PRINTF_INT32_MODIFIER "" 395# define PRINTF_INT32_MODIFIER ""
396# endif 396# endif
397#else 397#else
398#error "Platform not supported" 398#error "Platform not supported"
399#endif 399#endif
400#endif 400#endif
401 401
402#ifndef INT32_MAX 402#ifndef INT32_MAX
403# define INT32_MAX (0x7fffffffL) 403# define INT32_MAX (0x7fffffffL)
404#endif 404#endif
405#ifndef INT32_MIN 405#ifndef INT32_MIN
406# define INT32_MIN INT32_C(0x80000000) 406# define INT32_MIN INT32_C(0x80000000)
407#endif 407#endif
408#ifndef int32_t 408#ifndef int32_t
409#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S) 409#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
410 typedef signed long int32_t; 410 typedef signed long int32_t;
411# define INT32_C(v) v ## L 411# define INT32_C(v) v ## L
412# ifndef PRINTF_INT32_MODIFIER 412# ifndef PRINTF_INT32_MODIFIER
413# define PRINTF_INT32_MODIFIER "l" 413# define PRINTF_INT32_MODIFIER "l"
414# endif 414# endif
415#elif (INT_MAX == INT32_MAX) 415#elif (INT_MAX == INT32_MAX)
416 typedef signed int int32_t; 416 typedef signed int int32_t;
417# define INT32_C(v) v 417# define INT32_C(v) v
418# ifndef PRINTF_INT32_MODIFIER 418# ifndef PRINTF_INT32_MODIFIER
419# define PRINTF_INT32_MODIFIER "" 419# define PRINTF_INT32_MODIFIER ""
420# endif 420# endif
421#elif (SHRT_MAX == INT32_MAX) 421#elif (SHRT_MAX == INT32_MAX)
422 typedef signed short int32_t; 422 typedef signed short int32_t;
423# define INT32_C(v) ((short) (v)) 423# define INT32_C(v) ((short) (v))
424# ifndef PRINTF_INT32_MODIFIER 424# ifndef PRINTF_INT32_MODIFIER
425# define PRINTF_INT32_MODIFIER "" 425# define PRINTF_INT32_MODIFIER ""
426# endif 426# endif
427#else 427#else
428#error "Platform not supported" 428#error "Platform not supported"
429#endif 429#endif
430#endif 430#endif
431 431
432/* 432/*
433 * The macro stdint_int64_defined is temporarily used to record 433 * The macro stdint_int64_defined is temporarily used to record
434 * whether or not 64 integer support is available. It must be 434 * whether or not 64 integer support is available. It must be
435 * defined for any 64 integer extensions for new platforms that are 435 * defined for any 64 integer extensions for new platforms that are
436 * added. 436 * added.
437 */ 437 */
438 438
439#undef stdint_int64_defined 439#undef stdint_int64_defined
440#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S) 440#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
441# if (__STDC__ && __STDC_VERSION >= 199901L) || defined (S_SPLINT_S) 441# if (__STDC__ && __STDC_VERSION >= 199901L) || defined (S_SPLINT_S)
442# define stdint_int64_defined 442# define stdint_int64_defined
443 typedef long long int64_t; 443 typedef long long int64_t;
444 typedef unsigned long long uint64_t; 444 typedef unsigned long long uint64_t;
445# define UINT64_C(v) v ## ULL 445# define UINT64_C(v) v ## ULL
446# define INT64_C(v) v ## LL 446# define INT64_C(v) v ## LL
447# ifndef PRINTF_INT64_MODIFIER 447# ifndef PRINTF_INT64_MODIFIER
448# define PRINTF_INT64_MODIFIER "ll" 448# define PRINTF_INT64_MODIFIER "ll"
449# endif 449# endif
450# endif 450# endif
451#endif 451#endif
452 452
453#if !defined (stdint_int64_defined) 453#if !defined (stdint_int64_defined)
454# if defined(__GNUC__) 454# if defined(__GNUC__)
455# define stdint_int64_defined 455# define stdint_int64_defined
456 __extension__ typedef long long int64_t; 456 __extension__ typedef long long int64_t;
457 __extension__ typedef unsigned long long uint64_t; 457 __extension__ typedef unsigned long long uint64_t;
458# define UINT64_C(v) v ## ULL 458# define UINT64_C(v) v ## ULL
459# define INT64_C(v) v ## LL 459# define INT64_C(v) v ## LL
460# ifndef PRINTF_INT64_MODIFIER 460# ifndef PRINTF_INT64_MODIFIER
461# define PRINTF_INT64_MODIFIER "ll" 461# define PRINTF_INT64_MODIFIER "ll"
462# endif 462# endif
463# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S) 463# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
464# define stdint_int64_defined 464# define stdint_int64_defined
465 typedef long long int64_t; 465 typedef long long int64_t;
466 typedef unsigned long long uint64_t; 466 typedef unsigned long long uint64_t;
467# define UINT64_C(v) v ## ULL 467# define UINT64_C(v) v ## ULL
468# define INT64_C(v) v ## LL 468# define INT64_C(v) v ## LL
469# ifndef PRINTF_INT64_MODIFIER 469# ifndef PRINTF_INT64_MODIFIER
470# define PRINTF_INT64_MODIFIER "ll" 470# define PRINTF_INT64_MODIFIER "ll"
471# endif 471# endif
472# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC) 472# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
473# define stdint_int64_defined 473# define stdint_int64_defined
474 typedef __int64 int64_t; 474 typedef __int64 int64_t;
475 typedef unsigned __int64 uint64_t; 475 typedef unsigned __int64 uint64_t;
476# define UINT64_C(v) v ## UI64 476# define UINT64_C(v) v ## UI64
477# define INT64_C(v) v ## I64 477# define INT64_C(v) v ## I64
478# ifndef PRINTF_INT64_MODIFIER 478# ifndef PRINTF_INT64_MODIFIER
479# define PRINTF_INT64_MODIFIER "I64" 479# define PRINTF_INT64_MODIFIER "I64"
480# endif 480# endif
481# endif 481# endif
482#endif 482#endif
483 483
484#if !defined (LONG_LONG_MAX) && defined (INT64_C) 484#if !defined (LONG_LONG_MAX) && defined (INT64_C)
485# define LONG_LONG_MAX INT64_C (9223372036854775807) 485# define LONG_LONG_MAX INT64_C (9223372036854775807)
486#endif 486#endif
487#ifndef ULONG_LONG_MAX 487#ifndef ULONG_LONG_MAX
488# define ULONG_LONG_MAX UINT64_C (18446744073709551615) 488# define ULONG_LONG_MAX UINT64_C (18446744073709551615)
489#endif 489#endif
490 490
491#if !defined (INT64_MAX) && defined (INT64_C) 491#if !defined (INT64_MAX) && defined (INT64_C)
492# define INT64_MAX INT64_C (9223372036854775807) 492# define INT64_MAX INT64_C (9223372036854775807)
493#endif 493#endif
494#if !defined (INT64_MIN) && defined (INT64_C) 494#if !defined (INT64_MIN) && defined (INT64_C)
495# define INT64_MIN INT64_C (-9223372036854775808) 495# define INT64_MIN INT64_C (-9223372036854775808)
496#endif 496#endif
497#if !defined (UINT64_MAX) && defined (INT64_C) 497#if !defined (UINT64_MAX) && defined (INT64_C)
498# define UINT64_MAX UINT64_C (18446744073709551615) 498# define UINT64_MAX UINT64_C (18446744073709551615)
499#endif 499#endif
500 500
501/* 501/*
502 * Width of hexadecimal for number field. 502 * Width of hexadecimal for number field.
503 */ 503 */
504 504
505#ifndef PRINTF_INT64_HEX_WIDTH 505#ifndef PRINTF_INT64_HEX_WIDTH
506# define PRINTF_INT64_HEX_WIDTH "16" 506# define PRINTF_INT64_HEX_WIDTH "16"
507#endif 507#endif
508#ifndef PRINTF_INT32_HEX_WIDTH 508#ifndef PRINTF_INT32_HEX_WIDTH
509# define PRINTF_INT32_HEX_WIDTH "8" 509# define PRINTF_INT32_HEX_WIDTH "8"
510#endif 510#endif
511#ifndef PRINTF_INT16_HEX_WIDTH 511#ifndef PRINTF_INT16_HEX_WIDTH
512# define PRINTF_INT16_HEX_WIDTH "4" 512# define PRINTF_INT16_HEX_WIDTH "4"
513#endif 513#endif
514#ifndef PRINTF_INT8_HEX_WIDTH 514#ifndef PRINTF_INT8_HEX_WIDTH
515# define PRINTF_INT8_HEX_WIDTH "2" 515# define PRINTF_INT8_HEX_WIDTH "2"
516#endif 516#endif
517 517
518#ifndef PRINTF_INT64_DEC_WIDTH 518#ifndef PRINTF_INT64_DEC_WIDTH
519# define PRINTF_INT64_DEC_WIDTH "20" 519# define PRINTF_INT64_DEC_WIDTH "20"
520#endif 520#endif
521#ifndef PRINTF_INT32_DEC_WIDTH 521#ifndef PRINTF_INT32_DEC_WIDTH
522# define PRINTF_INT32_DEC_WIDTH "10" 522# define PRINTF_INT32_DEC_WIDTH "10"
523#endif 523#endif
524#ifndef PRINTF_INT16_DEC_WIDTH 524#ifndef PRINTF_INT16_DEC_WIDTH
525# define PRINTF_INT16_DEC_WIDTH "5" 525# define PRINTF_INT16_DEC_WIDTH "5"
526#endif 526#endif
527#ifndef PRINTF_INT8_DEC_WIDTH 527#ifndef PRINTF_INT8_DEC_WIDTH
528# define PRINTF_INT8_DEC_WIDTH "3" 528# define PRINTF_INT8_DEC_WIDTH "3"
529#endif 529#endif
530 530
531/* 531/*
532 * Ok, lets not worry about 128 bit integers for now. Moore's law says 532 * Ok, lets not worry about 128 bit integers for now. Moore's law says
533 * we don't need to worry about that until about 2040 at which point 533 * we don't need to worry about that until about 2040 at which point
534 * we'll have bigger things to worry about. 534 * we'll have bigger things to worry about.
535 */ 535 */
536 536
537#ifdef stdint_int64_defined 537#ifdef stdint_int64_defined
538 typedef int64_t intmax_t; 538 typedef int64_t intmax_t;
539 typedef uint64_t uintmax_t; 539 typedef uint64_t uintmax_t;
540# define INTMAX_MAX INT64_MAX 540# define INTMAX_MAX INT64_MAX
541# define INTMAX_MIN INT64_MIN 541# define INTMAX_MIN INT64_MIN
542# define UINTMAX_MAX UINT64_MAX 542# define UINTMAX_MAX UINT64_MAX
543# define UINTMAX_C(v) UINT64_C(v) 543# define UINTMAX_C(v) UINT64_C(v)
544# define INTMAX_C(v) INT64_C(v) 544# define INTMAX_C(v) INT64_C(v)
545# ifndef PRINTF_INTMAX_MODIFIER 545# ifndef PRINTF_INTMAX_MODIFIER
546# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER 546# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
547# endif 547# endif
548# ifndef PRINTF_INTMAX_HEX_WIDTH 548# ifndef PRINTF_INTMAX_HEX_WIDTH
549# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH 549# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
550# endif 550# endif
551# ifndef PRINTF_INTMAX_DEC_WIDTH 551# ifndef PRINTF_INTMAX_DEC_WIDTH
552# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH 552# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
553# endif 553# endif
554#else 554#else
555 typedef int32_t intmax_t; 555 typedef int32_t intmax_t;
556 typedef uint32_t uintmax_t; 556 typedef uint32_t uintmax_t;
557# define INTMAX_MAX INT32_MAX 557# define INTMAX_MAX INT32_MAX
558# define UINTMAX_MAX UINT32_MAX 558# define UINTMAX_MAX UINT32_MAX
559# define UINTMAX_C(v) UINT32_C(v) 559# define UINTMAX_C(v) UINT32_C(v)
560# define INTMAX_C(v) INT32_C(v) 560# define INTMAX_C(v) INT32_C(v)
561# ifndef PRINTF_INTMAX_MODIFIER 561# ifndef PRINTF_INTMAX_MODIFIER
562# define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER 562# define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
563# endif 563# endif
564# ifndef PRINTF_INTMAX_HEX_WIDTH 564# ifndef PRINTF_INTMAX_HEX_WIDTH
565# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH 565# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
566# endif 566# endif
567# ifndef PRINTF_INTMAX_DEC_WIDTH 567# ifndef PRINTF_INTMAX_DEC_WIDTH
568# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH 568# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
569# endif 569# endif
570#endif 570#endif
571 571
572/* 572/*
573 * Because this file currently only supports platforms which have 573 * Because this file currently only supports platforms which have
574 * precise powers of 2 as bit sizes for the default integers, the 574 * precise powers of 2 as bit sizes for the default integers, the
575 * least definitions are all trivial. Its possible that a future 575 * least definitions are all trivial. Its possible that a future
576 * version of this file could have different definitions. 576 * version of this file could have different definitions.
577 */ 577 */
578 578
579#ifndef stdint_least_defined 579#ifndef stdint_least_defined
580 typedef int8_t int_least8_t; 580 typedef int8_t int_least8_t;
581 typedef uint8_t uint_least8_t; 581 typedef uint8_t uint_least8_t;
582 typedef int16_t int_least16_t; 582 typedef int16_t int_least16_t;
583 typedef uint16_t uint_least16_t; 583 typedef uint16_t uint_least16_t;
584 typedef int32_t int_least32_t; 584 typedef int32_t int_least32_t;
585 typedef uint32_t uint_least32_t; 585 typedef uint32_t uint_least32_t;
586# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER 586# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
587# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER 587# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
588# define UINT_LEAST8_MAX UINT8_MAX 588# define UINT_LEAST8_MAX UINT8_MAX
589# define INT_LEAST8_MAX INT8_MAX 589# define INT_LEAST8_MAX INT8_MAX
590# define UINT_LEAST16_MAX UINT16_MAX 590# define UINT_LEAST16_MAX UINT16_MAX
591# define INT_LEAST16_MAX INT16_MAX 591# define INT_LEAST16_MAX INT16_MAX
592# define UINT_LEAST32_MAX UINT32_MAX 592# define UINT_LEAST32_MAX UINT32_MAX
593# define INT_LEAST32_MAX INT32_MAX 593# define INT_LEAST32_MAX INT32_MAX
594# define INT_LEAST8_MIN INT8_MIN 594# define INT_LEAST8_MIN INT8_MIN
595# define INT_LEAST16_MIN INT16_MIN 595# define INT_LEAST16_MIN INT16_MIN
596# define INT_LEAST32_MIN INT32_MIN 596# define INT_LEAST32_MIN INT32_MIN
597# ifdef stdint_int64_defined 597# ifdef stdint_int64_defined
598 typedef int64_t int_least64_t; 598 typedef int64_t int_least64_t;
599 typedef uint64_t uint_least64_t; 599 typedef uint64_t uint_least64_t;
600# define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER 600# define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
601# define UINT_LEAST64_MAX UINT64_MAX 601# define UINT_LEAST64_MAX UINT64_MAX
602# define INT_LEAST64_MAX INT64_MAX 602# define INT_LEAST64_MAX INT64_MAX
603# define INT_LEAST64_MIN INT64_MIN 603# define INT_LEAST64_MIN INT64_MIN
604# endif 604# endif
605#endif 605#endif
606#undef stdint_least_defined 606#undef stdint_least_defined
607 607
608/* 608/*
609 * The ANSI C committee pretending to know or specify anything about 609 * The ANSI C committee pretending to know or specify anything about
610 * performance is the epitome of misguided arrogance. The mandate of 610 * performance is the epitome of misguided arrogance. The mandate of
611 * this file is to *ONLY* ever support that absolute minimum 611 * this file is to *ONLY* ever support that absolute minimum
612 * definition of the fast integer types, for compatibility purposes. 612 * definition of the fast integer types, for compatibility purposes.
613 * No extensions, and no attempt to suggest what may or may not be a 613 * No extensions, and no attempt to suggest what may or may not be a
614 * faster integer type will ever be made in this file. Developers are 614 * faster integer type will ever be made in this file. Developers are
615 * warned to stay away from these types when using this or any other 615 * warned to stay away from these types when using this or any other
616 * stdint.h. 616 * stdint.h.
617 */ 617 */
618 618
619typedef int_least8_t int_fast8_t; 619typedef int_least8_t int_fast8_t;
620typedef uint_least8_t uint_fast8_t; 620typedef uint_least8_t uint_fast8_t;
621typedef int_least16_t int_fast16_t; 621typedef int_least16_t int_fast16_t;
622typedef uint_least16_t uint_fast16_t; 622typedef uint_least16_t uint_fast16_t;
623typedef int_least32_t int_fast32_t; 623typedef int_least32_t int_fast32_t;
624typedef uint_least32_t uint_fast32_t; 624typedef uint_least32_t uint_fast32_t;
625#define UINT_FAST8_MAX UINT_LEAST8_MAX 625#define UINT_FAST8_MAX UINT_LEAST8_MAX
626#define INT_FAST8_MAX INT_LEAST8_MAX 626#define INT_FAST8_MAX INT_LEAST8_MAX
627#define UINT_FAST16_MAX UINT_LEAST16_MAX 627#define UINT_FAST16_MAX UINT_LEAST16_MAX
628#define INT_FAST16_MAX INT_LEAST16_MAX 628#define INT_FAST16_MAX INT_LEAST16_MAX
629#define UINT_FAST32_MAX UINT_LEAST32_MAX 629#define UINT_FAST32_MAX UINT_LEAST32_MAX
630#define INT_FAST32_MAX INT_LEAST32_MAX 630#define INT_FAST32_MAX INT_LEAST32_MAX
631#define INT_FAST8_MIN INT_LEAST8_MIN 631#define INT_FAST8_MIN INT_LEAST8_MIN
632#define INT_FAST16_MIN INT_LEAST16_MIN 632#define INT_FAST16_MIN INT_LEAST16_MIN
633#define INT_FAST32_MIN INT_LEAST32_MIN 633#define INT_FAST32_MIN INT_LEAST32_MIN
634#ifdef stdint_int64_defined 634#ifdef stdint_int64_defined
635 typedef int_least64_t int_fast64_t; 635 typedef int_least64_t int_fast64_t;
636 typedef uint_least64_t uint_fast64_t; 636 typedef uint_least64_t uint_fast64_t;
637# define UINT_FAST64_MAX UINT_LEAST64_MAX 637# define UINT_FAST64_MAX UINT_LEAST64_MAX
638# define INT_FAST64_MAX INT_LEAST64_MAX 638# define INT_FAST64_MAX INT_LEAST64_MAX
639# define INT_FAST64_MIN INT_LEAST64_MIN 639# define INT_FAST64_MIN INT_LEAST64_MIN
640#endif 640#endif
641 641
642#undef stdint_int64_defined 642#undef stdint_int64_defined
643 643
644/* 644/*
645 * Whatever piecemeal, per compiler thing we can do about the wchar_t 645 * Whatever piecemeal, per compiler thing we can do about the wchar_t
646 * type limits. 646 * type limits.
647 */ 647 */
648 648
649#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__) 649#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
650# include <wchar.h> 650# include <wchar.h>
651# ifndef WCHAR_MIN 651# ifndef WCHAR_MIN
652# define WCHAR_MIN 0 652# define WCHAR_MIN 0
653# endif 653# endif
654# ifndef WCHAR_MAX 654# ifndef WCHAR_MAX
655# define WCHAR_MAX ((wchar_t)-1) 655# define WCHAR_MAX ((wchar_t)-1)
656# endif 656# endif
657#endif 657#endif
658 658
659/* 659/*
660 * Whatever piecemeal, per compiler/platform thing we can do about the 660 * Whatever piecemeal, per compiler/platform thing we can do about the
661 * (u)intptr_t types and limits. 661 * (u)intptr_t types and limits.
662 */ 662 */
663 663
664#if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED) 664#if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)
665# define STDINT_H_UINTPTR_T_DEFINED 665# define STDINT_H_UINTPTR_T_DEFINED
666#endif 666#endif
667 667
668#ifndef STDINT_H_UINTPTR_T_DEFINED 668#ifndef STDINT_H_UINTPTR_T_DEFINED
669# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64) 669# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)
670# define stdint_intptr_bits 64 670# define stdint_intptr_bits 64
671# elif defined (__WATCOMC__) || defined (__TURBOC__) 671# elif defined (__WATCOMC__) || defined (__TURBOC__)
672# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__) 672# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
673# define stdint_intptr_bits 16 673# define stdint_intptr_bits 16
674# else 674# else
675# define stdint_intptr_bits 32 675# define stdint_intptr_bits 32
676# endif 676# endif
677# elif defined (__i386__) || defined (_WIN32) || defined (WIN32) 677# elif defined (__i386__) || defined (_WIN32) || defined (WIN32)
678# define stdint_intptr_bits 32 678# define stdint_intptr_bits 32
679# elif defined (__INTEL_COMPILER) 679# elif defined (__INTEL_COMPILER)
680/* TODO -- what will Intel do about x86-64? */ 680/* TODO -- what will Intel do about x86-64? */
681# endif 681# endif
682 682
683# ifdef stdint_intptr_bits 683# ifdef stdint_intptr_bits
684# define stdint_intptr_glue3_i(a,b,c) a##b##c 684# define stdint_intptr_glue3_i(a,b,c) a##b##c
685# define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c) 685# define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)
686# ifndef PRINTF_INTPTR_MODIFIER 686# ifndef PRINTF_INTPTR_MODIFIER
687# define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER) 687# define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
688# endif 688# endif
689# ifndef PTRDIFF_MAX 689# ifndef PTRDIFF_MAX
690# define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX) 690# define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
691# endif 691# endif
692# ifndef PTRDIFF_MIN 692# ifndef PTRDIFF_MIN
693# define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN) 693# define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
694# endif 694# endif
695# ifndef UINTPTR_MAX 695# ifndef UINTPTR_MAX
696# define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX) 696# define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
697# endif 697# endif
698# ifndef INTPTR_MAX 698# ifndef INTPTR_MAX
699# define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX) 699# define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
700# endif 700# endif
701# ifndef INTPTR_MIN 701# ifndef INTPTR_MIN
702# define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN) 702# define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
703# endif 703# endif
704# ifndef INTPTR_C 704# ifndef INTPTR_C
705# define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x) 705# define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
706# endif 706# endif
707# ifndef UINTPTR_C 707# ifndef UINTPTR_C
708# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x) 708# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
709# endif 709# endif
710 typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t; 710 typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
711 typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t; 711 typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;
712# else 712# else
713/* TODO -- This following is likely wrong for some platforms, and does 713/* TODO -- This following is likely wrong for some platforms, and does
714 nothing for the definition of uintptr_t. */ 714 nothing for the definition of uintptr_t. */
715 typedef ptrdiff_t intptr_t; 715 typedef ptrdiff_t intptr_t;
716# endif 716# endif
717# define STDINT_H_UINTPTR_T_DEFINED 717# define STDINT_H_UINTPTR_T_DEFINED
718#endif 718#endif
719 719
720/* 720/*
721 * Assumes sig_atomic_t is signed and we have a 2s complement machine. 721 * Assumes sig_atomic_t is signed and we have a 2s complement machine.
722 */ 722 */
723 723
724#ifndef SIG_ATOMIC_MAX 724#ifndef SIG_ATOMIC_MAX
725# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1) 725# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
726#endif 726#endif
727 727
728#endif 728#endif
729 729
730#if defined (__TEST_PSTDINT_FOR_CORRECTNESS) 730#if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
731 731
732/* 732/*
733 * Please compile with the maximum warning settings to make sure macros are not 733 * Please compile with the maximum warning settings to make sure macros are not
734 * defined more than once. 734 * defined more than once.
735 */ 735 */
736 736
737#include <stdlib.h> 737#include <stdlib.h>
738#include <stdio.h> 738#include <stdio.h>
739#include <string.h> 739#include <string.h>
740 740
741#define glue3_aux(x,y,z) x ## y ## z 741#define glue3_aux(x,y,z) x ## y ## z
742#define glue3(x,y,z) glue3_aux(x,y,z) 742#define glue3(x,y,z) glue3_aux(x,y,z)
743 743
744#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,=) glue3(UINT,bits,_C) (0); 744#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,=) glue3(UINT,bits,_C) (0);
745#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,=) glue3(INT,bits,_C) (0); 745#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,=) glue3(INT,bits,_C) (0);
746 746
747#define DECL(us,bits) glue3(DECL,us,) (bits) 747#define DECL(us,bits) glue3(DECL,us,) (bits)
748 748
749#define TESTUMAX(bits) glue3(u,bits,=) glue3(~,u,bits); if (glue3(UINT,bits,_MAX) glue3(!=,u,bits)) printf ("Something wrong with UINT%d_MAX\n", bits) 749#define TESTUMAX(bits) glue3(u,bits,=) glue3(~,u,bits); if (glue3(UINT,bits,_MAX) glue3(!=,u,bits)) printf ("Something wrong with UINT%d_MAX\n", bits)
750 750
751int main () { 751int main () {
752 DECL(I,8) 752 DECL(I,8)
753 DECL(U,8) 753 DECL(U,8)
754 DECL(I,16) 754 DECL(I,16)
755 DECL(U,16) 755 DECL(U,16)
756 DECL(I,32) 756 DECL(I,32)
757 DECL(U,32) 757 DECL(U,32)
758#ifdef INT64_MAX 758#ifdef INT64_MAX
759 DECL(I,64) 759 DECL(I,64)
760 DECL(U,64) 760 DECL(U,64)
761#endif 761#endif
762 intmax_t imax = INTMAX_C(0); 762 intmax_t imax = INTMAX_C(0);
763 uintmax_t umax = UINTMAX_C(0); 763 uintmax_t umax = UINTMAX_C(0);
764 char str0[256], str1[256]; 764 char str0[256], str1[256];
765 765
766 sprintf (str0, "%d %x\n", 0, ~0); 766 sprintf (str0, "%d %x\n", 0, ~0);
767 767
768 sprintf (str1, "%d %x\n", i8, ~0); 768 sprintf (str1, "%d %x\n", i8, ~0);
769 if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1); 769 if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1);
770 sprintf (str1, "%u %x\n", u8, ~0); 770 sprintf (str1, "%u %x\n", u8, ~0);
771 if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1); 771 if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1);
772 sprintf (str1, "%d %x\n", i16, ~0); 772 sprintf (str1, "%d %x\n", i16, ~0);
773 if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1); 773 if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1);
774 sprintf (str1, "%u %x\n", u16, ~0); 774 sprintf (str1, "%u %x\n", u16, ~0);
775 if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1); 775 if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1);
776 sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0); 776 sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);
777 if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1); 777 if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1);
778 sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0); 778 sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);
779 if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1); 779 if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1);
780#ifdef INT64_MAX 780#ifdef INT64_MAX
781 sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0); 781 sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);
782 if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1); 782 if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1);
783#endif 783#endif
784 sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0); 784 sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);
785 if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1); 785 if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1);
786 sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0); 786 sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);
787 if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1); 787 if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1);
788 788
789 TESTUMAX(8); 789 TESTUMAX(8);
790 TESTUMAX(16); 790 TESTUMAX(16);
791 TESTUMAX(32); 791 TESTUMAX(32);
792#ifdef INT64_MAX 792#ifdef INT64_MAX
793 TESTUMAX(64); 793 TESTUMAX(64);
794#endif 794#endif
795 795
796 return EXIT_SUCCESS; 796 return EXIT_SUCCESS;
797} 797}
798 798
799#endif 799#endif
diff --git a/utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj b/utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj
index e0473e240a..5d0d204e27 100644
--- a/utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj
+++ b/utils/MTP/beastpatcher/vs2005/beastpatcher.vcproj
@@ -189,6 +189,10 @@
189 > 189 >
190 </File> 190 </File>
191 <File 191 <File
192 RelativePath="..\main.c"
193 >
194 </File>
195 <File
192 RelativePath="..\mtp_win32.c" 196 RelativePath="..\mtp_win32.c"
193 > 197 >
194 </File> 198 </File>
@@ -199,6 +203,10 @@
199 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" 203 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
200 > 204 >
201 <File 205 <File
206 RelativePath="..\beastpatcher.h"
207 >
208 </File>
209 <File
202 RelativePath="..\bootimg.h" 210 RelativePath="..\bootimg.h"
203 > 211 >
204 </File> 212 </File>