Commit 9d4e8725 authored by Olivier Duchateau's avatar Olivier Duchateau

Import 3 new files

parent c63c9e04
#include <stdio.h>
#include <stdlib.h> /* free() */
#include <glib.h>
#include <glib/gprintf.h>
#include <gio/gio.h>
int
main(int argc, char *argv[])
{
GFileInfo *info;
gchar *content_type;
GIcon *icon;
gchar *name = NULL;
info = g_file_query_info ();
content_type = g_content_type_get_description ("application/x-bat");
icon = g_content_type_get_icon (content_type);
g_free (content_type);
name = g_icon_to_string (icon);
if (name != NULL)
g_printf ("%s\n", name);
g_object_unref (icon);
return 0;
}
/**
* Simple C script in order to use kqueue/kevent and libgeom.
*
* clang -Wall -lc devd-devices.c -o devd-devices
*/
#include <stdio.h>
#include <string.h> /* strlcpy */
#include <sys/socket.h>
#include <sys/un.h> /* struct sockaddr_un */
#include <sys/event.h>
#define DEVD_SOCKET "/var/run/devd.pipe"
int
main (int argc, char *argv[])
{
int fd, kq, res;
struct sockaddr_un addr;
struct kevent event;
ssize_t ret;
char buf[1024];
fd = socket (PF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
perror ("socket");
}
addr.sun_family = AF_UNIX;
strlcpy (addr.sun_path, DEVD_SOCKET, sizeof (addr.sun_path));
if (connect (fd, (struct sockaddr *) &addr, sizeof (struct sockaddr_un)) < 0) {
perror ("connect");
}
/* Create kqueue */
kq = kqueue ();
if (kq < 0) {
perror ("kqueue");
}
else {
/* Initialize kevent structure */
EV_SET (&event, fd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, NULL);
/* Attach event to the kqueue */
res = kevent (kq, &event, 1, NULL, 0, NULL);
if (res < 0) {
perror ("kevent");
}
/* Infinite loop */
for (;;) {
ret = read (fd, buf, event.data);
printf ("%s\n", buf);
}
}
if (fd > 0)
close (fd);
return 0;
}
/**
*
* Simple script, which displays stats (using libpkg).
*
* cc -Wall -lc -lpkg -I/usr/include -I/usr/local/include
*/
#include <stdio.h>
#include <inttypes.h> /* PRId64 macro */
#include <pkg.h>
int
main (int argc, char *argv[])
{
struct pkgdb *db = NULL;
int64_t stat;
if (pkgdb_open (&db, PKGDB_REMOTE) != EPKG_OK) {
perror ("pkgdb_open");
}
else {
if (pkgdb_obtain_lock (db, PKGDB_LOCK_READONLY) != EPKG_OK) {
perror ("pkgdb_obtain_lock");
}
else {
stat = pkgdb_stats (db, PKG_STATS_REMOTE_REPOS);
printf ("%" PRId64 "\n", stat);
}
}
pkgdb_close (db);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment