Index: chmc/chmc.c =================================================================== --- chmc/chmc.c (Revision 68703) +++ chmc/chmc.c (Arbeitskopie) @@ -133,11 +133,12 @@ chm->config = config; if (strcmp(filename, "-") != 0) { - chm->fd = creat(filename, 0644); + chm->fd = open(filename, O_RDWR |O_CREAT | O_TRUNC | O_BINARY, 0644); if (chm->fd < 0) { chmcerr_set(errno, strerror(errno)); chmcerr_return_msg("creat file '%s'", filename); } + chmc_dump("file descriptor %d\n", chm->fd); } else { chm->fd = fileno(stdout); } @@ -264,7 +265,10 @@ tmpdir = chm->config->tmpdir; if (tmpdir == NULL) tmpdir = "/tmp/"; + + //fprintf(stderr, "tempdir: %s\n", tmpdir); + len = strlen(tmpdir); if (len >= PATH_MAX - 12) { chmcerr_set(errno, strerror(errno)); @@ -276,6 +280,8 @@ if (section->filename[len - 1] != '/') strcat(section->filename, "/"); + //fprintf(stderr, "file: %s\n", section->filename); + if (strcmp("MSCompressed", name) == 0) strcat(section->filename, "chmcCXXXXXX"); else @@ -978,7 +984,10 @@ struct chmcLzxInfo *lzx_info = (struct chmcLzxInfo *)arg; struct chmcSect0 *sect0 = &lzx_info->chm->sect0; int wx; + static int counter = 0; + counter+=n; + //chmc_dump("write: %u %u %u %u\n", lzx_info->section->fd, buf, n, counter); wx = write(lzx_info->section->fd, buf, n); sect0->file_len += wx; lzx_info->section->len += wx; @@ -1025,7 +1034,7 @@ // need to keep current entry file and offset trought blocks // until last entry while (todo) { - // end of entris reached? + // end of entries reached? if (lzx_info->pos == &chm->entries_list) { lzx_info->eof = 1; break; @@ -1046,7 +1055,8 @@ else if (lzx_info->fd == -1) { // open file if it isn't - lzx_info->fd = open(node->name, O_RDONLY); + //printf("open file %s\n", node->name); + lzx_info->fd = open(node->name, O_RDONLY | O_BINARY); if (lzx_info->fd < 0) { chmc_error("%s: %d: error %d: '%s' %s\n", __FILE__, __LINE__, @@ -1073,7 +1083,8 @@ { rx = read(lzx_info->fd, (char *)buf + (n - todo), toread); if (rx <= 0) { - chmc_error("read error\n"); + int temp = errno; + chmc_error("read error %s \n", strerror(temp)); lzx_info->error = 2; break; } @@ -1610,18 +1621,24 @@ assert(chm); + chmc_dump("write itsf %d\n", _CHMC_ITSF_V3_LEN); write(chm->fd, itsf, _CHMC_ITSF_V3_LEN); + chmc_dump("write sect0 %d\n", _CHMC_SECT0_LEN); write(chm->fd, sect0, _CHMC_SECT0_LEN); + chmc_dump("write itsp %d\n", _CHMC_ITSP_V1_LEN); write(chm->fd, itsp, _CHMC_ITSP_V1_LEN); list_for_each(pos, &chm->pmgl_list) { pmgl = list_entry(pos, struct chmcPmglChunkNode, list); + chmc_dump("write pmgl %d\n", _CHMC_CHUNK_LEN); write(chm->fd, &pmgl->chunk, _CHMC_CHUNK_LEN); } + chmc_dump("itsp->num_blocks %d", itsp->num_blocks); if (itsp->num_blocks > 1) { list_for_each( pos, &chm->pmgi_list ) { pmgi = list_entry(pos, struct chmcPmgiChunkNode, list); + chmc_dump("write pmgi %d\n", _CHMC_CHUNK_LEN); write(chm->fd, &pmgi->chunk, _CHMC_CHUNK_LEN); } } @@ -1640,7 +1657,7 @@ if (stat(filename, &statbuf) < 0) return errno; - in = open(filename, O_RDONLY); + in = open(filename, O_RDONLY | O_BINARY); if (in >= 0) { todo = statbuf.st_size; Index: hhp_reader.cpp =================================================================== --- hhp_reader.cpp (Revision 68703) +++ hhp_reader.cpp (Arbeitskopie) @@ -60,8 +60,10 @@ { if (has_default_value) return default_value; - else + else { + cerr << "pair '" + key + "' does not have a default value" << endl; throw domain_error("pair '" + key + "' does not have a default value"); + } } } @@ -73,13 +75,16 @@ void hhp_key_value_section::process_line(string line) { int pos_equals_sign = line.find_first_of('='); - if (pos_equals_sign == string::npos) + if (pos_equals_sign == string::npos) { + cerr << "key-value pair does not contain an equals sign" << endl; throw runtime_error("key-value pair does not contain an equals sign"); + } string key = to_upper(line.substr(0, pos_equals_sign)); string value = line.substr(pos_equals_sign + 1); - if (key.length() == 0) + if (key.length() == 0) { + cerr << "key has length zero" << endl; throw runtime_error("key has length zero"); - + } entries.find(key)->second->set_value(value); } @@ -86,8 +91,10 @@ void hhp_key_value_section::add_entry(hhp_pair* entry) { string upper_case_key = to_upper(entry->get_key()); - if (entries.count(upper_case_key) != 0) + if (entries.count(upper_case_key) != 0) { + cerr << "trying to redundantly add key '" + upper_case_key + "'" << endl; throw logic_error("trying to redundantly add key '" + upper_case_key + "'"); + } entries.insert(pair(upper_case_key, entry)); } @@ -171,8 +178,10 @@ void hhp_reader::add_section(hhp_section* section) { string upper_case_name = to_upper(section->get_name()); - if (sections.count(upper_case_name) != 0) + if (sections.count(upper_case_name) != 0) { + cerr << "trying to redundantly add section '" + upper_case_name + "'" << endl; throw logic_error("trying to redundantly add section '" + upper_case_name + "'"); + } sections.insert(pair(upper_case_name, section)); } Index: hhpcomp.cpp =================================================================== --- hhpcomp.cpp (Revision 68703) +++ hhpcomp.cpp (Arbeitskopie) @@ -62,11 +62,14 @@ struct chmcFile chm; struct chmcConfig chm_config; + memset(&chm, 0, sizeof(struct chmcFile)); + memset(&chm_config, 0, sizeof(struct chmcConfig)); chm_config.title = project_file.get_title_string().c_str(); chm_config.hhc = project_file.get_contents_file_string().c_str(); chm_config.hhk = project_file.get_index_file_string().c_str(); chm_config.deftopic = project_file.get_default_topic_string().c_str(); chm_config.language = project_file.get_language_code(); + chm_config.tmpdir = "."; int err; err = chmc_init(&chm, replace_backslashes(project_file.get_compiled_file_string()).c_str(), &chm_config); Index: port/mkstemps.c =================================================================== --- port/mkstemps.c (Revision 68688) +++ port/mkstemps.c (Arbeitskopie) @@ -1,139 +0,0 @@ -/* Copyright (C) 1991, 1992, 1996, 1998 Free Software Foundation, Inc. - This file is derived from mkstemp.c from the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_SYS_TIME_H -#include -#endif -#ifdef HAVE_PROCESS_H -#include -#endif - -/* We need to provide a type for gcc_uint64_t. */ -#ifdef __GNUC__ -__extension__ typedef unsigned long long gcc_uint64_t; -#else -typedef unsigned long gcc_uint64_t; -#endif - -#ifndef TMP_MAX -#define TMP_MAX 16384 -#endif - -/* - -@deftypefn Replacement int mkstemps (char *@var{template}, int @var{suffix_len}) - -Generate a unique temporary file name from @var{template}. -@var{template} has the form: - -@example - @var{path}/ccXXXXXX@var{suffix} -@end example - -@var{suffix_len} tells us how long @var{suffix} is (it can be zero -length). The last six characters of @var{template} before @var{suffix} -must be @samp{XXXXXX}; they are replaced with a string that makes the -filename unique. Returns a file descriptor open on the file for -reading and writing. - -@end deftypefn - -*/ - -int -mkstemps ( - char *template, - int suffix_len) -{ - static const char letters[] - = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - static gcc_uint64_t value; -#ifdef HAVE_GETTIMEOFDAY - struct timeval tv; -#endif - char *XXXXXX; - size_t len; - int count; - - len = strlen (template); - - if ((int) len < 6 + suffix_len - || strncmp (&template[len - 6 - suffix_len], "XXXXXX", 6)) - { - return -1; - } - - XXXXXX = &template[len - 6 - suffix_len]; - -#ifdef HAVE_GETTIMEOFDAY - /* Get some more or less random data. */ - gettimeofday (&tv, NULL); - value += ((gcc_uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid (); -#else - value += getpid (); -#endif - - for (count = 0; count < TMP_MAX; ++count) - { - gcc_uint64_t v = value; - int fd; - - /* Fill in the random bits. */ - XXXXXX[0] = letters[v % 62]; - v /= 62; - XXXXXX[1] = letters[v % 62]; - v /= 62; - XXXXXX[2] = letters[v % 62]; - v /= 62; - XXXXXX[3] = letters[v % 62]; - v /= 62; - XXXXXX[4] = letters[v % 62]; - v /= 62; - XXXXXX[5] = letters[v % 62]; - -#ifdef VMS - fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600, "fop=tmd"); -#else - fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600); -#endif - if (fd >= 0) - /* The file does not exist. */ - return fd; - - /* This is a random value. It is only necessary that the next - TMP_MAX values generated by adding 7777 to VALUE are different - with (module 2^32). */ - value += 7777; - } - - /* We return the null string if we can't find a unique file name. */ - template[0] = '\0'; - return -1; -} Index: port/mkstemps.c =================================================================== --- port/mkstemps.c (Revision 0) +++ port/mkstemps.c (Arbeitskopie) @@ -0,0 +1,141 @@ +/* Copyright (C) 1991, 1992, 1996, 1998 Free Software Foundation, Inc. + This file is derived from mkstemp.c from the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_PROCESS_H +#include +#endif + +/* We need to provide a type for gcc_uint64_t. */ +#ifdef __GNUC__ +__extension__ typedef unsigned long long gcc_uint64_t; +#else +typedef unsigned long gcc_uint64_t; +#endif + +#ifndef TMP_MAX +#define TMP_MAX 16384 +#endif + +/* + +@deftypefn Replacement int mkstemps (char *@var{template}, int @var{suffix_len}) + +Generate a unique temporary file name from @var{template}. +@var{template} has the form: + +@example + @var{path}/ccXXXXXX@var{suffix} +@end example + +@var{suffix_len} tells us how long @var{suffix} is (it can be zero +length). The last six characters of @var{template} before @var{suffix} +must be @samp{XXXXXX}; they are replaced with a string that makes the +filename unique. Returns a file descriptor open on the file for +reading and writing. + +@end deftypefn + +*/ + +int +mkstemps ( + char *template, + int suffix_len) +{ + static const char letters[] + = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + static gcc_uint64_t value; +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; +#endif + char *XXXXXX; + size_t len; + int count; + + len = strlen (template); + + if ((int) len < 6 + suffix_len + || strncmp (&template[len - 6 - suffix_len], "XXXXXX", 6)) + { + + printf("wrong parameter\n"); + return -1; + } + + XXXXXX = &template[len - 6 - suffix_len]; + +#ifdef HAVE_GETTIMEOFDAY + /* Get some more or less random data. */ + gettimeofday (&tv, NULL); + value += ((gcc_uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid (); +#else + value += getpid (); +#endif + + for (count = 0; count < TMP_MAX; ++count) + { + gcc_uint64_t v = value; + int fd; + + /* Fill in the random bits. */ + XXXXXX[0] = letters[v % 62]; + v /= 62; + XXXXXX[1] = letters[v % 62]; + v /= 62; + XXXXXX[2] = letters[v % 62]; + v /= 62; + XXXXXX[3] = letters[v % 62]; + v /= 62; + XXXXXX[4] = letters[v % 62]; + v /= 62; + XXXXXX[5] = letters[v % 62]; + +#ifdef VMS + fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600, "fop=tmd"); +#else + fd = open (template, O_RDWR|O_CREAT|O_EXCL|O_BINARY, 0600); +#endif + if (fd >= 0) { + /* The file does not exist. */ + return fd; + } + /* This is a random value. It is only necessary that the next + TMP_MAX values generated by adding 7777 to VALUE are different + with (module 2^32). */ + value += 7777; + } + + /* We return the null string if we can't find a unique file name. */ + template[0] = '\0'; + return -1; +} Eigenschaftsänderungen: port/mkstemps.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: utils.cpp =================================================================== --- utils.cpp (Revision 68703) +++ utils.cpp (Arbeitskopie) @@ -20,6 +20,7 @@ #include #include #include +#include #if defined(_WIN32) #define WIN32_LEAN_AND_MEAN @@ -50,8 +51,10 @@ #else temp = realpath(path, NULL); #endif - if (temp == NULL) + if (temp == NULL) { + cerr << "realpath failed" << endl; throw runtime_error("realpath failed"); + } string result(temp); #if !defined(_WIN32) free(temp);