Magellan Linux

Diff of /trunk/mkinitrd-magellan/klibc/usr/dash/var.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1121 by niro, Sat Sep 1 22:45:15 2007 UTC revision 1122 by niro, Wed Aug 18 21:11:40 2010 UTC
# Line 90  struct var varinit[] = { Line 90  struct var varinit[] = {
90   { 0, VSTRFIXED|VTEXTFIXED, "PS2=> ", 0 },   { 0, VSTRFIXED|VTEXTFIXED, "PS2=> ", 0 },
91   { 0, VSTRFIXED|VTEXTFIXED, "PS4=+ ", 0 },   { 0, VSTRFIXED|VTEXTFIXED, "PS4=+ ", 0 },
92   { 0, VSTRFIXED|VTEXTFIXED, "OPTIND=1", getoptsreset },   { 0, VSTRFIXED|VTEXTFIXED, "OPTIND=1", getoptsreset },
93     { 0, VSTRFIXED|VTEXTFIXED, "LINENO=1", 0 },
94  #ifndef SMALL  #ifndef SMALL
95   { 0, VSTRFIXED|VTEXTFIXED|VUNSET, "TERM\0", 0 },   { 0, VSTRFIXED|VTEXTFIXED|VUNSET, "TERM\0", 0 },
96   { 0, VSTRFIXED|VTEXTFIXED|VUNSET, "HISTSIZE\0", sethistsize },   { 0, VSTRFIXED|VTEXTFIXED|VUNSET, "HISTSIZE\0", sethistsize },
# Line 168  initvar(void) Line 169  initvar(void)
169  }  }
170    
171  /*  /*
  * Safe version of setvar, returns 1 on success 0 on failure.  
  */  
   
 int  
 setvarsafe(const char *name, const char *val, int flags)  
 {  
  int err;  
  volatile int saveint;  
  struct jmploc *volatile savehandler = handler;  
  struct jmploc jmploc;  
   
  SAVEINT(saveint);  
  if (setjmp(jmploc.loc))  
  err = 1;  
  else {  
  handler = &jmploc;  
  setvar(name, val, flags);  
  err = 0;  
  }  
  handler = savehandler;  
  RESTOREINT(saveint);  
  return err;  
 }  
   
 /*  
172   * Set the value of a variable.  The flags argument is ored with the   * Set the value of a variable.  The flags argument is ored with the
173   * flags of the variable.  If val is NULL, the variable is unset.   * flags of the variable.  If val is NULL, the variable is unset.
174   */   */
# Line 227  setvar(const char *name, const char *val Line 203  setvar(const char *name, const char *val
203   INTON;   INTON;
204  }  }
205    
206    /*
207     * Set the given integer as the value of a variable.  The flags argument is
208     * ored with the flags of the variable.
209     */
210    
211    intmax_t setvarint(const char *name, intmax_t val, int flags)
212    {
213     int len = max_int_length(sizeof(val));
214     char buf[len];
215    
216     fmtstr(buf, len, "%jd", val);
217     setvar(name, buf, flags);
218     return val;
219    }
220    
221    
222    
223  /*  /*
# Line 318  lookupvar(const char *name) Line 309  lookupvar(const char *name)
309   return NULL;   return NULL;
310  }  }
311    
312    intmax_t lookupvarint(const char *name)
313    {
314     return atomax(lookupvar(name) ?: nullstr, 0);
315    }
316    
317    
318    
319  /*  /*

Legend:
Removed from v.1121  
changed lines
  Added in v.1122