r18925: Add current snapshot of the ejs-2.0 code. Tridge, will you be incorporating...
[Samba/aatanasov.git] / source4 / lib / appweb / ejs-2.0 / mpr / VXWORKS / mprPlatform.c
blob29258dfe1c6683209abee96998f185b3bf65779b
1 /**
2 * @file mprPlatform.c
3 * @brief Cross platform routines
4 * @overview This module provides low level cross platform routines.
5 * @remarks Most routines in this file are not thread-safe. It is the callers
6 * responsibility to perform all thread synchronization.
7 */
9 /*
10 * @copy default
12 * Copyright (c) Mbedthis Software LLC, 2003-2006. All Rights Reserved.
14 * This software is distributed under commercial and open source licenses.
15 * You may use the GPL open source license described below or you may acquire
16 * a commercial license from Mbedthis Software. You agree to be fully bound
17 * by the terms of either license. Consult the LICENSE.TXT distributed with
18 * this software for full details.
20 * This software is open source; you can redistribute it and/or modify it
21 * under the terms of the GNU General Public License as published by the
22 * Free Software Foundation; either version 2 of the License, or (at your
23 * option) any later version. See the GNU General Public License for more
24 * details at: http://www.mbedthis.com/downloads/gplLicense.html
26 * This program is distributed WITHOUT ANY WARRANTY; without even the
27 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
29 * This GPL license does NOT permit incorporating this software into
30 * proprietary programs. If you are unable to comply with the GPL, you must
31 * acquire a commercial license to use this software. Commercial licenses
32 * for this software and support services are available from Mbedthis
33 * Software at http://www.mbedthis.com
35 * @end
38 /********************************** Includes **********************************/
40 * We need to use the underlying str(cpy) routines to implement our safe
41 * alternatives
43 #if !DOXYGEN
44 #define UNSAFE_FUNCTIONS_OK 1
45 #endif
47 #include "mpr.h"
49 /************************************ Code ************************************/
51 char *mprInetToStr(char *buffer, int bufsize, const struct in_addr in)
53 #if HAVE_NTOA_R
54 inet_ntoa_r(in, buffer, bufsize);
55 #else
56 uchar *cp;
57 /* FUTURE -- this is not portable */
58 cp = (uchar*) ∈
59 mprSprintf(buffer, bufsize, "%d.%d.%d.%d", cp[0], cp[1], cp[2], cp[3]);
60 #endif
61 return buffer;
64 /******************************************************************************/
66 void mprSetShell(MprCtx ctx, void *shell)
70 /******************************************************************************/
72 void *mprGetShell(MprCtx ctx)
74 return 0;
77 /******************************************************************************/
79 * Sleep. Period given in milliseconds.
82 void mprSleep(MprCtx ctx, int milliseconds)
84 struct timeval timeout;
85 int rc;
87 timeout.tv_sec = milliseconds / 1000;
88 timeout.tv_usec = (milliseconds % 1000) * 1000;
89 do {
90 rc = select(1, 0, 0, 0, &timeout);
91 } while (rc < 0 && errno == EINTR);
94 /******************************************************************************/
96 * Make intervening directories
99 int mprMakeDirPath(MprCtx ctx, const char *path)
101 char dir[MPR_MAX_PATH], buf[MPR_MAX_PATH];
102 char *dirSep;
103 char *next, *tok;
105 dir[0] = '\0';
106 dirSep = "/\\";
108 if (path == 0 || *path == '\0') {
109 return MPR_ERR_BAD_ARGS;
112 mprStrcpy(buf, sizeof(buf), path);
113 next = mprStrTok(buf, dirSep, &tok);
114 if (*buf == '/') {
115 dir[0] = '/';
117 while (next != NULL) {
118 if (strcmp(next, ".") == 0 ) {
119 next = mprStrTok(NULL, dirSep, &tok);
120 continue;
122 strcat(dir, next);
123 if (access(dir, R_OK) != 0) {
124 if (mkdir(dir) < 0) {
125 return MPR_ERR_CANT_CREATE;
128 strcat(dir, "/");
129 next = mprStrTok(NULL, dirSep, &tok);
131 return 0;
134 /******************************************************************************/
136 * Get a fully qualified file name for the given path. Return with forward
137 * slashes always
140 char *mprGetFullPathName(char *buf, int buflen, const char *path)
142 if (mprStrcpy(buf, buflen, path) < 0) {
143 mprAssert(0);
144 return 0;
146 return buf;
149 /******************************************************************************/
151 * Replacement for gethostbyname that is multi-thread safe
154 struct hostent *mprGetHostByName(MprCtx ctx, const char *name)
156 struct hostent *hp;
158 hp = (struct hostent*) mprAlloc(ctx, sizeof(struct hostent));
159 memset(hp, 0, sizeof(struct hostent));
161 struct in_addr inaddr;
162 inaddr.s_addr = (ulong) hostGetByName(name);
163 if (inaddr.s_addr < 0) {
164 mprAssert(0);
165 return 0;
167 hp->h_addrtype = AF_INET;
168 hp->h_length = sizeof(int);
169 hp->h_name = mprStrdup(name);
170 hp->h_addr_list = 0;
171 hp->h_aliases = 0;
173 hp->h_addr_list = new char*[2];
174 hp->h_addr_list[0] = (char *) mprAlloc(hp, sizeof(struct in_addr));
175 memcpy(&hp->h_addr_list[0], &inaddr, hp->h_length);
176 hp->h_addr_list[1] = 0;
178 return hp;
181 /******************************************************************************/
184 * Local variables:
185 * tab-width: 4
186 * c-basic-offset: 4
187 * End:
188 * vim:tw=78
189 * vim600: sw=4 ts=4 fdm=marker
190 * vim<600: sw=4 ts=4