/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* camel-uid-cache.c: UID caching code. */ /* * Authors: * Dan Winship * * Copyright 2000 Ximian, Inc. (www.ximian.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * 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 General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include "camel-uid-cache.h" struct _uid_state { int level; gboolean save; }; static void free_uid (gpointer key, gpointer value, gpointer data); static void maybe_write_uid (gpointer key, gpointer value, gpointer data); /** * camel_uid_cache_new: * @filename: path to load the cache from * * Creates a new UID cache, initialized from @filename. If @filename * doesn't already exist, the UID cache will be empty. Otherwise, if * it does exist but can't be read, the function will return %NULL. * * Return value: a new UID cache, or %NULL **/ CamelUIDCache * camel_uid_cache_new (const char *filename) { CamelUIDCache *cache; struct stat st; char *buf, **uids; int fd, i; fd = open (filename, O_RDWR | O_CREAT, 0700); if (fd == -1) return NULL; if (fstat (fd, &st) != 0) { close (fd); return NULL; } buf = g_malloc (st.st_size + 1); if (read (fd, buf, st.st_size) == -1) { close (fd); g_free (buf); return NULL; } buf[st.st_size] = '\0'; cache = g_new (CamelUIDCache, 1); cache->fd = fd; cache->level = 1; cache->uids = g_hash_table_new (g_str_hash, g_str_equal); uids = g_strsplit (buf, "\n", 0); g_free (buf); for (i = 0; uids[i]; i++) { struct _uid_state *state; state = g_new (struct _uid_state, 1); state->level = cache->level; state->save = TRUE; g_hash_table_insert (cache->uids, uids[i], state); } g_free (uids); return cache; } /** * camel_uid_cache_save: * @cache: a CamelUIDCache * * Attempts to save @cache back to disk. * * Return value: success or failure **/ gboolean camel_uid_cache_save (CamelUIDCache *cache) { if (lseek (cache->fd, 0, SEEK_SET) != 0) return FALSE; g_hash_table_foreach (cache->uids, maybe_write_uid, cache); return ftruncate (cache->fd, lseek (cache->fd, 0, SEEK_CUR)) == 0; } static void maybe_write_uid (gpointer key, gpointer value, gpointer data) { CamelUIDCache *cache = data; struct _uid_state *state = value; if (state && state->level == cache->level && state->save) { write (cache->fd, key, strlen (key)); write (cache->fd, "\n", 1); } } /** * camel_uid_cache_destroy: * @cache: a CamelUIDCache * * Destroys @cache and frees its data. **/ void camel_uid_cache_destroy (CamelUIDCache *cache) { g_hash_table_foreach (cache->uids, free_uid, NULL); g_hash_table_destroy (cache->uids); close (cache->fd); g_free (cache); } static void free_uid (gpointer key, gpointer value, gpointer data) { g_free (key); g_free (value); } /** * camel_uid_cache_get_new_uids: * @cache: a CamelUIDCache * @uids: an array of UIDs * * Returns an array of UIDs from @uids that are not in @cache, and * removes UIDs from @cache that aren't in @uids. * * Return value: an array of new UIDs, which must be freed with * camel_uid_cache_free_uids(). **/ GPtrArray * camel_uid_cache_get_new_uids (CamelUIDCache *cache, GPtrArray *uids) { GPtrArray *new_uids; gpointer old_uid; char *uid; int i; new_uids = g_ptr_array_new (); cache->level++; for (i = 0; i < uids->len; i++) { struct _uid_state *state; uid = uids->pdata[i]; if (g_hash_table_lookup_extended (cache->uids, uid, &old_uid, &state)) { g_hash_table_remove (cache->uids, uid); g_free (old_uid); } else { g_ptr_array_add (new_uids, g_strdup (uid)); state = g_new (struct _uid_state, 1); state->save = FALSE; } state->level = cache->level; g_hash_table_insert (cache->uids, g_strdup (uid), state); } return new_uids; } /** * camel_uid_cache_save_uid: * @cache: a CamelUIDCache * @uid: a uid to save * * Marks a uid for saving. **/ void camel_uid_cache_save_uid (CamelUIDCache *cache, const char *uid) { struct _uid_state *state; gpointer old_uid; g_return_if_fail (uid != NULL); if (g_hash_table_lookup_extended (cache->uids, uid, &old_uid, &state)) { state->save = TRUE; state->level = cache->level; } else { state = g_new (struct _uid_state, 1); state->save = TRUE; state->level = cache->level; g_hash_table_insert (cache->uids, g_strdup (uid), state); } } /** * camel_uid_cache_free_uids: * @uids: an array returned from camel_uid_cache_get_new_uids() * * Frees the array of UIDs. **/ void camel_uid_cache_free_uids (GPtrArray *uids) { int i; for (i = 0; i < uids->len; i++) g_free (uids->pdata[i]); g_ptr_array_free (uids, TRUE); } /npm_and_yarn/devel/electron6/files/ini-1.3.8&id=5c4e77c877814963a0bb37955d1522dadc7bd666'>refslogtreecommitdiffstats
Commit message (Expand)AuthorAgeFilesLines
* Autotools update. Read ports/UPDATING 20100915 for details.ade2010-09-161-2/+2
* Update to 11.0.1.jsa2010-08-133-4/+6
* Update to 12.6.9.jsa2010-08-132-4/+5
* - Mark BROKEN on 6.X: does not compilepav2010-07-241-0/+4
* - Unbreak with Xorg 1.7Xmiwi2010-07-103-24/+412
* Update from 0.1 to 0.2.osa2010-07-022-8/+7
* Mark ignore, useless without uep(4).osa2010-06-171-1/+8
* Add X.Org xf86-input-egalax driver, version 0.1.osa2010-06-025-0/+34
* Update to 1.2.1 in order to unbreak the build with X.org 7.5.marius2010-05-312-5/+4
* - Mark BROKEN on 6.X: does not compilepav2010-05-261-1/+7
* - Mark BROKEN on 6.X/amd64: does not compilepav2010-05-241-1/+7
* - Mark BROKEN: does not compilepav2010-05-243-0/+6
* - Mark BROKEN: does not compilepav2010-05-131-0/+2
* Pull in patch from git to fix BIOS read on 650 and 760rnoland2010-05-102-0/+12
* - Update to 2.1.17miwi2010-05-102-5/+5
* - Fix build on 6.Xmiwi2010-05-0734-33/+236
* - Fix build on 6.Xmiwi2010-05-0712-11/+84
* - Update to 12.6.7 (which also fix build on new xorg)miwi2010-05-062-5/+11
* Pull patches from git to fix build on newer Xorg.rnoland2010-05-042-1/+71
* Update to 1.4.1 (fix build with newer Xorg)rnoland2010-05-042-5/+4
* Pull patch from git to allow building with newer Xorg.rnoland2010-05-042-1/+76
* Add another patch to fix unresolved symbols.rnoland2010-05-042-1/+81
* - Update to Xorg 7.5miwi2010-05-01120-263/+1202
* - Add port for xf86-video-rdc, X.Org driver forstas2010-04-155-0/+36
* - Remove all broken Drivermiwi2010-03-271-9/+7
* x11-drivers/xf86-input-calcomp Unmaintained upstream. Notify x11 Maintainers...miwi2010-03-2749-403/+0
* Begin the process of deprecating sysutils/rc_subr bydougb2010-03-271-1/+1
* - Chase libpci shlib bumpfluffy2010-03-121-2/+2
* Chase xorg-server update and bump driver PORTREVISIONS.rnoland2010-02-0769-57/+69
* Limited Update to Mesa3D 7.6.1 and libdrm 2.4.17.nork2010-02-071-0/+4
* 2010-01-08 x11-toolkits/gtkada-gps: has been broken for 3 monthsmiwi2010-01-285-37/+0
* Fix the bsd.port.(pre|post).mk inclusion that was incorrectly removederwin2010-01-161-1/+3
* - USB module does not build on 8.x, turn it off by default in this case.pgollucci2010-01-151-7/+10
* Re-add accidentally removed line and fix PLISTgarga2009-12-221-0/+1
* Update to 0.2.904 to fix it on amd64garga2009-12-212-6/+4
* Revert to 1.1.2 for xorg big upgrade.nork2009-12-202-4/+4
* Update to 1.2.1.nork2009-12-202-4/+4
* This port has been broken for 3+ months, thuspav2009-12-081-0/+2
* Remove xf86-video-ati from CONFLICTS, and bump PORTREVISION.nork2009-12-051-2/+2
* Update to 1.3.0.nork2009-12-052-5/+5
* Go ahead and bump to 6.12.4.rnoland2009-12-024-10/+8
* Build for ia64 to satisfy the xorg-drivers dependencies.marcel2009-11-111-1/+1
* Update to 2009.11.01 based on 1.3.0.nork2009-11-013-19/+10
* - Switch SourceForge ports to the new File Release System: categories startin...amdmi32009-08-221-5/+4
* Update to 2009.08.08.nork2009-08-082-4/+4
* -Repocopy devel/libtool15 -> libtool22 and libltdl15 -> libltdl22.mezz2009-08-032-2/+2
* Update to newer snapshot.rnoland2009-08-024-12/+38
* Update to 2009.07.26.nork2009-07-262-4/+4
* Update to 2009.07.01.nork2009-07-012-4/+4
* Mark BROKEN: does not build.erwin2009-06-211-0/+2
* Remove x11-drivers/xf86-video-vga as it has been marked BROKEN for overerwin2009-06-145-35/+0
* Update o 2009.06.07.nork2009-06-072-5/+5
* Fix dependency on glproto to enable DRI.nork2009-06-051-2/+2
* Update to 2009.06.05.nork2009-06-042-4/+4
* Mark BROKEN on 8.x: does not build.erwin2009-05-291-0/+4
* Mark as not for sparc64 (does not install, and not called for bylinimon2009-05-291-0/+2
* Update to 1.1.2rnoland2009-05-292-4/+4
* Update to 1.1.1rnoland2009-05-222-5/+4
* - Update to 20090514.9656762 to reflect libdrm updatemiwi2009-05-162-9/+8
* . add glproto as a dependency, so packages are got compiled without DRI support;bsam2009-05-141-2/+2
* Update to 2.7.1rnoland2009-05-134-8/+8
* Update to 2009.05.09 based on 1.2.5.nork2009-05-094-11/+28
* Fix pkg-plist. It isn't obeying prefix for includes... This should bernoland2009-05-082-0/+2
* Update to 1.7.1rnoland2009-05-082-5/+4
* Update to 1.4.10rnoland2009-05-082-4/+4
* Update to 6.8.1rnoland2009-05-082-5/+4
* Update to 2.7.0rnoland2009-05-086-12/+10
* Update to 1.3.0rnoland2009-05-082-5/+4
* Update to 1.4.1rnoland2009-05-083-6/+4
* Update to 2.2.2rnoland2009-05-082-7/+4
* Chase xserver update with driver port bumps.rnoland2009-05-0863-38/+63
* Update to 1.1.0rnoland2009-04-264-5/+20
* Update to 1.2.5.20090412, which is same version of xf86-video-radeonhd 1.2.5.nork2009-04-123-29/+12
* Update the nouveau snapshot and remove BROKEN now that libdrm hasrnoland2009-04-112-10/+34
* - Fix build with xorg-server 1.6pav2009-04-102-1/+7
* Update to 1.2.5rnoland2009-04-102-5/+4
* Update to 6.12.2rnoland2009-04-084-10/+8
* Restore native PS/2 support.jkim2009-04-082-11/+18
* Update to 2.1.13rnoland2009-04-084-50/+4
* Chase the Xorg server update and bump ports that depend on it.rnoland2009-04-0447-14/+47
* Update Xorg server to 1.6.0rnoland2009-04-0435-46/+71
* Keep the code from turning off the FPU - cures excessive traps thatmarius2009-04-012-0/+27
* As xf86-video-intel is marked only for amd64 and i386 also onlymarius2009-04-011-1/+4
* Update to 6.12.1rnoland2009-03-194-8/+8
* - Mark BROKEN: does not compilepav2009-03-172-0/+4
* Update to 6.12.0rnoland2009-03-144-8/+8
* The nv driver was somewhat brain-damaged, it was detecting most allrnoland2009-03-023-1/+46
* Update to 2009.03.01 based 1.2.4.nork2009-03-012-8/+7
* nouveau is an X.Org Foundation and Freedesktop.org project which wasamdmi32009-02-215-0/+36
* Update to 6.11.0rnoland2009-02-194-8/+8
* - Replace open(2)/close(2) pairs with stat(2). Closing mouse device hasjkim2009-02-052-28/+62
* - Partially back out the previous attempt to fix PS/2 protocol support.jkim2009-02-032-19/+21
* Take a crack at resolving the mouse blocking issues.rnoland2009-01-292-5/+13
* - Update to 0.8.2-2pgollucci2009-01-274-21/+47
* Bump PORTREVISION for x11 drivers that weren't updated.rnoland2009-01-2511-6/+22
* - Update X.org ports to 7.4+ (few ports are more recent than the katamari).flz2009-01-24124-676/+482
* - Update to 0.8.2miwi2009-01-184-35/+96
* - No need to define USE_REINPLACE these dayspav2009-01-091-1/+0
* Bye bye xf86-video-i810. Everybody should have switched to xf86-video-intelflz2009-01-066-44/+2
* Update distinfo.flz2008-12-231-3/+3
* - Update xf86-video-radeonhd to 1.2.4. [1]flz2008-12-231-4/+4
* Update x11-drivers/xf86-video-intel to 2.4.3.flz2008-12-234-8/+8
* Mark as broken on sparc64.linimon2008-12-101-1/+7
* o Fix typo (CONFLICT -> CONFLICTS).nork2008-12-082-2/+19
* - Fix missing shared object issuepgj2008-11-213-4/+14
* Add an X.Org driver, a kernel module, and a script to configure X.Orgpgj2008-11-187-0/+523
* - Remove xf86-input-wacom to be re-added it with a different namepgj2008-11-187-522/+0
* Add an X.Org driver, a kernel module, and a script to configure X.Orgpgj2008-11-177-0/+522
* Update to 2008.11.14.nork2008-11-142-4/+4
* Update to 1.4.9rnoland2008-11-113-156/+5
* Fix pkg-plist.nork2008-11-031-0/+1
* Fix build error [1] and cosmetic change.nork2008-11-031-3/+4
* o Update to 2008.11.03 based 1.2.3.nork2008-11-032-5/+5
* Update to 0.10.0rnoland2008-10-243-17/+5
* Add xf86-video-radeonhd-devel 1.2.1.20080906, supports newnork2008-09-284-13/+29
* - Limit to i386 and amd64gahr2008-09-161-0/+3
* - Mark BROKEN: does not compilepav2008-09-151-0/+2
* - Update to 2.1.12miwi2008-09-052-4/+4
* Update x11-drivers/xf86-video-intel to 2.4.2.flz2008-09-024-8/+8
* - Update to 2.1.11miwi2008-09-012-4/+4
* - Update to 0.2.903miwi2008-09-012-11/+5
* - Update to 0.2.902miwi2008-08-262-5/+4
* Update CONFIGURE_ARGS for how we pass CONFIGURE_TARGET to configure script.rafan2008-08-211-2/+0
* Update x11-drivers/xf86-video-intel to 2.4.0.flz2008-07-314-8/+8
* Update to 2.3.2.delphij2008-07-236-10/+14
* Update to 2.1.10.delphij2008-07-162-4/+4
* Update x11-drivers/xf86-video-nv to 2.1.9.flz2008-06-282-5/+4
* Update x11-drivers/xf86-video-ati to 6.9.0 and separate mach64 and r128jkim2008-06-2816-21/+80
* - Fix x11-drivers/synaptics after latest xorg-server update.flz2008-06-183-14/+9
* - Add conflicts with xf86-video-sis-intel.chinsan2008-06-141-0/+2
* Add xf86-video-sis-intel 300407, x.Org sis display driver provided bychinsan2008-06-1415-0/+351
* Bump portrevision due to upgrade of devel/gettext.edwin2008-06-06