/* * * This file is part of bufferpool * * Copyright (C) 2007 by LScube team * See AUTHORS for more details * * bufferpool is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * bufferpool 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with bufferpool; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * * this piece of code was inspired from Richard Stevens source code of * UNIX Network Programming, Volume 2, Second Edition: Interprocess Communications, * Prentice Hall, 1999, ISBN 0-13-081081-9. * * */ #include #include #include #include #ifndef PATH_MAX #define PATH_MAX 4096 #endif char *bp_ipc_name(const char *firstname, const char *lastname) { char *dir, *dst, *slash; if ((dst = malloc(PATH_MAX)) == NULL) return (NULL); /* 4can override default directory with environment variable */ if ((dir = getenv("PX_IPC_NAME")) == NULL) { #ifdef POSIX_IPC_PREFIX dir = POSIX_IPC_PREFIX; /* from "config.h" */ #else dir = ""; // "/tmp/"; /* default */ #endif } /* 4dir must end in a slash */ slash = (strlen(dir) && (dir[strlen(dir) - 1] == '/')) ? "" : "/"; snprintf(dst, PATH_MAX, "%s%s%s.%s", dir, slash, firstname, lastname); return (dst); /* caller can free() this pointer */ }