Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / libedataserver / e-uid.c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* e-uid.c - Unique ID generator.
3  *
4  * Copyright (C) 2002 Ximian, Inc.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of version 2 of the GNU Lesser General Public
8  * License as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  * Author: Dan Winship <danw@ximian.com>
21  */
22
23 #include "e-uid.h"
24
25 #include <glib.h>
26
27 #include <string.h>
28 #include <time.h>
29 #include <unistd.h>
30
31 /**
32  * e_uid_new:
33  * 
34  * Generate a new unique string for use e.g. in account lists.
35  * 
36  * Return value: The newly generated UID.  The caller should free the string
37  * when it's done with it.
38  **/
39 char *
40 e_uid_new (void)
41 {
42         static int serial;
43         static char *hostname;
44
45         if (!hostname) {
46                 hostname = (char *) g_get_host_name ();
47         }
48
49         return g_strdup_printf ("%lu.%lu.%d@%s",
50                                 (unsigned long) time (NULL),
51                                 (unsigned long) getpid (),
52                                 serial++,
53                                 hostname);
54 }