comparison gtk3/dw.c @ 1506:308bfa8426db

Rewrite application directory detection code for GTK... So it properly handles when the application is started with no path.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 26 Dec 2011 23:53:07 +0000
parents fcdd9e3c735a
children 218c85939040
comparison
equal deleted inserted replaced
1505:fcdd9e3c735a 1506:308bfa8426db
1798 /* Setup the private data directory */ 1798 /* Setup the private data directory */
1799 if(argc && argv && *argc > 0 && (*argv)[0]) 1799 if(argc && argv && *argc > 0 && (*argv)[0])
1800 { 1800 {
1801 char *pathcopy = strdup((*argv)[0]); 1801 char *pathcopy = strdup((*argv)[0]);
1802 char *pos = strrchr(pathcopy, '/'); 1802 char *pos = strrchr(pathcopy, '/');
1803 char *binname = pathcopy;
1803 1804
1805 /* If we have a / then...
1806 * the binary name should be at the end.
1807 */
1804 if(pos) 1808 if(pos)
1805 { 1809 {
1806 char *binname = pos + 1; 1810 binname = pos + 1;
1811 *pos = 0;
1812 }
1813
1814 if(*binname)
1815 {
1816 char *binpos = strstr(pathcopy, "/bin");
1807 1817
1808 *pos = 0; 1818 if(binpos)
1809 if(*binname) 1819 strncpy(_dw_share_path, pathcopy, (size_t)(binpos - pathcopy));
1810 { 1820 else
1811 char *binpos = strstr(pathcopy, "/bin"); 1821 strcpy(_dw_share_path, "/usr/local");
1812 1822 strcat(_dw_share_path, "/share/");
1813 if(binpos) 1823 strcat(_dw_share_path, binname);
1814 strncpy(_dw_share_path, pathcopy, (size_t)(binpos - pathcopy));
1815 else
1816 strcpy(_dw_share_path, "/usr/local");
1817 strcat(_dw_share_path, "/share/");
1818 strcat(_dw_share_path, binname);
1819 }
1820 } 1824 }
1821 if(pathcopy) 1825 if(pathcopy)
1822 free(pathcopy); 1826 free(pathcopy);
1823 } 1827 }
1824 /* If that failed... just get the current directory */ 1828 /* If that failed... just get the current directory */