~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to file.c

  • Committer: Package Import Robot
  • Author(s): Antonio Terceiro, Lucas Nussbaum, Daigo Moriwaki, James Healy, Antonio Terceiro
  • Date: 2012-06-02 07:42:28 UTC
  • mfrom: (21.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20120602074228-09t2jgg1ozrsnnfo
Tags: 1.9.3.194-1
[ Lucas Nussbaum ]
* Add hurd-path-max.diff. Fixes FTBFS on Hurd. (Closes: #648055)

[ Daigo Moriwaki ]
* Removed debian/patches/debian/patches/sparc-continuations.diff,
  which the upstream has applied.
* debian/rules:
  - Bumped up tcltk_ver to 8.5.
  - Used chrpath for tcltklib.so to fix a lintian error,
    binary-or-shlib-defines-rpath.
* debian/control:
  - Suggests ruby-switch. (Closes: #654312)
  - Build-Depends: chrpath.
* debian/libruby1.9.1.symbols: Added a new symbol for
  rb_str_modify_expand@Base.
* debian/run-test-suites.bash:
  - Corrected options for test-all.
  - Enabled timeout to allow hang tests to be aborted.

[ James Healy ]
* New upstream release: 1.9.3p194 (Closes: #669582)
  + This release includes a fix for CVE-2011-0188 (Closes: #628451)
  + This release also does not segfault when running the test suite under
    amd64 (Closes: #674347)
* Enable hardened build flags (Closes: #667964)
* debian/control:
  - depend on specific version on coreutils
  - update policy version (no changes)

[ Antonio Terceiro ]
* debian/ruby1.9.1.postinst:
  + bump alternatives priority for `ruby` to 51 so that Ruby 1.9 has a
    higher priority than Ruby 1.8 (50).
  + bump alternatives priority for `gem` to 181 so that the Rubygems
    provided by Ruby 1.9 has priority over the one provided by the rubygems
    package.
* debian/control: added myself to Uploaders:
* debian/libruby1.9.1.symbols: update with new symbols added in 1.9.3p194
  upstream release.
* debian/manpages/*: fix references to command names with s/1.9/1.9.1/
* debian/rules: skip running DRB tests, since they seem to make the build
  hang. This should close #647296, but let's way and see. Also, with this do
  not need to timeout the test suite anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
  file.c -
4
4
 
5
 
  $Author: akr $
 
5
  $Author: naruse $
6
6
  created at: Mon Nov 15 12:24:34 JST 1993
7
7
 
8
8
  Copyright (C) 1993-2007 Yukihiro Matsumoto
94
94
#define STAT(p, s)      stat((p), (s))
95
95
#endif
96
96
 
 
97
#define rb_sys_fail_path(path) rb_sys_fail_str(path)
 
98
 
97
99
#if defined(__BEOS__) || defined(__HAIKU__) /* should not change ID if -1 */
98
100
static int
99
101
be_chown(const char *path, uid_t owner, gid_t group)
207
209
}
208
210
 
209
211
static long
210
 
apply2files(void (*func)(const char *, void *), VALUE vargs, void *arg)
 
212
apply2files(void (*func)(const char *, VALUE, void *), VALUE vargs, void *arg)
211
213
{
212
214
    long i;
213
215
    volatile VALUE path;
214
216
 
215
217
    rb_secure(4);
216
218
    for (i=0; i<RARRAY_LEN(vargs); i++) {
 
219
        const char *s;
217
220
        path = rb_get_path(RARRAY_PTR(vargs)[i]);
218
221
        path = rb_str_encode_ospath(path);
219
 
        (*func)(StringValueCStr(path), arg);
 
222
        s = RSTRING_PTR(path);
 
223
        (*func)(s, path, arg);
220
224
    }
221
225
 
222
226
    return RARRAY_LEN(vargs);
877
881
    rb_secure(4);
878
882
    FilePathValue(fname);
879
883
    if (rb_stat(fname, &st) < 0) {
880
 
        rb_sys_fail(RSTRING_PTR(fname));
 
884
        rb_sys_fail_path(fname);
881
885
    }
882
886
    return stat_new(&st);
883
887
}
903
907
    rb_io_t *fptr;
904
908
    struct stat st;
905
909
 
906
 
#define rb_sys_fail_path(path) rb_sys_fail(NIL_P(path) ? 0 : RSTRING_PTR(path))
907
910
    GetOpenFile(obj, fptr);
908
911
    if (fstat(fptr->fd, &st) == -1) {
909
912
        rb_sys_fail_path(fptr->pathv);
935
938
    FilePathValue(fname);
936
939
    fname = rb_str_encode_ospath(fname);
937
940
    if (lstat(StringValueCStr(fname), &st) == -1) {
938
 
        rb_sys_fail(RSTRING_PTR(fname));
 
941
        rb_sys_fail_path(fname);
939
942
    }
940
943
    return stat_new(&st);
941
944
#else
1704
1707
 
1705
1708
    if (rb_stat(fname, &st) < 0) {
1706
1709
        FilePathValue(fname);
1707
 
        rb_sys_fail(RSTRING_PTR(fname));
 
1710
        rb_sys_fail_path(fname);
1708
1711
    }
1709
1712
    return OFFT2NUM(st.st_size);
1710
1713
}
1774
1777
    FilePathValue(fname);
1775
1778
    fname = rb_str_encode_ospath(fname);
1776
1779
    if (lstat(StringValueCStr(fname), &st) == -1) {
1777
 
        rb_sys_fail(RSTRING_PTR(fname));
 
1780
        rb_sys_fail_path(fname);
1778
1781
    }
1779
1782
 
1780
1783
    return rb_file_ftype(&st);
1797
1800
 
1798
1801
    if (rb_stat(fname, &st) < 0) {
1799
1802
        FilePathValue(fname);
1800
 
        rb_sys_fail(RSTRING_PTR(fname));
 
1803
        rb_sys_fail_path(fname);
1801
1804
    }
1802
1805
    return stat_atime(&st);
1803
1806
}
1843
1846
 
1844
1847
    if (rb_stat(fname, &st) < 0) {
1845
1848
        FilePathValue(fname);
1846
 
        rb_sys_fail(RSTRING_PTR(fname));
 
1849
        rb_sys_fail_path(fname);
1847
1850
    }
1848
1851
    return stat_mtime(&st);
1849
1852
}
1892
1895
 
1893
1896
    if (rb_stat(fname, &st) < 0) {
1894
1897
        FilePathValue(fname);
1895
 
        rb_sys_fail(RSTRING_PTR(fname));
 
1898
        rb_sys_fail_path(fname);
1896
1899
    }
1897
1900
    return stat_ctime(&st);
1898
1901
}
1950
1953
}
1951
1954
 
1952
1955
static void
1953
 
chmod_internal(const char *path, void *mode)
 
1956
chmod_internal(const char *path, VALUE pathv, void *mode)
1954
1957
{
1955
1958
    if (chmod(path, *(int *)mode) < 0)
1956
 
        rb_sys_fail(path);
 
1959
        rb_sys_fail_path(pathv);
1957
1960
}
1958
1961
 
1959
1962
/*
2026
2029
 
2027
2030
#if defined(HAVE_LCHMOD)
2028
2031
static void
2029
 
lchmod_internal(const char *path, void *mode)
 
2032
lchmod_internal(const char *path, VALUE pathv, void *mode)
2030
2033
{
2031
2034
    if (lchmod(path, (int)(VALUE)mode) < 0)
2032
 
        rb_sys_fail(path);
 
2035
        rb_sys_fail_path(pathv);
2033
2036
}
2034
2037
 
2035
2038
/*
2066
2069
};
2067
2070
 
2068
2071
static void
2069
 
chown_internal(const char *path, void *arg)
 
2072
chown_internal(const char *path, VALUE pathv, void *arg)
2070
2073
{
2071
2074
    struct chown_args *args = arg;
2072
2075
    if (chown(path, args->owner, args->group) < 0)
2073
 
        rb_sys_fail(path);
 
2076
        rb_sys_fail_path(pathv);
2074
2077
}
2075
2078
 
2076
2079
/*
2157
2160
 
2158
2161
#if defined(HAVE_LCHOWN)
2159
2162
static void
2160
 
lchown_internal(const char *path, void *arg)
 
2163
lchown_internal(const char *path, VALUE pathv, void *arg)
2161
2164
{
2162
2165
    struct chown_args *args = arg;
2163
2166
    if (lchown(path, args->owner, args->group) < 0)
2164
 
        rb_sys_fail(path);
 
2167
        rb_sys_fail_path(pathv);
2165
2168
}
2166
2169
 
2167
2170
/*
2210
2213
};
2211
2214
 
2212
2215
#if defined DOSISH || defined __CYGWIN__
2213
 
NORETURN(static void utime_failed(const char *, const struct timespec *, VALUE, VALUE));
 
2216
NORETURN(static void utime_failed(VALUE, const struct timespec *, VALUE, VALUE));
2214
2217
 
2215
2218
static void
2216
 
utime_failed(const char *path, const struct timespec *tsp, VALUE atime, VALUE mtime)
 
2219
utime_failed(VALUE path, const struct timespec *tsp, VALUE atime, VALUE mtime)
2217
2220
{
2218
2221
    if (tsp && errno == EINVAL) {
2219
2222
        VALUE e[2], a = Qnil, m = Qnil;
2234
2237
        if (!NIL_P(e[0])) {
2235
2238
            if (path) {
2236
2239
                if (!d) e[0] = rb_str_dup(e[0]);
2237
 
                rb_str_cat2(rb_str_cat2(e[0], " for "), path);
 
2240
                rb_str_append(rb_str_cat2(e[0], " for "), path);
2238
2241
            }
2239
2242
            e[1] = INT2FIX(EINVAL);
2240
2243
            rb_exc_raise(rb_class_new_instance(2, e, rb_eSystemCallError));
2241
2244
        }
2242
2245
        errno = EINVAL;
2243
2246
    }
2244
 
    rb_sys_fail(path);
 
2247
    rb_sys_fail_path(path);
2245
2248
}
2246
2249
#else
2247
 
#define utime_failed(path, tsp, atime, mtime) rb_sys_fail(path)
 
2250
#define utime_failed(path, tsp, atime, mtime) rb_sys_fail_path(path)
2248
2251
#endif
2249
2252
 
2250
2253
#if defined(HAVE_UTIMES)
2251
2254
 
2252
2255
static void
2253
 
utime_internal(const char *path, void *arg)
 
2256
utime_internal(const char *path, VALUE pathv, void *arg)
2254
2257
{
2255
2258
    struct utime_args *v = arg;
2256
2259
    const struct timespec *tsp = v->tsp;
2265
2268
                try_utimensat = 0;
2266
2269
                goto no_utimensat;
2267
2270
            }
2268
 
            utime_failed(path, tsp, v->atime, v->mtime);
 
2271
            utime_failed(pathv, tsp, v->atime, v->mtime);
2269
2272
        }
2270
2273
        return;
2271
2274
    }
2280
2283
        tvp = tvbuf;
2281
2284
    }
2282
2285
    if (utimes(path, tvp) < 0)
2283
 
        utime_failed(path, tsp, v->atime, v->mtime);
 
2286
        utime_failed(pathv, tsp, v->atime, v->mtime);
2284
2287
}
2285
2288
 
2286
2289
#else
2293
2296
#endif
2294
2297
 
2295
2298
static void
2296
 
utime_internal(const char *path, void *arg)
 
2299
utime_internal(const char *path, VALUE pathv, void *arg)
2297
2300
{
2298
2301
    struct utime_args *v = arg;
2299
2302
    const struct timespec *tsp = v->tsp;
2304
2307
        utp = &utbuf;
2305
2308
    }
2306
2309
    if (utime(path, utp) < 0)
2307
 
        utime_failed(path, tsp, v->atime, v->mtime);
 
2310
        utime_failed(pathv, tsp, v->atime, v->mtime);
2308
2311
}
2309
2312
 
2310
2313
#endif
2344
2347
static void
2345
2348
sys_fail2(VALUE s1, VALUE s2)
2346
2349
{
2347
 
    char *buf;
 
2350
    VALUE str;
2348
2351
#ifdef MAX_PATH
2349
2352
    const int max_pathlen = MAX_PATH;
2350
2353
#else
2351
2354
    const int max_pathlen = MAXPATHLEN;
2352
2355
#endif
2353
 
    const char *e1, *e2;
2354
 
    int len = 5;
2355
 
    long l1 = RSTRING_LEN(s1), l2 = RSTRING_LEN(s2);
2356
2356
 
2357
 
    e1 = e2 = "";
2358
 
    if (l1 > max_pathlen) {
2359
 
        l1 = max_pathlen - 3;
2360
 
        e1 = "...";
2361
 
        len += 3;
2362
 
    }
2363
 
    if (l2 > max_pathlen) {
2364
 
        l2 = max_pathlen - 3;
2365
 
        e2 = "...";
2366
 
        len += 3;
2367
 
    }
2368
 
    len += (int)l1 + (int)l2;
2369
 
    buf = ALLOCA_N(char, len);
2370
 
    snprintf(buf, len, "(%.*s%s, %.*s%s)",
2371
 
             (int)l1, RSTRING_PTR(s1), e1,
2372
 
             (int)l2, RSTRING_PTR(s2), e2);
2373
 
    rb_sys_fail(buf);
 
2357
    str = rb_str_new_cstr("(");
 
2358
    rb_str_append(str, rb_str_ellipsize(s1, max_pathlen));
 
2359
    rb_str_cat2(str, ", ");
 
2360
    rb_str_append(str, rb_str_ellipsize(s2, max_pathlen));
 
2361
    rb_str_cat2(str, ")");
 
2362
    rb_sys_fail_path(str);
2374
2363
}
2375
2364
 
2376
2365
#ifdef HAVE_LINK
2481
2470
#endif
2482
2471
 
2483
2472
static void
2484
 
unlink_internal(const char *path, void *arg)
 
2473
unlink_internal(const char *path, VALUE pathv, void *arg)
2485
2474
{
2486
2475
    if (unlink(path) < 0)
2487
 
        rb_sys_fail(path);
 
2476
        rb_sys_fail_path(pathv);
2488
2477
}
2489
2478
 
2490
2479
/*
3176
3165
    if (tainted) OBJ_TAINT(result);
3177
3166
    rb_str_set_len(result, p - buf);
3178
3167
    rb_enc_check(fname, result);
 
3168
    ENC_CODERANGE_CLEAR(result);
3179
3169
    return result;
3180
3170
}
3181
3171
 
3293
3283
            if (!NIL_P(checkval)) {
3294
3284
                if (checkval == ID2SYM(resolving)) {
3295
3285
                    errno = ELOOP;
3296
 
                    rb_sys_fail(RSTRING_PTR(testpath));
 
3286
                    rb_sys_fail_path(testpath);
3297
3287
                }
3298
3288
                else {
3299
3289
                    *resolvedp = rb_str_dup(checkval);
3307
3297
                if (ret == -1) {
3308
3298
                    if (errno == ENOENT) {
3309
3299
                        if (strict || !last || *unresolved_firstsep)
3310
 
                            rb_sys_fail(RSTRING_PTR(testpath));
 
3300
                            rb_sys_fail_path(testpath);
3311
3301
                        *resolvedp = testpath;
3312
3302
                        break;
3313
3303
                    }
3314
3304
                    else {
3315
 
                        rb_sys_fail(RSTRING_PTR(testpath));
 
3305
                        rb_sys_fail_path(testpath);
3316
3306
                    }
3317
3307
                }
3318
3308
#ifdef HAVE_READLINK
3847
3837
            FilePathStringValue(tmp);
3848
3838
        }
3849
3839
        name = StringValueCStr(result);
3850
 
        if (i > 0 && !NIL_P(sep)) {
 
3840
        if (i == 0) {
 
3841
            rb_enc_copy(result, tmp);
 
3842
        }
 
3843
        else if (!NIL_P(sep)) {
3851
3844
            tail = chompdirsep(name);
3852
3845
            if (RSTRING_PTR(tmp) && isdirsep(RSTRING_PTR(tmp)[0])) {
3853
3846
                rb_str_set_len(result, tail - name);
3906
3899
    path = rb_str_encode_ospath(path);
3907
3900
#ifdef HAVE_TRUNCATE
3908
3901
    if (truncate(StringValueCStr(path), pos) < 0)
3909
 
        rb_sys_fail(RSTRING_PTR(path));
 
3902
        rb_sys_fail_path(path);
3910
3903
#else /* defined(HAVE_CHSIZE) */
3911
3904
    {
3912
3905
        int tmpfd;
3913
3906
 
3914
3907
        if ((tmpfd = open(StringValueCStr(path), 0)) < 0) {
3915
 
            rb_sys_fail(RSTRING_PTR(path));
 
3908
            rb_sys_fail_path(path);
3916
3909
        }
3917
3910
        rb_update_max_fd(tmpfd);
3918
3911
        if (chsize(tmpfd, pos) < 0) {
3919
3912
            close(tmpfd);
3920
 
            rb_sys_fail(RSTRING_PTR(path));
 
3913
            rb_sys_fail_path(path);
3921
3914
        }
3922
3915
        close(tmpfd);
3923
3916
    }
4256
4249
        CHECK(1);
4257
4250
        if (rb_stat(fname, &st) == -1) {
4258
4251
            FilePathValue(fname);
4259
 
            rb_sys_fail(RSTRING_PTR(fname));
 
4252
            rb_sys_fail_path(fname);
4260
4253
        }
4261
4254
 
4262
4255
        switch (cmd) {
4345
4338
    FilePathValue(fname);
4346
4339
    fname = rb_str_encode_ospath(fname);
4347
4340
    if (STAT(StringValueCStr(fname), &st) == -1) {
4348
 
        rb_sys_fail(RSTRING_PTR(fname));
 
4341
        rb_sys_fail_path(fname);
4349
4342
    }
4350
4343
    if (DATA_PTR(obj)) {
4351
4344
        xfree(DATA_PTR(obj));