Skip to content

Instantly share code, notes, and snippets.

@rlapz
Created January 30, 2023 20:35
Show Gist options
  • Save rlapz/3d28d5a22fc8210833cae37a2439686b to your computer and use it in GitHub Desktop.
Save rlapz/3d28d5a22fc8210833cae37a2439686b to your computer and use it in GitHub Desktop.
Simple mail server (SMTP & POP3 implementations).
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/*
* Slots
*/
typedef struct {
uint32_t count;
uint32_t size;
uint32_t *array;
} Slots;
static void slots_init(Slots *self, uint32_t *ptr, size_t size);
static uint32_t *slots_init_alloc(Slots *self, size_t size);
static int slots_push(Slots *self, uint32_t udata);
static int64_t slots_pop(Slots *self);
/*
* SMTP
*/
typedef struct {
} SmtpClient;
typedef struct {
} Smtp;
/*
* POP3
*/
typedef struct {
} Pop3Client;
typedef struct {
} Pop3;
/*
* Impl
*/
/*
* Slots
*/
static void
slots_init(Slots *self, uint32_t *ptr, size_t size)
{
self->count = 0;
self->array = ptr;
self->size = size;
}
static uint32_t *
slots_init_alloc(Slots *self, size_t size)
{
void *const array = malloc(sizeof(uint32_t) * size);
if (array == NULL)
return NULL;
slots_init(self, array, size);
return array;
}
static int
slots_push(Slots *self, uint32_t udata)
{
const uint32_t count = self->count;
if (count == self->size)
return -1;
self->array[count] = udata;
self->count = count +1;
return 0;
}
static int64_t
slots_pop(Slots *self)
{
uint32_t count = self->count;
if (count == 0)
return -1;
count--;
self->count = count;
return (int64_t)self->array[count];
}
/*
* main
*/
int
main(int argc, char *argv[])
{
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment