timezone stuff
authorC-o-r-E <can.of.tuna@gmail.com>
Sat, 28 Jul 2012 02:58:56 +0000 (22:58 -0400)
committerC-o-r-E <can.of.tuna@gmail.com>
Sat, 28 Jul 2012 02:58:56 +0000 (22:58 -0400)
libfreerdp-locale/timezone.c

index 3870117..69272b1 100644 (file)
@@ -1518,16 +1518,47 @@ char* freerdp_get_unix_timezone_identifier()
                        tzid[length - 1] = '\0';
 
                fclose(fp) ;
-       }
 
-       if(tzid == NULL)
-       {
-               printf("Unable to detect time zone\n");
+               printf("/etc/timezone -> tzid = [%s]\n", tzid);
+               return tzid;
        }
-       else
+
+       /* On linux distros such as Redhat or Archlinux, a symlink at /etc/localtime
+       * will point to /usr/share/zoneinfo/region/place where region/place could be
+       * America/Montreal for example.
+       */
+
+       char buf[1024];
+       char tz[256];
+       ssize_t len;
+       
+
+       if ((len = readlink("/etc/localtime", buf, sizeof(buf)-1)) != -1)
+           buf[len] = '\0';
+
+       printf("%d localtime = [%s]\n", len, buf);
+
+       //find the position of the 2nd to last "/"
+       int num = 0;
+       int pos = len;
+       while(num < 2)
        {
-               printf("/etc/timezone -> tzid = [%s]\n", tzid);
+               if(pos == 0)
+                       break;
+
+               pos -= 1;
+
+               if(buf[pos] == '/')
+                       num++;
        }
+
+       printf("looks like we want to cut at position %d\n", pos);
+
+       strncpy(tz, buf+pos+1, len - pos);
+
+       printf("timezone: [%s]\n", tz); 
+
+       printf("Unable to detect time zone\n");
        return tzid;
 }