1111#include <stdio.h>
1212#include <stdlib.h>
1313#include <string.h>
14+ #include <strings.h>
1415#include <unistd.h>
1516
1617#include "cx.h"
@@ -212,12 +213,8 @@ main(int argc, char **argv)
212213 return 0 ;
213214 }
214215
215- if (pflag ) {
216- if (fork ()) // Fork to avoid waiting
217- return 0 ;
218- else
219- return push_path (pushpath );
220- }
216+ if (pflag )
217+ return push_path (pushpath );
221218
222219 if (id == -1 ) {
223220 get_match (argv [argc - 1 ], match , sizeof (match ));
@@ -371,9 +368,6 @@ static int
371368push_path (char * path )
372369{
373370 sqlite3_stmt * stmt ;
374- unsigned i , j ;
375- char name [256 ];
376- memset (name , 0 , sizeof (name ));
377371
378372 if (access (path , X_OK ) != 0 )
379373 return 1 ;
@@ -385,16 +379,9 @@ push_path(char *path)
385379 sqlite3_bind_int (stmt , 1 , id );
386380 } else {
387381 /* the entry doesn't exist, parse the name from the path and add to db */
388- j = 0 ;
389- for (i = 0 ; path [i ] != '\0' && j < sizeof (name ) - 1 ; i ++ ) {
390- if (path [i ] == '/' )
391- j = 0 ;
392- else
393- name [j ++ ] = path [i ];
394- }
395- name [j ] = '\0' ;
382+ char * name = rindex (path , '/' ) + 1 ;
396383
397- /* now that we've got the name, insert the new entry to sqlite */
384+ /* insert the new entry to sqlite */
398385 stmt = cdbq [DB_INSERT ];
399386 sqlite3_bind_text (stmt , 1 , path , strlen (path ), SQLITE_STATIC );
400387 sqlite3_bind_text (stmt , 2 , name , strlen (name ), SQLITE_STATIC );
0 commit comments