Debian Codegraph @

Contrib/NSISdl/util.cpp

raw
1 /*
2 ** JNetLib
3 ** Copyright (C) 2000-2001 Nullsoft, Inc.
4 ** Author: Justin Frankel
5 ** File: util.cpp - JNL implementation of basic network utilities
6 ** License: see License.txt
7 **
8 ** Unicode support by Jim Park -- 08/24/2007
9 ** Keep everything here strictly ANSI. No TCHAR style stuff.
10 */
11
12 #include <windows.h>
13 #include "util.h"
14
15 int my_atoi(char *s)
16 {
17 int sign=0;
18 int v=0;
19 if (*s == '-') { s++; sign++; }
20 for (;;)
21 {
22 int c=*s++ - '0';
23 if (c < 0 || c > 9) break;
24 v*=10;
25 v+=c;
26 }
27 if (sign) return -(int) v;
28 return (int)v;
29 }
30
31 __int64 myatoi64(const char *s)
32 {
33 __int64 v=0;
34 int sign=0;
35
36 if (*s == '-')
37 sign++;
38 else
39 s--;
40
41 for (;;)
42 {
43 int c=*(++s) - '0';
44 if (c < 0 || c > 9) break;
45 v*=10;
46 v+=c;
47 }
48
49 if (sign)
50 v = -v;
51
52 return v;
53 }
54
55 void myitoa64(__int64 i, char *buffer)
56 {
57 char buf[128], *b = buf;
58
59 if (i < 0)
60 {
61 *(buffer++) = '-';
62 i = -i;
63 }
64 if (i == 0) *(buffer++) = '0';
65 else
66 {
67 while (i > 0)
68 {
69 *(b++) = '0' + ((char) (i%10));
70 i /= 10;
71 }
72 while (b > buf) *(buffer++) = *(--b);
73 }
74 *buffer = 0;
75 }
76
77 // Visual Studio 2015 (CLv19 x86) and some older versions of CLv14 x64 will optimize
78 // our loop into a direct call to _memset and this fails to link because we don't use the CRT
79 #if defined(_MSC_VER) && _MSC_VER+0 >= 1400
80 # if defined(_MSC_FULL_VER) && _MSC_FULL_VER+0 >= 140050727
81 # include <intrin.h>
82 # else
83 EXTERN_C void __stosb(BYTE*,BYTE,size_t);
84 # endif //~ _MSC_FULL_VER >= 140050727
85 # if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) // __stosb not available under _M_ARM nor _M_ARM64
86 # pragma intrinsic(__stosb)
87 # define CRTINTRINSIC_memset(p,c,s) __stosb((BYTE*)(p),(BYTE)(c),(s))
88 # elif defined(_M_ARM) || defined(_M_ARM64) // For _MSC_VER=1914 (VS 15.7.27703.2026/CL 19.14.26430)
89 EXTERN_C void* __cdecl memset(void *d, int v, size_t l) { char *p=(char*)d; while (l-- > 0) *p++=v; return d; }
90 # pragma function(memset)
91 # endif
92 #endif //~ _MSC_VER
93
94 void mini_memset(void *o,char i,int l)
95 {
96 #ifdef CRTINTRINSIC_memset
97 CRTINTRINSIC_memset(o, i, l);
98 #else
99 char *oo=(char*)o;
100 while (l-- > 0) *oo++=i;
101 #endif
102 }
103 void mini_memcpy(void *o,void*i,int l)
104 {
105 char *oo=(char*)o;
106 char *ii=(char*)i;
107 while (l-- > 0) *oo++=*ii++;
108 }