You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2006/11/02 12:08:50 UTC
svn commit: r470327 - in /lucene/lucy/trunk/charmonizer/src/Charmonizer:
Modules/LargeFiles.charm Modules/LargeFiles.harm Test/LargeFiles.charm
Author: marvin
Date: Thu Nov 2 03:08:49 2006
New Revision: 470327
URL: http://svn.apache.org/viewvc?view=rev&rev=470327
Log:
Change LargeFiles module to export off64_t, ftello64, and fseeko64 rather than
the previous made-up names. Refactor the LargeFiles probe module for
compactness.
Modified:
lucene/lucy/trunk/charmonizer/src/Charmonizer/Modules/LargeFiles.charm
lucene/lucy/trunk/charmonizer/src/Charmonizer/Modules/LargeFiles.harm
lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/LargeFiles.charm
Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Modules/LargeFiles.charm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Modules/LargeFiles.charm?view=diff&rev=470327&r1=470326&r2=470327
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Modules/LargeFiles.charm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Modules/LargeFiles.charm Thu Nov 2 03:08:49 2006
@@ -10,6 +10,26 @@
#include <stdlib.h>
#include <stdio.h>
+typedef struct off64_combo {
+ const char *includes;
+ const char *ftell_com;
+ const char *fseek_com;
+ const char *type;
+} off64_combo;
+
+static off64_combo off64_combos[] = {
+ { "#include <sys/types.h>\n", "ftello64", "fseeko64", "off64_t" },
+ { "#include <sys/types.h>\n", "ftello", "fseeko", "off_t" },
+ { "", "ftell","fseek", "long" },
+ { "", "_ftelli64","_fseeki64", "__int64" },
+ { NULL, NULL, NULL, NULL }
+};
+
+/* Check what name 64-bit ftell, fseek go by.
+ */
+static chaz_bool_t
+probe_off64(off64_combo *combo);
+
/* Determine whether we can use sparse files.
*/
static chaz_bool_t
@@ -32,95 +52,14 @@
static char ftell_command[10];
static char loff_type[10];
-/* code for checking ftello/fseeko and off_t */
-static char ftello_code[] = METAQUOTE
- #include "_charm.h"
- #include <sys/types.h>
- int main() {
- off_t foo;
- Charm_Setup;
- printf("%d", (int)sizeof(off_t));
- foo = ftello(stdout);
- fseeko(stdout, 0, SEEK_SET);
- return 0;
- }
-METAQUOTE;
-
-/* code for checking ftello64/fseeko64 and off64_t */
-static char ftello64_code[] = METAQUOTE
- #include "_charm.h"
- int main() {
- off64_t foo;
- Charm_Setup;
- printf("%d", (int)sizeof(off64_t));
- foo = ftello64(stdout);
- fseeko64(stdout, 0, SEEK_SET);
- return 0;
- }
-METAQUOTE;
-
-/* code for checking size of long */
-static char sizeof_long_code[] = METAQUOTE
- #include "_charm.h"
- int main() {
- Charm_Setup;
- printf("%d\n", (int)sizeof(long));
- return 0;
- }
-METAQUOTE;
-
void
chaz_LargeFiles_run(FILE *conf_fh)
{
- char *output;
- size_t output_len;
- chaz_bool_t has_off64_t = false;
- int sizeof_off_t = -1;
- int sizeof_long = -1;
chaz_bool_t success = false;
+ unsigned i;
Start_Run(conf_fh, "LargeFiles");
- /* check for ftello, fseeko, and 64-bit off_t */
- output = capture_output(ftello_code, strlen(ftello_code), &output_len);
- if (output != NULL) {
- sizeof_off_t = strtol(output, NULL, 10);
- if (sizeof_off_t == 8) {
- success = true;
- strcpy(fseek_command, "fseeko");
- strcpy(ftell_command, "ftello");
- strcpy(loff_type, "off_t");
- }
- }
-
- /* check for ftello64, fseek064, and off64_t */
- if (!success) {
- output = capture_output(ftello64_code, strlen(ftello64_code),
- &output_len);
- if (output != NULL) {
- success = true;
- has_off64_t = true;
- strcpy(fseek_command, "fseeko64");
- strcpy(ftell_command, "ftello64");
- strcpy(loff_type, "off64_t");
- }
- }
-
- /* if longs are 8 bytes, then ftell/fseek will work fine */
- if (!success){
- output = capture_output(sizeof_long_code, strlen(sizeof_long_code),
- &output_len);
- if (output != NULL) {
- sizeof_long = strtol(output, NULL, 10);
- if (sizeof_long == 8) {
- success = true;
- strcpy(fseek_command, "fseek");
- strcpy(ftell_command, "ftell");
- strcpy(loff_type, "long");
- }
- }
- }
-
/* check for sparse files */
if (check_sparse_files()) {
append_conf(conf_fh, "#define CHAZ_HAS_SPARSE_FILES\n");
@@ -132,31 +71,97 @@
append_conf(conf_fh, "#define CHAZ_NO_SPARSE_FILES\n");
}
+ /* see if off64_t and friends exist or have synonyms */
+ for (i = 0; off64_combos[i].includes != NULL; i++) {
+ off64_combo combo = off64_combos[i];
+ success = probe_off64(&combo);
+ if (success) {
+ strcpy(fseek_command, combo.fseek_com);
+ strcpy(ftell_command, combo.ftell_com);
+ strcpy(loff_type, combo.type);
+ break;
+ }
+ }
+
+
+
/* write the affirmations/definitions */
if (success) {
append_conf(conf_fh,
- "#define %sHAS_LARGE_FILE_SUPPORT\n"
- "#define %sLOFFSET_TYPE %s\n"
- "#define %slftell %s\n"
- "#define %slfseek %s\n",
- constant_prefix,
- constant_prefix, loff_type,
- function_prefix, ftell_command,
- function_prefix, fseek_command
- );
+ "#define %sHAS_LARGE_FILE_SUPPORT\n", constant_prefix );
+ /* alias these only if they're not already provided and correct */
+ if (strcmp(loff_type, "off64_t") != 0) {
+ append_conf(conf_fh,
+ "#define %soff64_t %s\n"
+ "#define %sftello64 %s\n"
+ "#define %sfseeko64 %s\n",
+ constant_prefix, loff_type,
+ function_prefix, ftell_command,
+ function_prefix, fseek_command
+ );
+ }
}
/* short names */
if (want_short_names && success) {
Start_Short_Names(conf_fh);
shorten_constant(conf_fh, "HAS_LARGE_FILE_SUPPORT");
- shorten_constant(conf_fh, "LOFFSET_TYPE");
- shorten_function(conf_fh, "lftell");
- shorten_function(conf_fh, "lfseek");
+
+ /* alias these only if they're not already provided and correct */
+ if (strcmp(loff_type, "off64_t") != 0) {
+ shorten_constant(conf_fh, "off64_t");
+ shorten_function(conf_fh, "ftello64");
+ shorten_function(conf_fh, "fseeko64");
+ }
End_Short_Names(conf_fh);
}
+ free(code_buf);
End_Run(conf_fh);
+}
+
+/* code for checking ftello64 and friends */
+static char off64_code[] = METAQUOTE
+ %s
+ #include "_charm.h"
+ int main() {
+ %s foo;
+ Charm_Setup;
+ printf("%%d", (int)sizeof(%s));
+ foo = %s(stdout);
+ %s(stdout, 0, SEEK_SET);
+ return 0;
+ }
+METAQUOTE;
+
+
+static chaz_bool_t
+probe_off64(off64_combo *combo)
+{
+ char *output = NULL;
+ size_t output_len;
+ size_t needed = sizeof(off64_code) + (2 * strlen(combo->type))
+ + strlen(combo->ftell_com) + strlen(combo->fseek_com) + 20;
+ chaz_bool_t success = false;
+
+ if (code_buf_len < needed) {
+ code_buf = (char*)realloc(code_buf, needed);
+ code_buf_len = needed;
+ }
+
+ sprintf(code_buf, off64_code, combo->includes, combo->type, combo->type,
+ combo->ftell_com, combo->fseek_com);
+
+ output = capture_output(code_buf, strlen(code_buf),
+ &output_len);
+ if (output != NULL) {
+ long size = strtol(output, NULL, 10);
+ if (size == 8)
+ success = true;
+ free(output);
+ }
+
+ return success;
}
static chaz_bool_t
Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Modules/LargeFiles.harm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Modules/LargeFiles.harm?view=diff&rev=470327&r1=470326&r2=470327
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Modules/LargeFiles.harm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Modules/LargeFiles.harm Thu Nov 2 03:08:49 2006
@@ -6,15 +6,18 @@
#include <stdio.h>
-/* Run the LargeFiles module.
- *
- * If support for large files is detected, these symbols will be defined.
- *
+/* The LargeFiles module attempts to detect these symbols or alias them to
+ * synonyms:
+ *
+ * off64_t
+ * ftello64
+ * fseeko64
+ *
+ * If the attempt succeeds, this will be defined:
+ *
* HAS_LARGE_FILE_SUPPORT
- * loff_t
- * lftell
- * lfseek
- *
+ *
+ * Use of the off64_t symbol may require sys/types.h.
*/
void chaz_LargeFiles_run(FILE *conf_fh);
@@ -23,7 +26,6 @@
#endif
#endif /* H_CHAZ_LARGE_FILES */
-
/**
* Copyright 2006 The Apache Software Foundation
Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/LargeFiles.charm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/LargeFiles.charm?view=diff&rev=470327&r1=470326&r2=470327
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/LargeFiles.charm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Test/LargeFiles.charm Thu Nov 2 03:08:49 2006
@@ -15,13 +15,13 @@
{
int test_num = 0;
FILE *fh;
- LOFFSET_TYPE offset;
+ off64_t offset;
int check_val;
char check_char;
/* a little over 4 GB, and a little over 2 GB */
- LOFFSET_TYPE gb4_plus = ((LOFFSET_TYPE)0x7FFFFFFF << 1) + 100;
- LOFFSET_TYPE gb2_plus = (LOFFSET_TYPE)0x7FFFFFFF + 200;
+ off64_t gb4_plus = ((off64_t)0x7FFFFFFF << 1) + 100;
+ off64_t gb2_plus = (off64_t)0x7FFFFFFF + 200;
/* gb4_plus modulo 4 GB */
i32_t wrap_gb4 = gb4_plus;
@@ -31,7 +31,7 @@
*num_failed = 0;
*num_skipped = *num_tests;
- Assert_True((sizeof(LOFFSET_TYPE) == 8), "offset type has 8 bytes");
+ Assert_True((sizeof(off64_t) == 8), "off64_t type has 8 bytes");
#ifndef HAS_LARGE_FILE_SUPPORT
Skip_Remaining("No large file support");