Fix file permissions

This commit is contained in:
Curt Spark 2024-07-26 09:26:27 +01:00
parent a8ffd073c2
commit a91b447feb
3 changed files with 12 additions and 12 deletions

View File

@ -3,6 +3,6 @@
rm test.bmp
gcc -g main.c lib/*.c
./a.out
chmod 777 test.bmp
# chmod 777 test.bmp
printf "\n"
xxd test.bmp

View File

@ -52,9 +52,9 @@ bitmap_file write_to_bitmap(const bitmap *bitmap_in, const char *filename) {
bitmap_file new_bitmap_file;
int8_t write_status;
uint32_t current_byte;
uint8_t blank_byte_buffer[1] = { 255 };
uint8_t blank_byte_buffer[1] = { 0 };
uint8_t *bitmap_in_byte_ptr = (uint8_t *)bitmap_in + 2; /* Offset by two to account for padding */
int8_t fd = open(filename, O_WRONLY | O_CREAT);
int8_t fd = open(filename, O_WRONLY | O_CREAT, 0666);
if (fd == -1)
/* TODO Need an error return type */
return new_bitmap_file;
@ -82,7 +82,8 @@ int write_bitmap_pixel(const bitmap_file *bitmap_file_in, const bitmap_pixel_col
int32_t byte_position_start = byte_position_end_padded - 3;
uint8_t *bitmap_pixel_in_byte_ptr = (uint8_t *)bitmap_pixel_in;
int8_t fd = open(bitmap_file_in->filename, O_WRONLY | O_CREAT);
int8_t fd = open(bitmap_file_in->filename, O_WRONLY | O_CREAT, 0666);
if (fd == -1)
return -1;
if (byte_position_start % 4)

15
main.c
View File

@ -35,19 +35,18 @@ int main() {
//
// printf("40C == %dF\n", (int) celsius_to_farenheit(40.0));
const bitmap test = init_bitmap(2, 2);
const bitmap test = init_bitmap(3, 3);
bitmap_file test_file = write_to_bitmap(&test, "test.bmp");
bitmap_pixel_color test_pixel;
test_pixel.red = 0;
test_pixel.green = 0;
test_pixel.blue = 0;
test_pixel.red = 255;
test_pixel.green = 255;
test_pixel.blue = 255;
bitmap_pixel_color test_pixel2;
test_pixel2.red = 0;
test_pixel2.green = 0;
test_pixel2.red = 100;
test_pixel2.green = 100;
test_pixel2.blue = 255;
write_bitmap_pixel(&test_file, &test_pixel, 1, 2);
write_bitmap_pixel(&test_file, &test_pixel2, 2, 2);
write_bitmap_pixel(&test_file, &test_pixel, 1, 1);
char *reserved_memory = ss_alloc(100);
ss_alloc_free(reserved_memory);