utils.h 1.63 KB
Newer Older
1 2 3 4 5
#ifndef _UTILS_H_
#define _UTILS_H_

void new_thread(void *(*f)(void *), void *data);
void sleepms(int ms);
Cedric Roux's avatar
Cedric Roux committed
6
void bps(char *out, float v, char *suffix);
7 8 9 10 11 12 13 14 15 16 17 18 19

/****************************************************************************/
/* list                                                                     */
/****************************************************************************/

typedef struct list {
  struct list *last, *next;
  void *data;
} list;

list *list_remove_head(list *l);
list *list_append(list *l, void *data);

Cedric Roux's avatar
Cedric Roux committed
20 21 22 23
/****************************************************************************/
/* socket                                                                   */
/****************************************************************************/

24 25 26
#define DEFAULT_REMOTE_IP "127.0.0.1"
#define DEFAULT_REMOTE_PORT 2021

27 28
/* socket_send: return 0 if okay, -1 on error */
int socket_send(int socket, void *buffer, int size);
29
int get_connection(char *addr, int port);
30
/* fullread: return length read if okay (that is: 'count'), -1 on error */
31
int fullread(int fd, void *_buf, int count);
32
int connect_to(char *addr, int port);
Cedric Roux's avatar
Cedric Roux committed
33 34 35 36 37 38 39 40 41 42 43 44 45

/****************************************************************************/
/* buffer                                                                   */
/****************************************************************************/

typedef struct {
  int osize;
  int omaxsize;
  char *obuf;
} OBUF;

void PUTC(OBUF *o, char c);
void PUTS(OBUF *o, char *s);
46
void PUTS_CLEAN(OBUF *o, char *s);
Cedric Roux's avatar
Cedric Roux committed
47
void PUTI(OBUF *o, int i);
48
void PUTX2(OBUF *o, int i);
Cedric Roux's avatar
Cedric Roux committed
49
void PUTUL(OBUF *o, unsigned long i);
Cedric Roux's avatar
Cedric Roux committed
50

51
#endif /* _UTILS_H_ */