cflags-compat.c (1903B)
1 // $Id$ --*- c -*-- 2 3 // Copyright (C) 2004 Enrico Scholz <ensc@delenn.intern.sigma-chemnitz.de> 4 // 5 // This program is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; version 2 of the License. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 19 #ifdef HAVE_CONFIG_H 20 # include <config.h> 21 #endif 22 23 #include "vserver.h" 24 #include <string.h> 25 #include <assert.h> 26 27 #define DECL(STR, VAL) { STR, sizeof(STR)-1, VAL } 28 29 static struct { 30 char const * const id; 31 size_t len; 32 unsigned char val; 33 } const FLAGVALUES[] = { 34 DECL("lock", S_CTX_INFO_LOCK), 35 DECL("sched", S_CTX_INFO_SCHED), 36 DECL("nproc", S_CTX_INFO_NPROC), 37 DECL("private", S_CTX_INFO_PRIVATE), 38 DECL("fakeinit", S_CTX_INFO_INIT), 39 DECL("hideinfo", S_CTX_INFO_HIDEINFO), 40 DECL("ulimit", S_CTX_INFO_ULIMIT), 41 DECL("namespace", S_CTX_INFO_NAMESPACE), 42 }; 43 44 uint_least32_t 45 vc_text2cflag_compat(char const *str, size_t len) 46 { 47 size_t i; 48 if (len==0) len=strlen(str); 49 50 for (i=0; i<sizeof(FLAGVALUES)/sizeof(FLAGVALUES[0]); ++i) 51 if (len==FLAGVALUES[i].len && 52 strncmp(FLAGVALUES[i].id, str, len)==0) 53 return FLAGVALUES[i].val; 54 55 return 0; 56 } 57 58 char const * 59 vc_hicflag2text_compat(uint_least32_t val) 60 { 61 size_t i; 62 size_t idx; 63 64 assert(S_CTX_INFO_ULIMIT==64); 65 66 for (i=S_CTX_INFO_ULIMIT, idx=6; i>0; i/=2, --idx) 67 if (val & i) return FLAGVALUES[idx].id; 68 69 return 0; 70 }