#endif
};
-static tr_bool
-str_has_suffix( const char *str, const char *suffix )
-{
- const size_t str_len = strlen( str );
- const size_t suffix_len = strlen( suffix );
-
- if( str_len < suffix_len )
- return FALSE;
-
- return !strncasecmp( str + str_len - suffix_len, suffix, suffix_len );
-}
-
/***
**** INOTIFY IMPLEMENTATION
***/
{
const char * name = d->d_name;
- if( !name || *name=='.' ) /* skip dotfiles */
- continue;
- if( !str_has_suffix( name, ".torrent" ) ) /* skip non-torrents */
+ if( !tr_str_has_suffix( name, ".torrent" ) ) /* skip non-torrents */
continue;
tr_inf( "Found new .torrent file \"%s\" in watchdir \"%s\"", name, w->dir );
while (i < len) {
struct inotify_event * event = (struct inotify_event *) &buf[i];
const char * name = event->name;
- if( str_has_suffix( name, ".torrent" ) )
+ if( tr_str_has_suffix( name, ".torrent" ) )
{
tr_inf( "Found new .torrent file \"%s\" in watchdir \"%s\"", name, w->dir );
w->callback( w->session, w->dir, name );
struct dirent * dirp;
while( ( dirp = readdir( dirh ) ) )
{
- if( strcmp( dirp->d_name,
- "." ) && strcmp( dirp->d_name, ".." ) )
+ const char * name = dirp->d_name;
+ if( name && strcmp( name, "." ) && strcmp( name, ".." ) )
{
- char * o = tr_buildPath( oldDir, dirp->d_name, NULL );
- char * n = tr_buildPath( newDir, dirp->d_name, NULL );
+ char * o = tr_buildPath( oldDir, name, NULL );
+ char * n = tr_buildPath( newDir, name, NULL );
rename( o, n );
++count;
tr_free( n );
struct dirent *d;
for( d = readdir( odir ); d != NULL; d = readdir( odir ) )
{
- if( d->d_name && d->d_name[0] != '.' ) /* skip dotfiles, ., and ..
- */
+ if( tr_str_has_suffix( d->d_name, ".torrent" ) )
{
tr_torrent * tor;
char * path = tr_buildPath( dirname, d->d_name, NULL );
struct dirent *d;
while(( d = readdir( odir )))
{
- if( d->d_name && d->d_name[0] != '.' )
+ if( tr_str_has_suffix( d->d_name, ".torrent" ) )
{
tr_info inf;
char * path = tr_buildPath( dirname, d->d_name, NULL );
struct dirent *d;
tr_ptrArrayInsertSorted( folders, tr_strdup( buf ), vstrcmp );
for( d = readdir( odir ); d != NULL; d = readdir( odir ) )
- if( d->d_name && d->d_name[0] != '.' ) /* skip dotfiles */
+ if( d->d_name && strcmp( d->d_name, "." ) && strcmp( d->d_name, ".." ) )
walkLocalData( tor, root, buf, d->d_name, torrentFiles, folders, dirtyFolders );
closedir( odir );
}
return str;
}
+tr_bool
+tr_str_has_suffix( const char *str, const char *suffix )
+{
+ size_t str_len;
+ size_t suffix_len;
+
+ if( !str )
+ return FALSE;
+ if( !suffix )
+ return TRUE;
+
+ str_len = strlen( str );
+ suffix_len = strlen( suffix );
+ if( str_len < suffix_len )
+ return FALSE;
+
+ return !strncasecmp( str + str_len - suffix_len, suffix, suffix_len );
+}
+
/****
*****
****/
@return the stripped string */
char* tr_strstrip( char * str );
+/** @brief Returns true if the string ends with the specified case-insensitive suffix */
+tr_bool tr_str_has_suffix( const char *str, const char *suffix );
+
+
/** @brief Portability wrapper for memmem() that uses the system implementation if available */
const char* tr_memmem( const char * haystack, size_t haystack_len,
const char * needle, size_t needle_len );