exit_err(NULL == file, world, err_o);
uint16_t lines, linemax;
exit_err(textfile_sizes(file, &linemax, &lines), world, err_s);
+ char line[linemax + 1];
- char line[linemax];
struct Command * cmds = malloc(lines * sizeof(struct Command));
exit_err(NULL == line, world, err_m);
uint8_t i = 0;
- while (fgets(line, linemax, file))
+ while (fgets(line, linemax + 1, file))
{
cmds[i].id = atoi(strtok(line, " "));
copy_tokenized_string(world, &cmds[i].dsc_short, " ", err_m);
-/* Learn from "file" the largest line length (pointed to by "linemax_p") and
- * (pointed to by "n_lines_p" if it is not set to NULL) the number of lines.
+/* Learn from "file" the largest line length (pointed to by "linemax_p"; length
+ * includes newline chars) and (pointed to by "n_lines_p" if it is not set to
+ * NULL) the number of lines (= number of newline chars).
*
- * Returns 0 on success, 1 on fseek() error.
+ * Returns 0 on success, 1 on error of fseek() (called to return to initial file
+ * reading position).
*/
extern uint8_t textfile_sizes(FILE * file, uint16_t * linemax_p,
uint16_t * n_lines_p);
FILE * file = fopen(path, "r");
exit_err(NULL == file, world, err_o);
free(path);
-
uint16_t linemax;
exit_err(textfile_sizes(file, &linemax, NULL), world, err_s);
- char line[linemax];
+ char line[linemax + 1];
struct WinConf * winconf = get_winconf_by_id(world, id);
- exit_err(NULL == fgets(line, linemax, file), world, err_g);
+ exit_err(NULL == fgets(line, linemax + 1, file), world, err_g);
exit_err(NULL == (winconf->title = malloc(strlen(line))), world, err_m);
memcpy(winconf->title, line, strlen(line) - 1); /* Eliminate newline char */
winconf->title[strlen(line) - 1] = '\0'; /* char at end of string. */
- exit_err(NULL == fgets(line, linemax, file), world, err_g);
+ exit_err(NULL == fgets(line, linemax + 1, file), world, err_g);
winconf->height = atoi(line);
if (0 >= winconf->height)
{
winconf->height_type = 1;
}
- exit_err(NULL == fgets(line, linemax, file), world, err_g);
+ exit_err(NULL == fgets(line, linemax + 1, file), world, err_g);
winconf->width = atoi(line);
if (0 >= winconf->width)
{
char * path = "config/windows/toggle_order";
FILE * file = fopen(path, "r");
exit_err(NULL == file, world, err_o);
-
uint16_t linemax;
exit_err(textfile_sizes(file, &linemax, NULL), world, err_s);
+ char win_order[linemax + 1];
- char win_order[linemax];
- exit_err(NULL == fgets(win_order, linemax, file), world, err_g);
+ exit_err(NULL == fgets(win_order, linemax + 1, file), world, err_g);
exit_err(fclose(file), world, err_c);
uint8_t i = 0;
- for (; i < linemax - 2; i++)
+ for (; i < linemax - 1; i++)
{
toggle_window(world->wmeta, get_win_by_id(world, win_order[i]));
}