Changeset 5715


Ignore:
Timestamp:
Apr 28, 2008, 6:09:17 PM (14 years ago)
Author:
charles
Message:

don't use strlcat.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r5694 r5715  
    3535AC_HEADER_STDC
    3636AC_HEADER_TIME
    37 AC_CHECK_FUNCS([lrintf strlcpy strlcat daemon dirname basename])
     37AC_CHECK_FUNCS([lrintf strlcpy daemon dirname basename])
    3838AC_CHECK_SIZEOF([void*])
    3939AC_PROG_INSTALL
  • trunk/daemon/misc.c

    r5646 r5715  
    4040#include "misc.h"
    4141
    42 static void pushdir ( char *, const char *, size_t );
    43 
    4442static char gl_myname[256];
    4543
     
    6462
    6563void
    66 pushdir( char * path, const char * file, size_t size )
    67 {
    68     size_t off;
    69 
    70     off = strlen( path );
    71     if( 0 < off && off + 1 < size && '/' != path[off-1] )
    72     {
    73         path[off]   = '/';
    74         path[off+1] = '\0';
    75     }
    76     strlcat( path, file, size );
    77 }
    78 
    79 void
    8064confpath( char               * buf,
    8165          size_t               len,
     
    8468          enum confpathtype    type )
    8569{
    86     strlcpy( buf, configDir, len );
    87 
    8870    switch( type )
    8971    {
    9072        case CONF_PATH_TYPE_DAEMON:
    91             pushdir( buf, "daemon", len );
     73            tr_buildPath( buf, len, configDir, "daemon", file, NULL );
    9274            break;
    9375        case CONF_PATH_TYPE_GTK:
    94             pushdir( buf, "gtk", len );
     76            tr_buildPath( buf, len, configDir, "gtk", file, NULL );
    9577            break;
    9678        case CONF_PATH_TYPE_OSX:
     79            tr_buildPath( buf, len, configDir, file, NULL );
    9780            break;
    9881        default:
    9982            assert( 0 );
    10083            break;
    101     }
    102 
    103     if( NULL != file )
    104     {
    105         pushdir( buf, file, len );
    10684    }
    10785}
     
    11088absolutify( char * buf, size_t len, const char * path )
    11189{
    112     size_t off;
    113 
    114     if( '/' == path[0] )
    115     {
     90    if( *path == '/' )
    11691        strlcpy( buf, path, len );
    117         return;
     92    else {
     93        char cwd[MAX_PATH_LENGTH];
     94        getcwd( cwd, sizeof( cwd ) );
     95        tr_buildPath( buf, len, cwd, path, NULL );
    11896    }
    119 
    120     getcwd( buf, len );
    121     off = strlen( buf );
    122     if( 0 < off && len > off + 1 && '/' != buf[off] )
    123     {
    124         buf[off] = '/';
    125         off++;
    126         buf[off] = '\0';
    127     }
    128     strlcat( buf, path, len );
    12997}
    13098
  • trunk/daemon/torrents.c

    r5646 r5715  
    113113
    114114    confpath( gl_state, sizeof gl_state, configdir, CONF_FILE_STATE, 0 );
    115     strlcpy( gl_newstate, gl_state, sizeof gl_state );
    116     strlcat( gl_newstate, ".new", sizeof gl_state );
     115    snprintf( gl_newstate, sizeof( gl_newstate ), "%s.new", gl_state );
    117116    absolutify( gl_dir, sizeof gl_dir, "." );
    118117
  • trunk/libtransmission/trcompat.h

    r4404 r5715  
    3232#endif
    3333
    34 #ifndef HAVE_STRLCAT
    35 size_t strlcat(char *dst, const char *src, size_t siz);
    36 #endif
    37 
    3834#endif /* TRCOMPAT_H */
  • trunk/libtransmission/utils.c

    r5701 r5715  
    911911#endif /* HAVE_STRLCPY */
    912912
    913 
    914 #ifndef HAVE_STRLCAT
    915 
    916 /*
    917  * Appends src to string dst of size siz (unlike strncat, siz is the
    918  * full size of dst, not space left).  At most siz-1 characters
    919  * will be copied.  Always NUL terminates (unless siz <= strlen(dst)).
    920  * Returns strlen(src) + MIN(siz, strlen(initial dst)).
    921  * If retval >= siz, truncation occurred.
    922  */
    923 size_t
    924 strlcat(char *dst, const char *src, size_t siz)
    925 {
    926         char *d = dst;
    927         const char *s = src;
    928         size_t n = siz;
    929         size_t dlen;
    930 
    931         /* Find the end of dst and adjust bytes left but don't go past end */
    932         while (n-- != 0 && *d != '\0')
    933                 d++;
    934         dlen = d - dst;
    935         n = siz - dlen;
    936 
    937         if (n == 0)
    938                 return(dlen + strlen(s));
    939         while (*s != '\0') {
    940                 if (n != 1) {
    941                         *d++ = *s;
    942                         n--;
    943                 }
    944                 s++;
    945         }
    946         *d = '\0';
    947 
    948         return(dlen + (s - src));       /* count does not include NUL */
    949 }
    950 
    951 #endif /* HAVE_STRLCAT */
    952 
    953913/***
    954914****
  • trunk/macosx/IPCController.m

    r5580 r5715  
    3434#include "ipcparse.h"
    3535#include "transmission.h"
     36#include "utils.h"
    3637
    3738#import "IPCController.h"
     
    515516    bzero( sun, sizeof *sun );
    516517    sun->sun_family = AF_LOCAL;
    517     strlcpy( sun->sun_path, tr_getDefaultConfigDir(), sizeof sun->sun_path );
    518     strlcat( sun->sun_path, "/socket", sizeof sun->sun_path );
     518    tr_buildPath( sun->sun_path, sizeof( sun->sun_path ), tr_getDefaultConfigDir(), "socket", NULL );
    519519}
    520520
Note: See TracChangeset for help on using the changeset viewer.