Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

eval

Name: Anonymous 2012-03-01 16:33

or the equivalent in your fag language of choice

evil? awesome? what does /prog/ think?

Name: Anonymous 2012-11-02 8:34

What is uglier?


Symta:

get FileName |c:[T:@4.utf8 L:@4.ul D:@L.y? @Xs] [[T D] @Xs,r]


C/C++:

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

typedef struct chunk {
  uint8_t Tag[5];
  uint32_t Len;
  uint8_t *Data;
  struct chunk *Next;
} chunk;

chunk *loadChunks(char *FileName) {
  int I, L;
  uint8_t *D, *P, *E;
  chunk *C=0, *T, *N;
  FILE *F = fopen(FileName, "r");
  fseek(F, 0, SEEK_END);
  L = ftell(F);
  D = P = (uint8_t *)malloc(L);
  E = P+L;
  fseek(F, 0, SEEK_SET);
  fread(D, 1, L, F);
  fclose(F);

  while (P < E) {
    T = (chunk *)malloc(sizeof(chunk));
    memcpy(T->Tag, P, 4);
    T->Tag[4] = 0;
    P += 4;
    T->Len = *(uint32_t *)P;
    P += 4;
    T->Data = (uint8_t *)malloc(T->Len);
    memcpy(T->Data, P, T->Len);
    P += T->Len;
    T->Next = C;
    C = T;
  }

  for (T = 0; C; C = N) {
    N = C->Next;
    C->Next = T;
    T = C;
  }

  free(D);
  return T;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List