2

I'm completely stumped. I have this little thing to ease the mounting of MTP units under linux, but for some reason I can't get libnotify to show my icon when using variables. If I hardcode the complete path, it works fine, but when using variables as getcwd and getenv, it won't show.

Here is a piece of the code:

char cwd[1024];
char *slash = "/";  
{
NotifyNotification *mount;
notify_init ("Galaxy Nexus mounter");
    if (getcwd(cwd, sizeof(cwd)) != NULL)
    {
        mount = notify_notification_new ("Samsung Galaxy Nexus", "Mounted at ~/Nexus", ("%s%sandroid_on.png", cwd, slash));
        fprintf(stdout, "Icon used %s%sandroid_on.png\n", cwd, slash);
        system("jmtpfs ~/Nexus");
        notify_notification_set_timeout (mount, 2000);
        notify_notification_show (mount, NULL);
    }
    }

What am I doing wrong?

Nelson
  • 49,283
  • 8
  • 68
  • 81
tristan202
  • 1,081
  • 3
  • 19
  • 28

2 Answers2

1
("%s%sandroid_on.png", cwd, slash)

Are you aware that this expresion in C is equivalent to?

(slash)

The comma operator has no other effect!

You may want to do something like:

char png[1100];
sprintf(png, "%s%sandroid_on.png", cwd, slash);
mount = notify_notification_new ("Samsung Galaxy Nexus", "Mounted at ~/Nexus", png);

Or simpler, particularly if you know you won't overflow the char array:

strcat(cwd, slash);
strcat(cwd, "android_on.png");
mount = notify_notification_new ("Samsung Galaxy Nexus", "Mounted at ~/Nexus", cwd);
rodrigo
  • 94,151
  • 12
  • 143
  • 190
1

This doesn't look right:

mount = notify_notification_new ("Samsung Galaxy Nexus", "Mounted at ~/Nexus", ("%s%sandroid_on.png", cwd, slash));

Is the third parameter supposed to be a string? If so, you need to build it separately with snprintf:

char path[1000];
snprintf (path, sizeof(path), "%s%sandroid_on.png", cwd, slash);
mount = notify_notification_new ("Samsung Galaxy Nexus", "Mounted at ~/Nexus", path);
fprintf(stdout, "Icon used %s\n", path);
craig65535
  • 3,439
  • 1
  • 23
  • 49
  • At first I though the notify_notification_new call was python not C as ("%s%sandroid_on.png" % cwd, slash) would work find if it was python :) – Neil Wightman Mar 23 '13 at 09:26