83 lines · 1.6 KB · C
RawDownload
#include <SDL2/SDL.h> #include "prefs.h"#include "printsdlerror.h"#include "util.h" /*Copyright (c) 2013-2021 Devine Lu Linvega2018 web port by rezmason2021 C89 port by rezmason Permission to use, copy, modify, and distribute this software for anypurpose with or without fee is hereby granted, provided that the abovecopyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIESWITH REGARD TO THIS SOFTWARE.*/ static char *_prefPath = NULL;static void *_ptr;static size_t _size; voidPrefs_Init(const char *org, const char *app, void *ptr, size_t size){	char *prefPath;	SDL_Init(0);	prefPath = SDL_GetPrefPath(org, app);	_prefPath = concat(prefPath, "prefs");	free(prefPath);	SDL_Quit(); 	_ptr = ptr;	_size = size;} voidPrefs_Quit(){	free(_prefPath);	_prefPath = NULL;} voidPrefs_Reset(){	SDL_RWops *file = SDL_RWFromFile(_prefPath, "wb");	SDL_RWclose(file);	/* printf("Clobbered the prefs file.\n"); */} voidPrefs_Load(){	SDL_RWops *file = SDL_RWFromFile(_prefPath, "rb");	SDL_ClearError(); 	if(file == NULL) {		printf("Prefs error: prefs file not found.\n");	} else {		if((long)_size != file->size(file)) {			printf("Prefs error: prefs file is invalid; ignoring.\n");		} else if(SDL_RWread(file, _ptr, _size, 1) == 0) {			printSDLError("SDL could not read the prefs file.");		} 		SDL_RWclose(file);	}} voidPrefs_Save(){	SDL_RWops *file = SDL_RWFromFile(_prefPath, "wb");	if(file == NULL) {		printSDLError("SDL could not write the prefs file.");		return;	} 	SDL_RWwrite(file, _ptr, _size, 1);	SDL_RWclose(file);}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t