Mailing List Archive

r3848 - trunk/charmonizer/src/Charmonizer/Probe
Author: creamyg
Date: 2008-09-09 11:12:46 -0700 (Tue, 09 Sep 2008)
New Revision: 3848

Modified:
trunk/charmonizer/src/Charmonizer/Probe/DirSep.charm
Log:
Improve Windows compatibility, specifically with Strawberry Perl. Include all valid headers in probe code rather than only the first. Account for one-arg vs. two-arg mkdir.

Modified: trunk/charmonizer/src/Charmonizer/Probe/DirSep.charm
===================================================================
--- trunk/charmonizer/src/Charmonizer/Probe/DirSep.charm 2008-09-09 05:31:34 UTC (rev 3847)
+++ trunk/charmonizer/src/Charmonizer/Probe/DirSep.charm 2008-09-09 18:12:46 UTC (rev 3848)
@@ -15,13 +15,16 @@
#include <sys/stat.h>
int main () {
Charm_Setup;
- if (mkdir("_charm_test_dir_orig", 0777) == 0) {
+ if (%s == 0) {
printf("1");
}
return 0;
}
METAQUOTE;

+static char mkdir_1arg[] = "mkdir(\"_charm_test_dir_orig\")";
+static char mkdir_2args[] = "mkdir(\"_charm_test_dir_orig\", 0777)";
+
static char *headers[] = {
"direct.h",
"unistd.h",
@@ -53,48 +56,51 @@
size_t inc_buf_len = 2;
size_t needed;
char *code_buf;
+ FILE *f;

START_RUN("DirSep");

/* Include any possible relevant headers. */
for (i = 0; headers[i] != NULL; i++) {
if (!check_header(headers[i]))
- break;
+ continue;
inc_buf_len = append_strings(&includes_buf, inc_buf_len, "#include <",
headers[i], ">\n", NULL);
}
- needed = strlen(mkdir_code) + inc_buf_len + 10;
+ needed = sizeof(mkdir_code) + sizeof(mkdir_2args) + inc_buf_len + 10;
code_buf = malloc(needed);
- sprintf(code_buf, mkdir_code, includes_buf);
+ sprintf(code_buf, mkdir_code, includes_buf, mkdir_2args);

/* create a directory */
output = capture_output(code_buf, strlen(code_buf), &output_len);
-
- if (output != NULL && (strcmp(output, "1") == 0)) {
- FILE *f;
-
- /* clean up */
+ if (output == NULL || (strcmp(output, "1") != 0)) {
free(output);
+ strcpy(code_buf, "");
+ needed = sizeof(mkdir_code) + sizeof(mkdir_1arg) + inc_buf_len + 10;
+ code_buf = realloc(code_buf, needed);
+ sprintf(code_buf, mkdir_code, includes_buf, mkdir_1arg);
+ output = capture_output(code_buf, strlen(code_buf), &output_len);
+ }
+ free(output);

- /* try to create files under the new directory */
- if ( (f = fopen("_charm_test_dir_orig\\backslash", "w")) != NULL)
- fclose(f);
- if ( (f = fopen("_charm_test_dir_orig/slash", "w")) != NULL)
- fclose(f);
+ /* try to create files under the new directory */
+ if ( (f = fopen("_charm_test_dir_orig\\backslash", "w")) != NULL)
+ fclose(f);
+ if ( (f = fopen("_charm_test_dir_orig/slash", "w")) != NULL)
+ fclose(f);

- /* rename the directory, and see which file we can get to */
- rename("_charm_test_dir_orig", "_charm_test_dir_mod");
- if ( (f = fopen("_charm_test_dir_mod\\backslash", "r")) != NULL) {
- fclose(f);
- strcpy(dir_sep, "\\\\");
- dir_sep_is_valid = true;
- }
- else if ( (f = fopen("_charm_test_dir_mod/slash", "r")) != NULL) {
- fclose(f);
- strcpy(dir_sep, "/");
- dir_sep_is_valid = true;
- }
+ /* rename the directory, and see which file we can get to */
+ rename("_charm_test_dir_orig", "_charm_test_dir_mod");
+ if ( (f = fopen("_charm_test_dir_mod\\backslash", "r")) != NULL) {
+ fclose(f);
+ strcpy(dir_sep, "\\\\");
+ dir_sep_is_valid = true;
}
+ else if ( (f = fopen("_charm_test_dir_mod/slash", "r")) != NULL) {
+ fclose(f);
+ strcpy(dir_sep, "/");
+ dir_sep_is_valid = true;
+ }

/* clean up - delete all possible files without verifying */
remove("_charm_test_dir_mod/slash");


_______________________________________________
kinosearch-commits mailing list
kinosearch-commits@rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch-commits