~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/programs/winetest/util.c

Version: ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Utility functions.
  3  *
  4  * Copyright 2003 Dimitrie O. Paun
  5  * Copyright 2003 Ferenc Wagner
  6  *
  7  * This library is free software; you can redistribute it and/or
  8  * modify it under the terms of the GNU Lesser General Public
  9  * License as published by the Free Software Foundation; either
 10  * version 2.1 of the License, or (at your option) any later version.
 11  *
 12  * This library is distributed in the hope that it will be useful,
 13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15  * Lesser General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU Lesser General Public
 18  * License along with this library; if not, write to the Free Software
 19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 20  */
 21 
 22 #include <stdarg.h>
 23 #include <windef.h>
 24 #include <winbase.h>
 25 
 26 #include "winetest.h"
 27 
 28 HANDLE logfile = 0;
 29 
 30 void *heap_alloc (size_t len)
 31 {
 32     void *p = HeapAlloc(GetProcessHeap(), 0, len);
 33 
 34     if (!p) report (R_FATAL, "Out of memory.");
 35     return p;
 36 }
 37 
 38 void *heap_realloc (void *op, size_t len)
 39 {
 40     void *p = HeapReAlloc(GetProcessHeap(), 0, op, len);
 41 
 42     if (len && !p) report (R_FATAL, "Out of memory.");
 43     return p;
 44 }
 45 
 46 char *heap_strdup( const char *str )
 47 {
 48     int len = strlen(str) + 1;
 49     char* res = HeapAlloc(GetProcessHeap(), 0, len);
 50     if (!res) report (R_FATAL, "Out of memory.");
 51     memcpy(res, str, len);
 52     return res;
 53 }
 54 
 55 void heap_free (void *op)
 56 {
 57     HeapFree(GetProcessHeap(), 0, op);
 58 }
 59 
 60 static char *vstrfmtmake (size_t *lenp, const char *fmt, va_list ap)
 61 {
 62     size_t size = 1000;
 63     char *p, *q;
 64     int n;
 65 
 66     p = HeapAlloc(GetProcessHeap(), 0, size);
 67     if (!p) return NULL;
 68     while (1) {
 69         n = vsnprintf (p, size, fmt, ap);
 70         if (n < 0) size *= 2;   /* Windows */
 71         else if ((unsigned)n >= size) size = n+1; /* glibc */
 72         else break;
 73         q = HeapReAlloc(GetProcessHeap(), 0, p, size);
 74         if (!q) {
 75           heap_free (p);
 76           return NULL;
 77        }
 78        p = q;
 79     }
 80     if (lenp) *lenp = n;
 81     return p;
 82 }
 83 
 84 char *vstrmake (size_t *lenp, va_list ap)
 85 {
 86     const char *fmt;
 87 
 88     fmt = va_arg (ap, const char*);
 89     return vstrfmtmake (lenp, fmt, ap);
 90 }
 91 
 92 char *strmake (size_t *lenp, ...)
 93 {
 94     va_list ap;
 95     char *p;
 96 
 97     va_start (ap, lenp);
 98     p = vstrmake (lenp, ap);
 99     if (!p) report (R_FATAL, "Out of memory.");
100     va_end (ap);
101     return p;
102 }
103 
104 void xprintf (const char *fmt, ...)
105 {
106     va_list ap;
107     size_t size;
108     DWORD written;
109     char *buffer, *head;
110 
111     va_start (ap, fmt);
112     buffer = vstrfmtmake (&size, fmt, ap);
113     head = buffer;
114     va_end (ap);
115     while (size) {
116         if (!WriteFile( logfile, head, size, &written, NULL ))
117             report (R_FATAL, "Can't write logs: %u", GetLastError());
118         head += written;
119         size -= written;
120     }
121     heap_free (buffer);
122 }
123 
124 int
125 goodtagchar (char c)
126 {
127     return (('a'<=c && c<='z') ||
128             ('A'<=c && c<='Z') ||
129             (''<=c && c<='9') ||
130             c=='-' || c=='.');
131 }
132 
133 const char *
134 findbadtagchar (const char *tag)
135 {
136     while (*tag)
137         if (goodtagchar (*tag)) tag++;
138         else return tag;
139     return NULL;
140 }
141 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.