summaryrefslogtreecommitdiff
path: root/util/romcc/romcc.c
diff options
context:
space:
mode:
authorPatrick Georgi <patrick.georgi@coresystems.de>2009-11-21 19:54:02 +0000
committerPatrick Georgi <patrick.georgi@coresystems.de>2009-11-21 19:54:02 +0000
commit26774f2b729d791c9dbf5ba0f7fcf4a59e3795a5 (patch)
tree0c6bd1252925799a2f9f7f62707d24b663170302 /util/romcc/romcc.c
parentb198a478ed190552f5228e43bc34391ca7b0f2dd (diff)
downloadcoreboot-26774f2b729d791c9dbf5ba0f7fcf4a59e3795a5.tar.xz
Make the kconfig-style build work in mingw:
* use relative paths in ldscript.ld and crt0_includes.h * avoid use of dd(1) in xcompile * build libregex for kconfig, if necessary * work around missing utsname on win32 * unlink targets before rename on win32 * implement (crude) mkstemp for win32 * avoid open/read/close, use fopen/fread/fclose instead * don't free certain data structures in romcc on win32 to avoid crashes (likely use-after-free()) * handle "\CRLF" and win32 style absolute paths (X:/ or X:\) in romcc * make lzma (part of cbfstool) build on XP * implement ntohl/htonl on win32 * handle CRLF in awk script * set larger stack for romcc on win32 Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de> Acked-by: Peter Stuge <peter@stuge.se> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4952 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/romcc/romcc.c')
-rw-r--r--util/romcc/romcc.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/util/romcc/romcc.c b/util/romcc/romcc.c
index 3ae24e2a69..6f3a44bb70 100644
--- a/util/romcc/romcc.c
+++ b/util/romcc/romcc.c
@@ -219,11 +219,10 @@ static int exists(const char *dirname, const char *filename)
static char *slurp_file(const char *dirname, const char *filename, off_t *r_size)
{
char cwd[MAX_CWD_SIZE];
- int fd;
char *buf;
off_t size, progress;
ssize_t result;
- struct stat stats;
+ FILE* file;
if (!filename) {
*r_size = 0;
@@ -233,25 +232,22 @@ static char *slurp_file(const char *dirname, const char *filename, off_t *r_size
die("cwd buffer to small");
}
xchdir(dirname);
- fd = open(filename, O_RDONLY);
+ file = fopen(filename, "rb");
xchdir(cwd);
- if (fd < 0) {
+ if (file == NULL) {
die("Cannot open '%s' : %s\n",
filename, strerror(errno));
}
- result = fstat(fd, &stats);
- if (result < 0) {
- die("Cannot stat: %s: %s\n",
- filename, strerror(errno));
- }
- size = stats.st_size;
+ fseek(file, 0, SEEK_END);
+ size = ftell(file);
+ fseek(file, 0, SEEK_SET);
*r_size = size +1;
buf = xmalloc(size +2, filename);
buf[size] = '\n'; /* Make certain the file is newline terminated */
buf[size+1] = '\0'; /* Null terminate the file for good measure */
progress = 0;
while(progress < size) {
- result = read(fd, buf + progress, size - progress);
+ result = fread(buf + progress, 1, size - progress, file);
if (result < 0) {
if ((errno == EINTR) || (errno == EAGAIN))
continue;
@@ -260,11 +256,7 @@ static char *slurp_file(const char *dirname, const char *filename, off_t *r_size
}
progress += result;
}
- result = close(fd);
- if (result < 0) {
- die("Close of %s failed: %s\n",
- filename, strerror(errno));
- }
+ fclose(file);
return buf;
}
@@ -3863,15 +3855,16 @@ static const char *next_char(struct file_state *file, const char *pos, int index
}
/* Is this an escaped newline? */
if (file->join_lines &&
- (c == '\\') && (pos + size < end) && (pos[1] == '\n'))
+ (c == '\\') && (pos + size < end) && ((pos[1] == '\n') || ((pos[1] == '\r') && (pos[2] == '\n'))))
{
+ int cr_offset = ((pos[1] == '\r') && (pos[2] == '\n'))?1:0;
/* At the start of a line just eat it */
if (pos == file->pos) {
file->line++;
file->report_line++;
- file->line_start = pos + size + 1;
+ file->line_start = pos + size + 1 + cr_offset;
}
- pos += size + 1;
+ pos += size + 1 + cr_offset;
}
/* Do I need to ga any farther? */
else if (index == 0) {
@@ -5088,7 +5081,7 @@ static void compile_file(struct compile_state *state, const char *filename, int
if (getcwd(cwd, sizeof(cwd)) == 0) {
die("cwd buffer to small");
}
- if (subdir[0] == '/') {
+ if ((subdir[0] == '/') || ((subdir[1] == ':') && ((subdir[2] == '/') || (subdir[2] == '\\')))) {
file->dirname = xmalloc(subdir_len + 1, "dirname");
memcpy(file->dirname, subdir, subdir_len);
file->dirname[subdir_len] = '\0';
@@ -15148,7 +15141,9 @@ static void free_basic_block(struct compile_state *state, struct block *block)
}
}
memset(block, -1, sizeof(*block));
+#ifndef WIN32
xfree(block);
+#endif
}
static void free_basic_blocks(struct compile_state *state,