6 * XXX We need to find a better place for these things...
9 bool perf_guest
= false;
11 void event_attr_init(struct perf_event_attr
*attr
)
14 attr
->exclude_host
= 1;
16 attr
->exclude_guest
= 1;
19 int mkdir_p(char *path
, mode_t mode
)
28 if (stat(path
, &st
) == 0)
33 while ((d
= strchr(d
, '/'))) {
35 err
= stat(path
, &st
) && mkdir(path
, mode
);
42 return (stat(path
, &st
) && mkdir(path
, mode
)) ? -1 : 0;
45 static int slow_copyfile(const char *from
, const char *to
)
50 FILE *from_fp
= fopen(from
, "r"), *to_fp
;
55 to_fp
= fopen(to
, "w");
59 while (getline(&line
, &n
, from_fp
) > 0)
60 if (fputs(line
, to_fp
) == EOF
)
72 int copyfile(const char *from
, const char *to
)
82 if (st
.st_size
== 0) /* /proc? do it slowly... */
83 return slow_copyfile(from
, to
);
85 fromfd
= open(from
, O_RDONLY
);
89 tofd
= creat(to
, 0755);
93 addr
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_PRIVATE
, fromfd
, 0);
94 if (addr
== MAP_FAILED
)
97 if (write(tofd
, addr
, st
.st_size
) == st
.st_size
)
100 munmap(addr
, st
.st_size
);
111 unsigned long convert_unit(unsigned long value
, char *unit
)
133 int readn(int fd
, void *buf
, size_t n
)
135 void *buf_start
= buf
;
138 int ret
= read(fd
, buf
, n
);
147 return buf
- buf_start
;