diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-11-13 12:14:12 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-11-13 12:14:12 -0500 |
| commit | 44792fd5369cfe2ad1478b72bf22b0d1829f291b (patch) | |
| tree | ee991768c1632b50eaaba6e6b4f873eae420871a /balls.c | |
| parent | 2e442c894d50c42aea748d21a6f08add123e9a70 (diff) | |
| download | balls-44792fd5369cfe2ad1478b72bf22b0d1829f291b.zip | |
move readFile() out of balls.c
Diffstat (limited to 'balls.c')
| -rw-r--r-- | balls.c | 24 |
1 files changed, 3 insertions, 21 deletions
@@ -85,7 +85,6 @@ void keyboard(unsigned char key, int x, int y); void freeCL(void); void freeGL(void); void initShaders(void); -char *readFile(const char *filename, size_t *size); void compileShader(GLint shader); void frameCount(void); void drawString(const char *str); @@ -210,7 +209,9 @@ initCL(void) { free(platforms); /* Create program from file. */ - progBuf = readFile(PROG_FILE, &progSize); + err = readFile(PROG_FILE, &progBuf, &progSize); + if (err != 0) + sysfatal("Failed to read %s\n", PROG_FILE); cpuProg = clCreateProgramWithSource(cpuContext, 1, (const char **) &progBuf, &progSize, &err); if (err < 0) sysfatal("Failed to create CPU program.\n"); @@ -726,25 +727,6 @@ initShaders(void) { glUseProgram(prog); } -char * -readFile(const char *filename, size_t *size) { - FILE *f; - char *buf; - - if ((f = fopen(filename, "r")) == NULL) - sysfatal("Failed to open file '%s'\n", filename); - fseek(f, 0, SEEK_END); - *size = ftell(f); - if ((buf = malloc((*size + 1) * sizeof(char))) == NULL) { - fclose(f); - sysfatal("Failed to allocate file buffer for '%s'\n", filename); - } - rewind(f); - fread(buf, sizeof(char), *size, f); - buf[*size] = '\0'; - fclose(f); - return buf; -} void compileShader(GLint shader) { |