File: test_cowbuilder.c

package info (click to toggle)
cowdancer 0.70
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 692 kB
  • sloc: ansic: 3,695; sh: 474; makefile: 191; cpp: 6
file content (45 lines) | stat: -rwxr-xr-x 1,028 bytes parent folder | download | duplicates (2)
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
/*BINFMTC: cowbuilder.c parameter.c forkexec.c ilistcreate.c
 */

#define _GNU_SOURCE
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "file.h"
#include "parameter.h"

// utility to check hardlink count of file.
static int check_hardlink_count(const char* filename)
{
  struct stat buf;
  stat(filename, &buf);
  return buf.st_nlink;
}

int break_cowlink(const char* s);

void test_break_cowlink()
{
  char *temp = strdupa("/tmp/cowtestXXXXXX");
  char *temp2 = strdupa("/tmp/cowtestXXXXXX");
  close(mkstemp(temp));
  close(mkstemp(temp2));
  assert(check_hardlink_count(temp2) == 1);
  assert(check_hardlink_count(temp) == 1);
  assert(-1!=unlink(temp2));
  assert(-1!=link(temp, temp2));
  assert(check_hardlink_count(temp2) == 2);
  assert(check_hardlink_count(temp) == 2);
  break_cowlink(temp2);
  assert(check_hardlink_count(temp2) == 1);
  assert(check_hardlink_count(temp) == 1);
}

int main()
{
  test_break_cowlink();
  return 0;
}