static int read_str_gpio_file(uint8_t gpio_pin, const char *file_name, char *value, uint32_t max_str_length) { char path[MAX_STR_LENGTH]; if (!create_gpio_path(path, gpio_pin, file_name)) return -1; return read_str_file(path, value, max_str_length); }
int read_int_file(const char *path, uint32_t *value) { char str[MAX_STR_LENGTH]; if (read_str_file(path, str, MAX_STR_LENGTH) < 0) return -1; errno = 0; *value = strtoul(str, NULL, 10); if (errno != 0) { fprintf(stderr, "Failed to convert string %s to integer", str); return -1; } return 0; }
/* load a map file or get it from the cache */ static struct pixmap_info *load_image_mtime(char *name,time_t *mtime /*GdkWindow *win*/) { GList *cached; struct cache_entry ce_search; struct cache_entry *ce; struct stat st; char filename[512]; #ifdef USE_IMLIB GdkPixmap *p; GdkImlibImage *im; #else struct pixmap_info *p; #endif cache_count++; ce_search.name=name; p=NULL; cached=g_list_find_custom(cache_list, &ce_search,find_cache); if (cached) { ce=(struct cache_entry *)cached->data; if (ce) { ce->count=cache_count; if (mtime) *mtime=ce->mtime; return ce->p; } } if (g_list_length(cache_list)>=MAX_CACHE) { GList *rem; cache_list=g_list_sort(cache_list,compare_cache); ce=(struct cache_entry *)g_list_nth_data(cache_list,0); if (ce->p) #ifdef USE_IMLIB gdk_imlib_free_pixmap(ce->p); #else free_pinfo(ce->p); #endif /* printf("entferne %s\n",ce->name); */ g_free(ce->name); g_free(ce); rem=g_list_first(cache_list); cache_list=g_list_remove_link(cache_list,rem); g_list_free(rem); } snprintf(filename,sizeof(filename),"%s.str", name); read_str_file(filename,name); snprintf(filename,sizeof(filename),"%s.png", name); #ifndef USE_IMLIB p=load_gfxfile(filename); if (!p) { if (!stat(filename,&st)) { if (mtime) *mtime=st.st_mtime; return NULL; } snprintf(filename,sizeof(filename),"%s.jpg", name); p=load_gfxfile(filename); } #endif #ifdef USE_IMLIB im=gdk_imlib_load_image(filename); if (im) break; snprintf(filename,sizeof(filename),"%s/%s.bmp",kartenpfad[i], name); im=gdk_imlib_load_image(filename); if (im) break; #endif #ifdef USE_IMLIB if (!im) return NULL; w=im->rgb_width; h=im->rgb_height; if (!gdk_imlib_render(im,w,h)) { gdk_imlib_destroy_image(im); return NULL; } p=gdk_imlib_move_image(im); gdk_imlib_destroy_image(im); #endif if (p) { struct stat st; ce=g_malloc(sizeof(struct cache_entry)); ce->p=p; ce->name=g_strdup(name); ce->count=cache_count; cache_list=g_list_append(cache_list,ce); stat(filename,&st); ce->mtime=st.st_mtime; if (mtime) *mtime=ce->mtime; } else { if (!stat(filename,&st)) { if (mtime) *mtime=st.st_mtime; return NULL; } } return p; }