Compare commits

...

2 commits

10 changed files with 68 additions and 5635 deletions

3
.gitignore vendored
View file

@ -78,3 +78,6 @@ Makefile
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,autotools
fckgw
*.o
*~

View file

@ -1 +1,7 @@
SUBDIRS = src
AM_CFLAGS = -std=c17
.PHONY: run
run:
./src/fckgw

View file

@ -2,6 +2,5 @@ AC_INIT([fckgw],[1.0])
AC_CONFIG_SRCDIR([src/main.c])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
CFLAGS="$CFLAGS -std=c17"
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT

View file

@ -1,6 +0,0 @@
AC_INIT([fckgw], [1.0])
AC_CONFIG_SRCDIR([src/main.c])
AM_INIT_AUTOMAKE([-Wall -Wextra -Werror foreign])
AC_PROG_CC_STDC
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT

5626
configure~

File diff suppressed because it is too large Load diff

View file

@ -1,2 +1,2 @@
bin_PROGRAMS = fckgw
fckgw_SOURCES = main.c
fckgw_SOURCES = main.c code.c

24
src/code.c Normal file
View file

@ -0,0 +1,24 @@
#include <stdint.h>
#include <stdio.h>
#include <sys/random.h>
#include <time.h>
#include "code.h"
#include "errors.h"
int code_init(struct code *key) {
struct timespec ts;
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
perror("Unable to read clock 'CLOCK_REALTIME'");
return ERR_CLOCK_READ;
}
key->unix_ts_sec = ts.tv_sec;
key->unix_ts_msec = ts.tv_nsec / 1000000;
key->purpose = ACCESS;
return 0;
}

23
src/code.h Normal file
View file

@ -0,0 +1,23 @@
#include <stdint.h>
#include <time.h>
#ifdef __SIZEOF_INT128__
typedef unsigned __int128 uint128_t;
#endif
enum code_purpose {
ACCESS,
DISCOUNT,
};
struct code {
time_t unix_ts_sec;
long unix_ts_msec;
enum code_purpose purpose;
uint16_t rand_a;
uint64_t rand_b;
};
int code_init(struct code *key);
uint128_t code_convert_to_num(struct code *key);

1
src/errors.h Normal file
View file

@ -0,0 +1 @@
#define ERR_CLOCK_READ 1

View file

@ -1,5 +1,14 @@
#include <stdio.h>
#include "code.h"
int main(void) {
return 0;
struct code key;
int key_init_err = code_init(&key);
if (key_init_err != 0) {
return key_init_err;
}
printf("unix_ts_sec: %ld, unix_ts_nsec: %ld, purpose: %d\n", key.unix_ts_sec, key.unix_ts_msec, key.purpose);
}