Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2006 Pekka Riikonen
+ Copyright (C) 2006 - 2007 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
*/
-#include "silc.h"
+#include "silcruntime.h"
#include "silchttpphp.h"
/* Executes PHP code and returns result */
return NULL;
#else
memset(tmp, 0, sizeof(tmp));
- snprintf(tmp, sizeof(tmp) - 1, "/tmp/silchttpphpXXXXXX");
+ silc_snprintf(tmp, sizeof(tmp) - 1, "/tmp/silchttpphpXXXXXX");
if (mkstemp(tmp) == -1)
return NULL;
name = tmp;
SilcBuffer ret = NULL;
unsigned char tmp[8192];
FILE *fd;
- int len, off = 0;
+ int len;
SILC_LOG_DEBUG(("Executing PHP"));
memset(tmp, 0, sizeof(tmp));
- snprintf(tmp, sizeof(tmp) - 1, "php -f %s", filename);
+ silc_snprintf(tmp, sizeof(tmp) - 1, "php -f %s", filename);
#ifdef SILC_WIN32
fd = _popen(tmp, "r");
len = fread(tmp, 1, sizeof(tmp), fd);
if (len < 0) {
silc_buffer_free(ret);
+#ifdef SILC_WIN32
+ _pclose(fd);
+#else
pclose(fd);
+#endif /* SILC_WIN32 */
return NULL;
}
if (!ret) {
ret = silc_buffer_alloc(0);
if (!ret) {
- pclose(fd);
+#ifdef SILC_WIN32
+ _pclose(fd);
+#else
+ pclose(fd);
+#endif /* SILC_WIN32 */
return NULL;
}
}
silc_buffer_format(ret,
- SILC_STR_OFFSET(off),
- SILC_STR_UI_XNSTRING(tmp, len),
+ SILC_STR_ADVANCE,
+ SILC_STR_DATA(tmp, len),
SILC_STR_END);
- off += len;
}
} while (len);
- if (ret)
- silc_buffer_strformat(ret, "\0", SILC_STRFMT_END);
+ if (ret) {
+ silc_buffer_format(ret,
+ SILC_STR_ADVANCE,
+ SILC_STR_DATA('\0', 1),
+ SILC_STR_END);
+ silc_buffer_push(ret, silc_buffer_truelen(ret));
+ }
return ret;
}