Changeset 36


Ignore:
Timestamp:
11/07/10 01:36:30 (13 years ago)
Author:
atzm
Message:
  • check dictionary loadable
Location:
trunk/pymigemo
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/pymigemo/ChangeLog

    • Property svn:keywords set to Id
    r34 r36  
     12010-11-07  Atzm WATANABE  <atzm@atzm.org> 
     2 
     3        * pymigemo.c (isloadable): check dictionary loadable 
     4 
    152010-11-06  Atzm WATANABE  <atzm@atzm.org> 
    26 
     
    2327 
    2428        * initial 
     29 
     30$Id$ 
  • trunk/pymigemo/LICENSE

    r30 r36  
    1 Copyright (c) 2005-2009, Atzm WATANABE <atzm@atzm.org> 
     1Copyright (c) 2005-2010, Atzm WATANABE <atzm@atzm.org> 
    22All rights reserved. 
    33 
  • trunk/pymigemo/pymigemo.c

    r35 r36  
    1111#include <stdbool.h> 
    1212#include <string.h> 
     13#include <errno.h> 
     14#include <sys/types.h> 
     15#include <sys/stat.h> 
     16#include <fcntl.h> 
     17#include <unistd.h> 
    1318 
    1419#define PYMIGEMO_VERSION "0.3" 
     
    6065} 
    6166 
     67static int 
     68isloadable(const char *path) 
     69{ 
     70    struct stat st; 
     71    int ret = 0; 
     72    int fd  = open(path, O_RDONLY); 
     73 
     74    if (fd < 0) { 
     75        return errno; 
     76    } 
     77 
     78    if (fstat(fd, &st) < 0) { 
     79        ret = errno; 
     80        goto isloadable_end; 
     81    } 
     82    if (S_ISDIR(st.st_mode)) { 
     83        ret = EISDIR; 
     84        goto isloadable_end; 
     85    } 
     86 
     87  isloadable_end: 
     88    if (close(fd) < 0) { 
     89        ret = errno; 
     90    } 
     91    return ret; 
     92} 
     93 
    6294static void 
    6395Migemo_dealloc(Migemo *self) 
     
    97129 
    98130    if (dictionary) { 
     131        int ret = isloadable(dictionary); 
     132 
     133        if (ret != 0) { 
     134            PyErr_SetString(PyExc_ValueError, strerror(ret)); 
     135            return -1; 
     136        } 
     137 
    99138        if (self->migemo_obj) { 
    100139            migemo_close(self->migemo_obj); 
     
    241280 
    242281    if (dict_file) { 
     282        int ret = isloadable(dict_file); 
     283 
     284        if (ret != 0) { 
     285            PyErr_SetString(PyExc_ValueError, strerror(ret)); 
     286            return NULL; 
     287        } 
     288 
    243289        result = PyInt_FromLong((long)migemo_load(self->migemo_obj, dict_id, dict_file)); 
    244290    } 
  • trunk/pymigemo/setup.py

    r31 r36  
    11#!/usr/bin/env python 
    2 # -*- coding: ascii -*- 
     2# -*- coding: utf-8 -*- 
     3# $Id$ 
    34 
    45from distutils.core import setup, Extension 
    56setup(name="migemo", 
    6       version="0.2", 
     7      version="0.3", 
    78      description="C/Migemo wrapper for Python", 
    89      author="Atzm WATANABE", 
Note: See TracChangeset for help on using the changeset viewer.