rendered paste body// Prepare socket path for addr.sun_path[]
// Returns the path length minus the terminating '\0'
static int _rpc_socket_path(char **pathp, const char *ident)
{
if (pathp == NULL)
return 0;
char *path;
int n, len;
#if USE_ANONYMOUS_SOCKETS
n = 0;
#else
// XXX don't use TMPDIR because the length of the resulting path
// could exceed the size of sun_path[] (typically 108 bytes on Linux)
char *tmpdir = "/tmp";
n = strlen(tmpdir);
#endif
len = strlen(ident);
if ((path = (char *)malloc(n + 1 + len + 1)) == NULL)
return 0;
#if USE_ANONYMOUS_SOCKETS
path[0] = 0;
strcpy(&path[1], ident);
n = 1 + len;
#else
n = sprintf(path, "%s/", tmpdir);
for (int i = 0; i < len; i++) {
char ch = ident[i];
if (ch == '/')
ch = '_';
path[n++] = ch;
}
path[n] = '\0';
#endif
if (*pathp)
free(*pathp);
*pathp = path;
return n;
}