| 1 |
/* |
| 2 |
|
| 3 |
Copyright 1986, 1998 The Open Group |
| 4 |
|
| 5 |
Permission to use, copy, modify, distribute, and sell this software and its |
| 6 |
documentation for any purpose is hereby granted without fee, provided that |
| 7 |
the above copyright notice appear in all copies and that both that |
| 8 |
copyright notice and this permission notice appear in supporting |
| 9 |
documentation. |
| 10 |
|
| 11 |
The above copyright notice and this permission notice shall be included in |
| 12 |
all copies or substantial portions of the Software. |
| 13 |
|
| 14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 |
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 18 |
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 19 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 |
|
| 21 |
Except as contained in this notice, the name of The Open Group shall not be |
| 22 |
used in advertising or otherwise to promote the sale, use or other dealings |
| 23 |
in this Software without prior written authorization from The Open Group. |
| 24 |
|
| 25 |
*/ |
| 26 |
|
| 27 |
#ifdef HAVE_CONFIG_H |
| 28 |
#include <config.h> |
| 29 |
#endif |
| 30 |
#include "Xlibint.h" |
| 31 |
#include "reallocarray.h" |
| 32 |
#include <limits.h> |
| 33 |
|
| 34 |
char **XGetFontPath( |
| 35 |
register Display *dpy, |
| 36 |
int *npaths) /* RETURN */ |
| 37 |
{ |
| 38 |
xGetFontPathReply rep; |
| 39 |
unsigned long nbytes = 0; |
| 40 |
char **flist = NULL; |
| 41 |
char *ch = NULL; |
| 42 |
char *chend; |
| 43 |
int count = 0; |
| 44 |
register unsigned i; |
| 45 |
register int length; |
| 46 |
_X_UNUSED register xReq *req; |
| 47 |
|
| 48 |
LockDisplay(dpy); |
| 49 |
GetEmptyReq (GetFontPath, req); |
| 50 |
(void) _XReply (dpy, (xReply *) &rep, 0, xFalse); |
| 51 |
|
| 52 |
if (rep.nPaths) { |
| 53 |
flist = Xmallocarray(rep.nPaths, sizeof (char *)); |
| 54 |
if (rep.length < (INT_MAX >> 2)) { |
| 55 |
nbytes = (unsigned long) rep.length << 2; |
| 56 |
ch = Xmalloc (nbytes + 1); |
| 57 |
/* +1 to leave room for last null-terminator */ |
| 58 |
} |
| 59 |
|
| 60 |
if ((! flist) || (! ch)) { |
| 61 |
Xfree(flist); |
| 62 |
Xfree(ch); |
| 63 |
_XEatDataWords(dpy, rep.length); |
| 64 |
UnlockDisplay(dpy); |
| 65 |
SyncHandle(); |
| 66 |
return (char **) NULL; |
| 67 |
} |
| 68 |
|
| 69 |
_XReadPad (dpy, ch, nbytes); |
| 70 |
/* |
| 71 |
* unpack into null terminated strings. |
| 72 |
*/ |
| 73 |
chend = ch + nbytes; |
| 74 |
length = *(unsigned char *)ch; |
| 75 |
for (i = 0; i < rep.nPaths; i++) { |
| 76 |
if (ch + length < chend) { |
| 77 |
flist[i] = ch+1; /* skip over length */ |
| 78 |
ch += length + 1; /* find next length ... */ |
| 79 |
length = *(unsigned char *)ch; |
| 80 |
*ch = '\0'; /* and replace with null-termination */ |
| 81 |
count++; |
| 82 |
} else if (i == 0) { |
| 83 |
Xfree(flist); |
| 84 |
Xfree(ch); |
| 85 |
flist = NULL; |
| 86 |
break; |
| 87 |
} else |
| 88 |
flist[i] = NULL; |
| 89 |
} |
| 90 |
} |
| 91 |
*npaths = count; |
| 92 |
UnlockDisplay(dpy); |
| 93 |
SyncHandle(); |
| 94 |
return (flist); |
| 95 |
} |
| 96 |
|
| 97 |
int |
| 98 |
XFreeFontPath (char **list) |
| 99 |
{ |
| 100 |
if (list != NULL) { |
| 101 |
Xfree (list[0]-1); |
| 102 |
Xfree (list); |
| 103 |
} |
| 104 |
return 1; |
| 105 |
} |