1 /*
2 * IceBreaker
3 * Copyright (c) 2000-2002 Matthew Miller <mattdm@mattdm.org> and
4 * Enrico Tassi <gareuselesinge@infinito.it>
5 *
6 * <http://www.mattdm.org/icebreaker>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24
25 /************************************************************************/
26 /*
27 * This file contains varibles and functions to aid in win32 cross-compiling
28 * using mingw32.
29 *
30 * Enrico Tassi <gareuselesinge@infinito.it> contributed the initial work.
31 */
32
33 #include <stdio.h>
34 #include <stdarg.h>
35 #include <windows.h>
36 #include <lmcons.h>
37 #include "win32_compatibility.h"
38
39
40 #ifdef __MINGW32__
41
42 /* This is the structure that getpwuid returns. fix -- how to get username
43 in winNT, etc? */
44 struct passwd pwdwin32_standard={NULL,"*",1,1,"Win32 User",".","command.com"};
45
46 /* mingw32's string.h is missing index() */
index(const char * s,int c)47 char *index(const char *s, int c)
48 {
49 while( *s != '\0'&& *s != (char)c ) s++;
50 return((char*)s);
51 }
52
53 /* foolish foolish windows. the _snprintf function writes size+1 chars, not
54 just size as it is supposed to. */
snprintf_mingw32kludge(char * str,size_t size,const char * fmt,...)55 int snprintf_mingw32kludge(char *str, size_t size, const char *fmt, ...)
56 {
57 int rc;
58 va_list args;
59 va_start(args, fmt);
60 rc=_vsnprintf(str,size-1,fmt,args);
61 va_end(args);
62 *(str+size-1)='\0';
63 return rc;
64 }
65
vsnprintf_mingw32kludge(char * str,size_t size,const char * fmt,va_list ap)66 int vsnprintf_mingw32kludge(char *str, size_t size, const char *fmt, va_list ap)
67 {
68 int rc;
69 rc=_vsnprintf(str,size-1,fmt,ap);
70 *(str+size-1)='\0';
71 return rc;
72 }
73
74
getpwuid(int id)75 struct passwd *getpwuid(int id)
76 {
77 static CHAR name[UNLEN + 1]="Nobody";
78 DWORD width=UNLEN + 1;
79 int i;
80
81 GetUserName(name,&width);
82 for (i=0;i<50 && name[i]!='\0';i++)
83 {
84 if (name[i]==' ')
85 {
86 name[i]='\0';
87 break;
88 }
89 }
90
91 pwdwin32_standard.pw_name = name;
92
93 return &pwdwin32_standard;
94 }
95
96 #endif /* __MINGW32__ */
97