Created
July 12, 2019 21:00
-
-
Save rene-d/45418a9c93727b048ef62fb63b0c9f1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <netdb.h> | |
| #include <arpa/inet.h> | |
| #include <glib.h> | |
| int main() | |
| { | |
| printf("\033[35m"); | |
| puts("hello"); | |
| struct hostent *e = gethostbyname("dns.google"); // 8.8.8.8 et 8.8.4.4 | |
| printf("e=%p\n", e); | |
| if (e != NULL) | |
| { | |
| printf("name=%s", e->h_name); | |
| unsigned int i = 0; | |
| while (e->h_addr_list[i] != NULL) | |
| { | |
| printf(" %s", inet_ntoa(*(struct in_addr *)(e->h_addr_list[i]))); | |
| i++; | |
| } | |
| printf("\n"); | |
| } | |
| GList *list = NULL; | |
| for (int i = 0; i < 10; ++i) | |
| { | |
| char *s = malloc(20); | |
| sprintf(s, "element %d", i + 1); | |
| list = g_list_append(list, s); | |
| } | |
| GList *it = g_list_first(list); | |
| while (it != NULL) | |
| { | |
| printf("%s\n", (char *)it->data); | |
| it = g_list_next(it); | |
| } | |
| printf("\033[0m"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/sh | |
| set -e | |
| # build image (compile a.c statically) | |
| docker build -q -t z:latest . | |
| # print size in bytes | |
| echo "Docker image size: $(docker inspect z:latest | jq '.[] | .Size')" | |
| docker save z:latest | tar -xO '*/layer.tar' | tar -tv | |
| # run a.out | |
| docker run -t --rm z:latest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM alpine AS builder | |
| RUN apk add gcc musl-dev glib-static glib-dev upx | |
| COPY a.c / | |
| RUN gcc a.c `pkg-config --cflags --libs glib-2.0` -static \ | |
| && strip a.out \ | |
| && upx -q a.out || true | |
| FROM scratch | |
| COPY --from=builder /a.out / | |
| ENTRYPOINT ["/a.out"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment