diff options
author | marha <marha@users.sourceforge.net> | 2011-01-12 20:56:18 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-01-12 20:56:18 +0000 |
commit | ca14143b18b939ee4506936e77478f8c593802b5 (patch) | |
tree | 83cf183c0a8814b67d664d002611da95bc78a98f /mesalib/src/glsl/main.cpp | |
parent | 0f84d9e7c6d9556e3b00adc5db3235c9291eeaa1 (diff) | |
parent | 2ebdcfeee38bed8c65daa78aa7d18d8d1d93ed85 (diff) | |
download | vcxsrv-ca14143b18b939ee4506936e77478f8c593802b5.tar.gz vcxsrv-ca14143b18b939ee4506936e77478f8c593802b5.tar.bz2 vcxsrv-ca14143b18b939ee4506936e77478f8c593802b5.zip |
svn merge ^/branches/released .
Diffstat (limited to 'mesalib/src/glsl/main.cpp')
-rw-r--r-- | mesalib/src/glsl/main.cpp | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/mesalib/src/glsl/main.cpp b/mesalib/src/glsl/main.cpp index fd8be6821..eac944a0d 100644 --- a/mesalib/src/glsl/main.cpp +++ b/mesalib/src/glsl/main.cpp @@ -35,11 +35,6 @@ #define O_RDONLY _O_RDONLY
#endif
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-
#include "ast.h"
#include "glsl_parser_extras.h"
#include "glsl_parser.h"
@@ -121,38 +116,40 @@ static char * load_text_file(void *ctx, const char *file_name)
{
char *text = NULL;
- struct stat st;
- ssize_t total_read = 0;
- int fd = open(file_name, O_RDONLY);
+ size_t size;
+ size_t total_read = 0;
+ FILE *fp = fopen(file_name, "rb");
- if (fd < 0) {
+ if (!fp) {
return NULL;
}
- if (fstat(fd, & st) == 0) {
- text = (char *) talloc_size(ctx, st.st_size + 1);
- if (text != NULL) {
- do {
- ssize_t bytes = read(fd, text + total_read,
- st.st_size - total_read);
- if (bytes < 0) {
- free(text);
- text = NULL;
- break;
- }
-
- if (bytes == 0) {
- break;
- }
-
- total_read += bytes;
- } while (total_read < st.st_size);
-
- text[total_read] = '\0';
- }
+ fseek(fp, 0L, SEEK_END);
+ size = ftell(fp);
+ fseek(fp, 0L, SEEK_SET);
+
+ text = (char *) talloc_size(ctx, size + 1);
+ if (text != NULL) {
+ do {
+ size_t bytes = fread(text + total_read,
+ 1, size - total_read, fp);
+ if (bytes < size - total_read) {
+ free(text);
+ text = NULL;
+ break;
+ }
+
+ if (bytes == 0) {
+ break;
+ }
+
+ total_read += bytes;
+ } while (total_read < size);
+
+ text[total_read] = '\0';
}
- close(fd);
+ fclose(fp);
return text;
}
|