init commit

This commit is contained in:
2025-04-13 21:48:15 +03:00
commit 23255e9121
192 changed files with 12200 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
enum
{
MY_INT_MAX = ~0u >> (!0),
MY_INT_MIN = ~(~0u >> (!0))
};
int
satsum(int v1, int v2)
{
if (v1 > 0 && (signed int) MY_INT_MAX - v1 < v2) {
return MY_INT_MAX;
}
if (v1 < 0 && (signed int) MY_INT_MIN - v1 > v2) {
return MY_INT_MIN;
}
return v1 + v2;
}
+45
View File
@@ -0,0 +1,45 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
enum
{
CHAR_IN_INT = 12
};
struct Elem
{
struct Elem *next;
char *str;
};
struct Elem *
dup_elem(struct Elem *head)
{
if (head == NULL) {
return NULL;
}
head->next = dup_elem(head->next);
errno = 0;
char *p;
long n = strtol(head->str, &p, 10);
if (errno || (int) n != n || n == INT_MAX || *p || p == head->str) {
return head;
}
struct Elem *new = calloc(1, sizeof(*new));
if (new == NULL) {
exit(1);
}
char *str = calloc(CHAR_IN_INT, sizeof(*str));
snprintf(str, CHAR_IN_INT, "%d", (int) n + 1);
new->str = str;
new->next = head;
return new;
}