diff options
| author | Werner Koch <[email protected]> | 2016-08-22 14:32:14 +0000 | 
|---|---|---|
| committer | Werner Koch <[email protected]> | 2016-08-22 14:32:14 +0000 | 
| commit | c9e7dcb100d807583d8e312da459561138231376 (patch) | |
| tree | e5a7990466da62838988f2961d943614c83ef53a | |
| parent | core: New commands --lang and --have-lang for gpgme-config (diff) | |
| download | gpgme-c9e7dcb100d807583d8e312da459561138231376.tar.gz gpgme-c9e7dcb100d807583d8e312da459561138231376.zip | |
core: Base gpgme_get_dirinfo(uiserver-socket) on the socket dir.
* src/dirinfo.c (dirname_len): New.
(parse_output): Change computation of UISRV_SOCKET.
Signed-off-by: Werner Koch <[email protected]>
| -rw-r--r-- | src/dirinfo.c | 33 | 
1 files changed, 23 insertions, 10 deletions
| diff --git a/src/dirinfo.c b/src/dirinfo.c index 8824c9a4..226f93ca 100644 --- a/src/dirinfo.c +++ b/src/dirinfo.c @@ -70,6 +70,15 @@ _gpgme_dirinfo_disable_gpgconf (void)  } +/* Return the length of the directory part including the trailing + * slash of NAME.  */ +static size_t +dirname_len (const char *name) +{ +  return _gpgme_get_basename (name) - name; +} + +  /* Parse the output of "gpgconf --list-dirs".  This function expects     that DIRINFO_LOCK is held by the caller.  If COMPONENTS is set, the     output of --list-components is expected. */ @@ -77,6 +86,7 @@ static void  parse_output (char *line, int components)  {    char *value, *p; +  size_t n;    value = strchr (line, ':');    if (!value) @@ -110,22 +120,25 @@ parse_output (char *line, int components)    else      {        if (!strcmp (line, "homedir") && !dirinfo.homedir) +        dirinfo.homedir = strdup (value); +      else if (!strcmp (line, "agent-socket") && !dirinfo.agent_socket)          {            const char name[] = "S.uiserver"; +          char *buffer; -          dirinfo.homedir = strdup (value); -          if (dirinfo.homedir) +          dirinfo.agent_socket = strdup (value); +          if (dirinfo.agent_socket)              { -              dirinfo.uisrv_socket = malloc (strlen (dirinfo -                                                     .homedir) -                                             + 1 + strlen (name) + 1); -              if (dirinfo.uisrv_socket) -                strcpy (stpcpy (stpcpy (dirinfo.uisrv_socket, dirinfo.homedir), -                                DIRSEP_S), name); +              n = dirname_len (dirinfo.agent_socket); +              buffer = malloc (n + strlen (name) + 1); +              if (buffer) +                { +                  strncpy (buffer, dirinfo.agent_socket, n); +                  strcpy (buffer + n, name); +                  dirinfo.uisrv_socket = buffer; +                }              }          } -      else if (!strcmp (line, "agent-socket") && !dirinfo.agent_socket) -        dirinfo.agent_socket = strdup (value);      }  } | 
