File: e-uid.c

package info (click to toggle)
evolution-data-server 3.4.4-3%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 47,788 kB
  • sloc: ansic: 248,622; sh: 12,008; makefile: 2,874; xml: 428; perl: 204; python: 30
file content (52 lines) | stat: -rw-r--r-- 1,427 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-uid.c - Unique ID generator.
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * Author: Dan Winship <danw@ximian.com>
 */

#include "e-uid.h"

#include <string.h>
#include <time.h>
#include <unistd.h>

/**
 * e_uid_new:
 *
 * Generate a new unique string for use e.g. in account lists.
 *
 * Returns: The newly generated UID.  The caller should free the string
 * when it's done with it.
 **/
gchar *
e_uid_new (void)
{
	static gint serial;
	static gchar *hostname;

	if (!hostname) {
		hostname = (gchar *) g_get_host_name ();
	}

	return g_strdup_printf ("%lu.%lu.%d@%s",
				(gulong) time (NULL),
				(gulong) getpid (),
				serial++,
				hostname);
}