format the code
This commit is contained in:
@@ -1,12 +1,10 @@
|
|||||||
#include "todo.h"
|
#include "todo.h"
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
// Memory management
|
// Memory management
|
||||||
void todo_free_item(TodoItem *item) {
|
void todo_free_item(TodoItem *item) { free(item->title); }
|
||||||
free(item->title);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Item operations
|
// Item operations
|
||||||
TodoItem todo_create_item(char *title) {
|
TodoItem todo_create_item(char *title) {
|
||||||
@@ -38,7 +36,8 @@ char *todo_item_serialize(TodoItem *item, int *buffer_size_out) {
|
|||||||
// title_length - 1 byte
|
// title_length - 1 byte
|
||||||
// title - title_length bytes
|
// title - title_length bytes
|
||||||
// completed - 1 byte
|
// completed - 1 byte
|
||||||
unsigned char title_length = item->title_length; unsigned char completed_length = sizeof(item->completed);
|
unsigned char title_length = item->title_length;
|
||||||
|
unsigned char completed_length = sizeof(item->completed);
|
||||||
int buffer_size = sizeof(unsigned char) + title_length + completed_length;
|
int buffer_size = sizeof(unsigned char) + title_length + completed_length;
|
||||||
|
|
||||||
char *buffer = malloc(buffer_size);
|
char *buffer = malloc(buffer_size);
|
||||||
@@ -48,7 +47,8 @@ char *todo_item_serialize(TodoItem *item, int *buffer_size_out) {
|
|||||||
// copy title
|
// copy title
|
||||||
memcpy(buffer + sizeof(unsigned char), item->title, title_length);
|
memcpy(buffer + sizeof(unsigned char), item->title, title_length);
|
||||||
// copy completed
|
// copy completed
|
||||||
memcpy(buffer + sizeof(unsigned char) + title_length, &item->completed, completed_length);
|
memcpy(buffer + sizeof(unsigned char) + title_length, &item->completed,
|
||||||
|
completed_length);
|
||||||
|
|
||||||
*buffer_size_out = buffer_size;
|
*buffer_size_out = buffer_size;
|
||||||
|
|
||||||
|
|||||||
8
main.c
8
main.c
@@ -1,8 +1,8 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include "engine/todo.h"
|
#include "engine/todo.h"
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define MAX_TODOS UINT_MAX
|
#define MAX_TODOS UINT_MAX
|
||||||
#define SAVE_FILE "todos.todd"
|
#define SAVE_FILE "todos.todd"
|
||||||
|
|||||||
Reference in New Issue
Block a user