C++ (Cpp) perror Examples

C++ (Cpp) perror - 30 examples found. These are the top rated real world C++ (Cpp) examples of perror extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
void *opendir(const char *name) {
    DIR dirp=(DIR)malloc(sizeof(struct dir));
    dirp->fd=open(name,O_RDONLY|O_DIRECTORY);
    if(dirp->fd < 0) {
        //open failed
        free(dirp);
        perror("unable to open directory\n");
        return NULL;
    }
    //open was successful
    dirp->nreads=getdents(dirp);
    //dirp->nreads=syscall_3((uint64_t)SYS_getdents,(uint64_t)dirp->fd,(uint64_t)dirp->buf,(uint64_t)DIR_BUF_SIZE);
    if(dirp->nreads==-1) {
        //error reading dir entries
        perror("unable to get dirents\n");
        free(dirp);
        return NULL;
    }
    else if(dirp->nreads==0) {
        //no entries in directory
        free(dirp);
        return (void *)1;
    }
    //initialize buffer position to start of the buffer
    dirp->bpos=0;
    //char *str=((struct dirent *)(dirp->buf))->d_name;
    //printf("%s\n",str);
    //printf("%d\n",sizeof(dirp->buf));
    return dirp;
}
Example #2
0
status_t mmfile(const char * const filename, void **data, size_t &size)
{
    struct stat sb;
    void *p;
    int fd;
    fd = open(filename, O_RDONLY);
    if(-1 == fd)
    {
        perror("cannot open file");
        return Status::FAILURE;
    }
    if(-1 == fstat(fd, &sb)) {
        perror("cannot stat file");
        return Status::FAILURE;
    }
    if(!S_ISREG(sb.st_mode)) {
        fprintf(stderr, "%s is not a file\n", filename);
        return Status::FAILURE;
    }
    p = mmap(0, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
    if(p == MAP_FAILED) {
        perror("cannot mmap file");
        return Status::FAILURE;
    }
    if(-1 == close(fd))
    {
        perror("cannot close file");
        return Status::FAILURE;
    }
    size = sb.st_size;
    *data = p;
    return Status::SUCCESS;
}
int reset_imu() {

    char msgreset[5];

    msgreset[0]=250;
    msgreset[1]=255;
    msgreset[2]=64;
    msgreset[3]=00;
    msgreset[4]=193;

    statwrite=write(fd,&msgreset,5);

    if (statwrite!=5) {

        perror("Reset unsuccessful");

        statwrite=write(fd,&msgreset,5);

        if (statwrite!=5) perror("Reset unsuccessful");

    }

    return 0;

}
Example #4
0
File: 1-4.c Project: Nan619/ltp-ddt
int main()
{
    struct sigaction act;

    act.sa_handler = handler;
    act.sa_flags = 0;
    sigemptyset(&act.sa_mask);
    if (sigaction(SIGCHLD, &act, 0) == -1) {
        perror("Unexpected error while attempting to setup test "
               "pre-conditions");
        return PTS_UNRESOLVED;
    }

    if (raise(SIGCHLD) == -1) {
        perror("Unexpected error while attempting to setup test "
               "pre-conditions");
        return PTS_UNRESOLVED;
    }

    if (handler_called) {
        printf("Test PASSED\n");
        return PTS_PASS;
    }

    printf("Test FAILED\n");
    return PTS_FAIL;
}
Example #5
0
int main()
{
    struct sigaction act;

    act.sa_handler = SIGFPE_handler;
    act.sa_flags = 0;
    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask, SIGCONT);
    if (sigaction(SIGFPE,  &act, 0) == -1) {
        perror("Unexpected error while attempting to "
               "setup test pre-conditions");
        return PTS_UNRESOLVED;
    }

    act.sa_handler = SIGCONT_handler;
    act.sa_flags = 0;
    sigemptyset(&act.sa_mask);
    if (sigaction(SIGCONT,  &act, 0) == -1) {
        perror("Unexpected error while attempting to "
               "setup test pre-conditions");
        return PTS_UNRESOLVED;
    }

    if (raise(SIGFPE) == -1) {
        perror("Unexpected error while attempting to "
               "setup test pre-conditions");
        return PTS_UNRESOLVED;
    }

    printf("Test PASSED\n");
    return PTS_PASS;
}
Example #6
0
/* This function creates a new stream socket and connects to
 * hostname:port via IPv6 or IPv4. On success, the new socket
 * is returned, a value less than zero otherwise. */
int connect_to_host(const char *hostname, unsigned short port) {
    /* taken from getaddrinfo(3) */
    struct sockaddr_in server;

    //socket erzeugen
    int sock = socket(AF_INET,SOCK_STREAM,0);
    if (sock < 0) {
        perror("socket konnte nicht erzeugt werden\n");
        exit(EXIT_FAILURE);
    }

    //informationen  anhand des hostnamens erfragen
    struct hostent *host = gethostbyname(hostname);
    if (host == NULL) {
        perror("host wurde nicht gefunden\n");
        exit(EXIT_FAILURE);
    }
    //hostaddresse definieren
    memcpy((char *)&server.sin_addr,host->h_addr,host->h_length);

    server.sin_family = AF_INET;
    server.sin_port = htons(port);

    if (connect(sock,(struct sockaddr*)&server,sizeof(server)) == -1) {
        close(sock);
        perror("connect");
    }


    return sock;
}