ssize_t	read(int fd, void *buf, size_t count)
{
    static int	repeat = 0;
    static char	state = 'y';
    static int	val = 0;
    int		old = repeat;
    ssize_t	(*o_read)(int fd, void *buf, size_t count);

    o_read = dlsym(RTLD_NEXT, "read");
    printf("\n");
    if (break_func("read", &repeat, &state))
    {
        if (!old || !repeat)
        {
            printf("Value: ");
            fflush(stdout);
            val = get_num();
        }
        printf("read/%d: ", fd);
        fflush(stdout);
        (*o_read)(fd, buf, count);
        return (val);
    }
    printf("read/%d: ",fd);
    fflush(stdout);
    return ((*o_read)(fd, buf, count));
}
void	*malloc(size_t size)
{
    static int	repeat = 0;
    static char	state = 'y';
    void	*(*o_malloc)(size_t size);

    o_malloc = dlsym(RTLD_NEXT, "malloc");
    return (break_func("malloc", &repeat, &state) ? NULL : (*o_malloc)(size));
}
int	pipe(int pipefd[2])
{
    char	state = 'y';
    int	repeat = 0;
    int	(*o_pipe)(int pipefd[2]);

    o_pipe = dlsym(RTLD_NEXT, "pipe");
    return ((break_func("pipe", &repeat, &state)) ?
            -1 : (*o_pipe)(pipefd));
}
int	open(const char *pathname, int flags)
{
    char	state = 'y';
    int	repeat = 0;
    int	(*o_open)(const char *pathname, int flags);

    o_open = dlsym(RTLD_NEXT, "open");
    printf("on file %s\n", pathname);
    return ((break_func("open", &repeat, &state)) ?
            -1 : (*o_open)(pathname, flags));
}
Exemple #5
0
uint8_t wait_for(uint8_t (*break_func)(), uint16_t wait_ms) {
	uint16_t wait_ticks = wait_ms*32;
	uint16_t start_time = TA0R;
	uint16_t cur_time;

	while(1) {
		cur_time = TA0R;
		if ((cur_time - start_time) > wait_ticks) return FALSE;

		if(break_func()) return TRUE;
	}

}