当前位置: 首页>>代码示例>>C++>>正文


C++ seterrno函数代码示例

本文整理汇总了C++中seterrno函数的典型用法代码示例。如果您正苦于以下问题:C++ seterrno函数的具体用法?C++ seterrno怎么用?C++ seterrno使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了seterrno函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fatfs_fcntl

static int fatfs_fcntl(mount_point_t *point, file_t *file, int cmd, int arg)
{
    privinfo_t *priv = file->ctx;

    if (priv == NULL) {
        seterrno(EINVAL);
        return -1;
    }

    switch (cmd) {
    case F_GETFL:
        return file->flags;

    case F_SETFL:
        if ((!(file->flags & FWRITE)) && (arg & FWRITE)) {
            seterrno(EINVAL);
            return -1;
        }
        file->flags = arg;
        return 0;

    default:
        seterrno(EINVAL);
        return -1;
    }
}
开发者ID:charlestac,项目名称:smileos,代码行数:26,代码来源:fatfs.c

示例2: __vfs_close

/*********************************************************************************************************
** Function name:           __vfs_close
** Descriptions:            关闭文件
** input parameters:        pid                 任务 ID
**                          fd                  文件描述符
** output parameters:       NONE
** Returned value:          0 OR -1
*********************************************************************************************************/
int __vfs_close(pid_t pid, int fd)
{
    int ret;

    vfs_file_begin(pid);
    if (point->fs->close == NULL) {
        vfs_file_end(pid);
        seterrno(ENOSYS);
        return -1;
    }
    seterrno(0);
    if (atomic_dec_and_test(&file->ref)) {
        ret = point->fs->close(point, file);
        if (ret == 0) {
            mutex_lock(&info_lock[pid], 0);
            info->files[fd] = NULL;
            mutex_unlock(&info_lock[pid]);
            vfs_file_free(file);
            atomic_dec(&point->ref);
            return ret;
        } else {
            atomic_inc(&file->ref);
        }
    } else {
        ret = 0;
    }
    vfs_file_end(pid);
    return ret;
}
开发者ID:charlestac,项目名称:smileos,代码行数:37,代码来源:vfs_file.c

示例3: fatfs_mount

static int fatfs_mount(mount_point_t *point, device_t *dev, const char *dev_name, const char *param)
{
    FATFS *fs;
    FRESULT res;

    if (dev == NULL) {
        seterrno(EINVAL);
        return -1;
    }

    fs = (FATFS *)kmalloc(sizeof(FATFS), GFP_KERNEL);
    if (fs != NULL) {
        memset(fs, 0, sizeof(FATFS));
        res = f_mount(0, fs);
        if (res != FR_OK) {
            fatfs_result_to_errno(res);
            kfree(fs);
            return -1;
        } else {
            point->ctx = fs;
            fs->drv    = dev;
            return 0;
        }
    } else {
        seterrno(ENOMEM);
        return -1;
    }
}
开发者ID:charlestac,项目名称:smileos,代码行数:28,代码来源:fatfs.c

示例4: vfs_write

/*********************************************************************************************************
** Function name:           vfs_write
** Descriptions:            写文件
** input parameters:        fd                  文件描述符
**                          buf                 数据缓冲区
**                          len                 新长度
** output parameters:       NONE
** Returned value:          成功写入的字节数 OR -1
*********************************************************************************************************/
ssize_t vfs_write(int fd, const void *buf, size_t len)
{
    ssize_t slen;
    pid_t pid = getpid();

    if (buf == NULL || len < 0) {
        seterrno(EINVAL);
        return -1;
    }

    if (len == 0) {
        seterrno(0);
        return 0;
    }

    {
        vfs_file_begin(pid);
        if (!(file->flags & FWRITE)) {
            vfs_file_end(pid);
            seterrno(EIO);
            return -1;
        }
        if (point->fs->write == NULL) {
            vfs_file_end(pid);
            seterrno(ENOSYS);
            return -1;
        }
        seterrno(0);
        slen = point->fs->write(point, file, buf, len);
        vfs_file_end(pid);
        return slen;
    }
}
开发者ID:charlestac,项目名称:smileos,代码行数:42,代码来源:vfs_file.c

示例5: caca_create_canvas

/** \brief Initialise a \e libcaca canvas.
 *
 *  Initialise internal \e libcaca structures and the backend that will
 *  be used for subsequent graphical operations. It must be the first
 *  \e libcaca function to be called in a function. caca_free_canvas()
 *  should be called at the end of the program to free all allocated resources.
 *
 *  Both the cursor and the canvas' handle are initialised at the top-left
 *  corner.
 *
 *  If an error occurs, NULL is returned and \b errno is set accordingly:
 *  - \c EINVAL Specified width or height is invalid.
 *  - \c ENOMEM Not enough memory for the requested canvas size.
 *
 *  \param width The desired canvas width
 *  \param height The desired canvas height
 *  \return A libcaca canvas handle upon success, NULL if an error occurred.
 */
caca_canvas_t * caca_create_canvas(int width, int height)
{
    caca_canvas_t *cv;

    if(width < 0 || height < 0)
    {
        seterrno(EINVAL);
        return NULL;
    }

    cv = malloc(sizeof(caca_canvas_t));

    if(!cv)
        goto nomem;

    cv->refcount = 0;
    cv->autoinc = 0;
    cv->resize_callback = NULL;
    cv->resize_data = NULL;

    cv->frame = 0;
    cv->framecount = 1;
    cv->frames = malloc(sizeof(struct caca_frame));
    if(!cv->frames)
    {
        free(cv);
        goto nomem;
    }

    cv->frames[0].width = cv->frames[0].height = 0;
    cv->frames[0].chars = NULL;
    cv->frames[0].attrs = NULL;
    cv->frames[0].x = cv->frames[0].y = 0;
    cv->frames[0].handlex = cv->frames[0].handley = 0;
    cv->frames[0].curattr = 0;
    cv->frames[0].name = strdup("frame#00000000");

    _caca_load_frame_info(cv);
    caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);

    cv->ndirty = 0;
    cv->dirty_disabled = 0;
    cv->ff = NULL;

    if(caca_resize(cv, width, height) < 0)
    {
        int saved_errno = geterrno();
        free(cv->frames[0].name);
        free(cv->frames);
        free(cv);
        seterrno(saved_errno);
        return NULL;
    }

    return cv;

nomem:
    seterrno(ENOMEM);
    return NULL;
}
开发者ID:mwgoldsmith,项目名称:caca,代码行数:78,代码来源:canvas.c

示例6: xxx_write

/*
 * 写 xxx
 */
static ssize_t xxx_write(void *ctx, file_t *file, const void *buf, size_t len)
{
    privinfo_t *priv = ctx;
    int ret;

    if (priv == NULL) {
        seterrno(EINVAL);
        return -1;
    }

    __again:
    if (atomic_read(&priv->select.flags) & VFS_FILE_ERROR) {
        seterrno(EIO);
        return -1;
    }

    if (0) {                                                            /*  如果没有空间可写            */
        ret = vfs_block_helper(&priv->select, xxx_scan, ctx, file, VFS_FILE_WRITEABLE);
        if (ret <= 0) {
            return ret;
        } else {
            goto __again;
        }
    }

    {
        /*
         * 完成写操作
         */
        return 0;
    }
}
开发者ID:charlestac,项目名称:smileos,代码行数:35,代码来源:xxxdrv.c

示例7: socket_priv_fd

/*********************************************************************************************************
** Function name:           socket_priv_fd
** Descriptions:            获得 socket 的私有文件描述符
** input parameters:        fd                  IO 系统文件描述符
** output parameters:       ctx                 上下文
** Returned value:          socket 的私有文件描述符
*********************************************************************************************************/
int socket_priv_fd(int fd, void **ctx)
{
    file_t *file;
    device_t *dev;
    privinfo_t *priv;
    int sock_fd;

    file = vfs_get_file(fd);
    if (file != NULL) {
        if (file->type & VFS_FILE_TYPE_SOCK) {
            dev = file->ctx;
            if (dev != NULL) {
                priv = dev->ctx;
                if (priv != NULL) {
                    sock_fd = priv->sock_fd;
                    *ctx = file;
                    seterrno(0);
                    return sock_fd;
                }
            }
        }
        seterrno(EFTYPE);
    }
    return -1;
}
开发者ID:charlestac,项目名称:smileos,代码行数:32,代码来源:socket.c

示例8: socket_scan

/*
 * 扫描 socket
 */
static int socket_scan(void *ctx, file_t *file, int flags)
{
    privinfo_t *priv = ctx;
    int ret;
    int readable;
    int writeable;
    int error;

    if (priv == NULL) {
        seterrno(EINVAL);
        return -1;
    }

    extern int socket_stat(int sock_fd, int *readable, int *writeable, int *error);
    ret = socket_stat(priv->sock_fd, &readable, &writeable, &error);
    if (ret < 0) {
        seterrno(EINVAL);
        return -1;
    }

    ret = 0;
    if (readable && flags & VFS_FILE_READABLE) {
        ret |= VFS_FILE_READABLE;
    }
    if (writeable && flags & VFS_FILE_WRITEABLE) {
        ret |= VFS_FILE_WRITEABLE;
    }
    if (error && flags & VFS_FILE_ERROR) {
        ret |= VFS_FILE_ERROR;
    }
    return ret;
}
开发者ID:charlestac,项目名称:smileos,代码行数:35,代码来源:socket.c

示例9: vfs_ftruncate

/*********************************************************************************************************
** Function name:           vfs_ftruncate
** Descriptions:            修改文件长度
** input parameters:        fd                  文件描述符
**                          len                 新长度
** output parameters:       NONE
** Returned value:          0 OR -1
*********************************************************************************************************/
int vfs_ftruncate(int fd, off_t len)
{
    int ret;
    pid_t pid = getpid();

    if (len < 0) {
        seterrno(EINVAL);
        return -1;
    }

    vfs_file_begin(pid);
    if (!(file->flags & FWRITE)) {
        vfs_file_end(pid);
        seterrno(EIO);
        return -1;
    }
    if (point->fs->ftruncate == NULL) {
        vfs_file_end(pid);
        seterrno(ENOSYS);
        return -1;
    }
    seterrno(0);
    ret = point->fs->ftruncate(point, file, len);
    vfs_file_end(pid);
    return ret;
}
开发者ID:charlestac,项目名称:smileos,代码行数:34,代码来源:vfs_file.c

示例10: socket_attach

/*********************************************************************************************************
** Function name:           socket_attach
** Descriptions:            联结 socket
** input parameters:        sock_fd             socket 的私有文件描述符
** output parameters:       NONE
** Returned value:          IO 系统文件描述符
*********************************************************************************************************/
int socket_attach(int sock_fd)
{
    char path[PATH_MAX];
    int fd;
    privinfo_t *priv;
    reg_t reg;
    file_t *file;
    int err;

    priv = kmalloc(sizeof(privinfo_t), GFP_KERNEL);
    if (priv != NULL) {
        priv->sock_fd = sock_fd;

        device_init(priv);

        sprintf(path, "/dev/socket%d", sock_fd);

        reg = interrupt_disable();

        if (device_create(path, "socket", priv) < 0) {
            interrupt_resume(reg);
            kfree(priv);
            return -1;
        }

        fd = vfs_open(path, O_RDWR, 0666);
        if (fd < 0) {
            geterrno(err);
            vfs_unlink(path);
            seterrno(err);
            interrupt_resume(reg);
            kfree(priv);
            return -1;
        }

        file = vfs_get_file(fd);
        if (file == NULL) {
            geterrno(err);
            vfs_close(fd);
            vfs_unlink(path);
            seterrno(err);
            interrupt_resume(reg);
            kfree(priv);
            return -1;
        }

        file->type = VFS_FILE_TYPE_SOCK;
        vfs_put_file(file);

        lwip_socket_set_ctx(sock_fd, priv);

        interrupt_resume(reg);
        seterrno(0);
        return fd;
    } else {
        seterrno(ENOMEM);
        return -1;
    }
}
开发者ID:charlestac,项目名称:smileos,代码行数:66,代码来源:socket.c

示例11: vfs_unmount

/*********************************************************************************************************
** Function name:           vfs_unmount
** Descriptions:            取消挂载文件系统
** input parameters:        path                目录 PATH
**                          param               参数
** output parameters:       NONE
** Returned value:          0 OR -1
*********************************************************************************************************/
int vfs_unmount(const char *path, const char *param)
{
    mount_point_t  *point;
    char           *pathbuf;
    char           *filepath;
    int             ret;

    pathbuf = kmalloc(PATH_BUF_LEN, GFP_KERNEL);
    if (pathbuf == NULL) {
        seterrno(ENOMEM);
        return -1;
    }

    mutex_lock(&mount_point_lock, 0);

    point = vfs_mount_point_lookup2(pathbuf, &filepath, path);          /*  查找挂载点                  */
    if (point == NULL) {
        mutex_unlock(&mount_point_lock);
        kfree(pathbuf);
        return -1;
    }

    if (point->fs->unmount == NULL) {
        mutex_unlock(&mount_point_lock);
        kfree(pathbuf);
        seterrno(ENOSYS);
        return -1;
    }

    if (atomic_read(&point->ref) != 0) {
        mutex_unlock(&mount_point_lock);
        kfree(pathbuf);
        seterrno(EBUSY);
        return -1;
    }

    vfs_sync(path);

    seterrno(0);
    ret = point->fs->unmount(point, param);                             /*  取消挂载文件系统            */
    if (ret == 0) {
        if (point->dev != NULL) {
            atomic_dec(&point->dev->ref);
        }
        atomic_dec(&point->fs->ref);
        mount_point_remove(point);
    }

    mutex_unlock(&mount_point_lock);

    kfree(pathbuf);

    return ret;
}
开发者ID:charlestac,项目名称:smileos,代码行数:62,代码来源:vfs_mount.c

示例12: fatfs_telldir

static long fatfs_telldir(mount_point_t *point, file_t *file)
{
    privinfo_t *priv = file->ctx;

    if (priv == NULL) {
        seterrno(EINVAL);
        return -1;
    }

    seterrno(ENOSYS);
    return -1;
}
开发者ID:charlestac,项目名称:smileos,代码行数:12,代码来源:fatfs.c

示例13: fatfs_seekdir

static int fatfs_seekdir(mount_point_t *point, file_t *file, long loc)
{
    privinfo_t *priv = file->ctx;

    if (priv == NULL) {
        seterrno(EINVAL);
        return -1;
    }

    seterrno(ENOSYS);
    return -1;
}
开发者ID:charlestac,项目名称:smileos,代码行数:12,代码来源:fatfs.c

示例14: fatfs_ioctl

static int fatfs_ioctl(mount_point_t *point, file_t *file, int cmd, void *arg)
{
    privinfo_t *priv = file->ctx;

    if (priv == NULL) {
        seterrno(EINVAL);
        return -1;
    }

    seterrno(ENOSYS);
    return -1;
}
开发者ID:charlestac,项目名称:smileos,代码行数:12,代码来源:fatfs.c

示例15: socket_write

/*
 * 写 socket
 */
static ssize_t socket_write(void *ctx, file_t *file, const void *buf, size_t len)
{
    privinfo_t *priv = ctx;

    if (priv == NULL) {
        seterrno(EINVAL);
        return -1;
    }
    if (atomic_read(&priv->select.flags) & VFS_FILE_ERROR) {
        seterrno(EIO);
        return -1;
    }

    return lwip_send(priv->sock_fd, buf, len, 0);
}
开发者ID:charlestac,项目名称:smileos,代码行数:18,代码来源:socket.c


注:本文中的seterrno函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。