File: byte_copy.c

package info (click to toggle)
libowfat 0.34-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,288 kB
  • sloc: ansic: 20,181; makefile: 16
file content (71 lines) | stat: -rw-r--r-- 1,921 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "byte.h"
#include <assert.h>
#include "errmsg.h"
#include <string.h>

char buf[4096];
char text[128];

int main() {
  memset(buf,0,sizeof(buf));
  strcpy(text,"this is a test!\n");

//  carp("both aligned");
  byte_copy(buf,16,text);
  assert(memcmp(buf,"this is a test!\n\0",18)==0);

  memset(buf,0,sizeof(buf));
//  carp("destination aligned, source unaligned");
  byte_copy(buf,15,text+1);
  assert(memcmp(buf,"his is a test!\n\0\0",18)==0);

  memset(buf,0,sizeof(buf));
//  carp("destination unaligned, source aligned");
  byte_copy(buf+1,15,text);
  assert(memcmp(buf,"\0this is a test!\0\0",18)==0);

  memset(buf,0,sizeof(buf));
//  carp("both unaligned");
  byte_copy(buf+1,10,text+3);
  assert(memcmp(buf,"\0s is a tes\0\0",14)==0);

  memset(buf,0,sizeof(buf));
  byte_copyr(buf,16,text);
  assert(memcmp(buf,"this is a test!\n\0",18)==0);

  memset(buf,0,sizeof(buf));
  byte_copyr(buf,15,text+1);
  assert(memcmp(buf,"his is a test!\n\0\0",18)==0);

  memset(buf,0,sizeof(buf));
  byte_copyr(buf+1,15,text);
  assert(memcmp(buf,"\0this is a test!\0\0",18)==0);

  memset(buf,0,sizeof(buf));
  byte_copyr(buf+1,10,text+3);
  assert(memcmp(buf,"\0s is a tes\0\0",14)==0);

  memset(buf,0,sizeof(buf));
  byte_copy(buf,16,text);
  byte_copy(buf,16,buf+1);
  assert(memcmp(buf,"his is a test!\n\0\0",18)==0);

  memset(buf,0,sizeof(buf));
  byte_copy(buf,16,text);
  byte_copyr(buf+1,16,buf);
  assert(memcmp(buf,"tthis is a test!\n",18)==0);

  assert(byte_diff(text,15,"this is a test!")==0);
  assert(byte_diff(text,16,"this is a test!")>0);
  assert(byte_diff("this is a test!",16,text)<0);

  assert(byte_chr("0123456789abcdef",17,'9')==9);
  assert(byte_rchr("0123456789abcdef",17,'9')==9);
  assert(byte_chr("0123456789abcdef",17,'A')==17);
  assert(byte_rchr("0123456789abcdef",17,'A')==17);

  byte_zero(buf,16);
  assert(byte_equal(buf,16,"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"));

  return 0;
}