~ubuntu-branches/ubuntu/maverick/vice/maverick

« back to all changes in this revision

Viewing changes to src/util.c

  • Committer: Bazaar Package Importer
  • Author(s): Zed Pobre
  • Date: 2005-02-01 11:30:26 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050201113026-3eyakzsmmheclvjg
Tags: 1.16-1
* New upstream version
* Fixes crash on 64-bit architectures (closes: #287640)
* x128 working again (closes: #286767)
* Works fine with /dev/dsp in use (not in the main changelog, but tested
  on my local machine as working).  Presumably, this also takes care of
  the issue with dsp being held.  I'm not sure if this is because I'm
  testing it on a 2.6 kernel now -- if you are still having problems
  with /dev/dsp, please reopen the bugs. (closes: #152952, #207942)
* Don't kill Makefile.in on clean

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
 
65
65
    newp = (char *)lib_malloc(tot_len + 1);
66
66
 
67
 
    memcpy(newp, s, arg_len[0]);
 
67
    if (arg_len[0] > 0)
 
68
        memcpy(newp, s, arg_len[0]);
68
69
    ptr = newp + arg_len[0];
69
70
 
70
71
    va_start(ap, s);
79
80
    return newp;
80
81
}
81
82
 
 
83
/* Add a line to a string.  */
 
84
void util_addline(char **list, const char *line)
 
85
{
 
86
    char *tmp;
 
87
 
 
88
    tmp = util_concat(*list, line, NULL);
 
89
    lib_free(*list);
 
90
    *list = tmp;
 
91
}
 
92
 
 
93
/* Add a line to a string and free the line.  */
 
94
void util_addline_free(char **list, char *line)
 
95
{
 
96
    util_addline(list, line);
 
97
    lib_free(line);
 
98
}
 
99
 
82
100
/* Add the first `src_size' bytes of `src' to the end of `buf', which is a
83
101
   malloc'ed block of `max_buf_size' bytes of which only the first `buf_size'
84
102
   ones are used.  If the `buf' is not large enough, realloc it.  Return a
312
330
        if (i + length > size)
313
331
            break;
314
332
        r = fread((void *)&(dest[i]), length, 1, fd);
 
333
//log_debug("READ %i bytes to offset %i result %i.",length,i,r);
315
334
        if (r < 1)
316
335
            break;
317
336
    }
360
379
    size_t len;
361
380
 
362
381
    r = fgets(buf, bufsize, f);
 
382
 
363
383
    if (r == NULL)
364
384
        return -1;
365
385
 
371
391
        /* Remove trailing newline characters.  */
372
392
        /* Remove both 0x0a and 0x0d characters, this solution makes it */
373
393
        /* work on all target platforms: Unixes, Win32, DOS, and even for MAC */
374
 
        while ((len > 0) && ((*(buf+len-1)==0x0d) || (*(buf+len-1)==0x0a)))
 
394
        while ((len > 0) && ((*(buf + len - 1) == 0x0d)
 
395
            || (*(buf + len - 1) == 0x0a)))
375
396
            len--;
376
397
 
377
398
        /* Remove useless spaces.  */
527
548
 
528
549
/* ------------------------------------------------------------------------- */
529
550
 
530
 
/* This code is grabbed from GNU make.  It returns the maximum path length by
531
 
   using `pathconf'.  */
532
 
#ifdef NEED_GET_PATH_MAX
533
 
unsigned int get_path_max(void)
534
 
{
535
 
    static unsigned int value;
536
 
 
537
 
    if (value == 0) {
538
 
        long int x = pathconf("/", _PC_PATH_MAX);
539
 
 
540
 
        if (x > 0)
541
 
            value = x;
542
 
        else
543
 
            return MAXPATHLEN;
544
 
    }
545
 
 
546
 
    return value;
547
 
}
548
 
#endif
549
 
 
550
551
/* The following are replacements for libc functions that could be missing.  */
551
552
 
552
553
#if !defined HAVE_MEMMOVE
694
695
    return ext_filename;
695
696
}
696
697
 
 
698
char *util_get_extension(char *filename)
 
699
{
 
700
    char *s;
 
701
 
 
702
    if (filename == NULL)
 
703
        return NULL;
 
704
 
 
705
    s = strrchr(filename, FSDEV_EXT_SEP_CHR);
 
706
    if (s)
 
707
        return s + 1;
 
708
    else
 
709
        return NULL;
 
710
}
 
711