Ignore:
Timestamp:
Nov 30, 2011, 8:47:35 PM (14 years ago)
Author:
bird
Message:

Added $(set-umask ) and $(get-umask ).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/function.c

    r2532 r2554  
    52385238}
    52395239#endif  /* CONFIG_WITH_COMMANDS_FUNC */
    5240 
    52415240#ifdef KMK
     5241
    52425242/* Useful when debugging kmk and/or makefiles. */
    52435243char *
     
    52555255  return o;
    52565256}
     5257
     5258/* umask | umask -S. */
     5259char *
     5260func_get_umask (char *o, char **argv UNUSED, const char *funcname UNUSED)
     5261{
     5262  char sz[80];
     5263  int off;
     5264  mode_t u;
     5265  int symbolic = 0;
     5266
     5267  if (argv[0])
     5268    {
     5269      if (   !strcmp (argv[0], "S")
     5270          || !strcmp (argv[0], "-S")
     5271          || !strcmp (argv[0], "symbolic") )
     5272        symbolic = 1;
     5273      else
     5274        error (reading_file, _("$(%s ) invalid argument `%s'"), funcname, argv[0]);
     5275    }
     5276
     5277  u = umask (002);
     5278  umask (u);
     5279
     5280  if (symbolic)
     5281    {
     5282      off = 0;
     5283      sz[off++] = 'u';
     5284      sz[off++] = '=';
     5285      if ((u & S_IRUSR) == 0)
     5286        sz[off++] = 'r';
     5287      if ((u & S_IWUSR) == 0)
     5288        sz[off++] = 'w';
     5289      if ((u & S_IXUSR) == 0)
     5290        sz[off++] = 'x';
     5291      sz[off++] = ',';
     5292      sz[off++] = 'g';
     5293      sz[off++] = '=';
     5294      if ((u & S_IRGRP) == 0)
     5295        sz[off++] = 'r';
     5296      if ((u & S_IWGRP) == 0)
     5297        sz[off++] = 'w';
     5298      if ((u & S_IXGRP) == 0)
     5299        sz[off++] = 'x';
     5300      sz[off++] = ',';
     5301      sz[off++] = 'o';
     5302      sz[off++] = '=';
     5303      if ((u & S_IROTH) == 0)
     5304        sz[off++] = 'r';
     5305      if ((u & S_IWOTH) == 0)
     5306        sz[off++] = 'w';
     5307      if ((u & S_IXOTH) == 0)
     5308        sz[off++] = 'x';
     5309    }
     5310  else
     5311    off = sprintf (sz, "%.4o", u);
     5312
     5313  return variable_buffer_output (o, sz, off);
     5314}
     5315
     5316
     5317/* umask 0002 | umask u=rwx,g=rwx,o=rx. */
     5318char *
     5319func_set_umask (char *o, char **argv UNUSED, const char *funcname UNUSED)
     5320{
     5321  mode_t u;
     5322  const char *psz;
     5323
     5324  /* Figure what kind of input this is. */
     5325  psz = argv[0];
     5326  while (isblank ((unsigned char)*psz))
     5327    psz++;
     5328
     5329  if (isdigit ((unsigned char)*psz))
     5330   {
     5331      u = 0;
     5332      while (*psz)
     5333        {
     5334          u <<= 3;
     5335          if (*psz >= '0' && *psz < '8')
     5336            u += *psz - '0';
     5337          else
     5338            error (reading_file, _("$(%s ) illegal number `%s'"), funcname, argv[0]);
     5339        }
     5340
     5341      if (argv[1] != NULL)
     5342          error (reading_file, _("$(%s ) too many arguments for octal mode"), funcname);
     5343  }
     5344  else
     5345  {
     5346      u = umask(0);
     5347      umask(u);
     5348      error (reading_file, _("$(%s ) symbol mode is not implemented"), funcname);
     5349  }
     5350
     5351  umask(u);
     5352
     5353  return o;
     5354}
     5355
    52575356#endif /* KMK */
    52585357
     
    54445543#ifdef KMK
    54455544  { STRING_SIZE_TUPLE("breakpoint"),    0,  0,  0,  func_breakpoint},
     5545  { STRING_SIZE_TUPLE("set-umask"),     1,  3,  1,  func_set_umask},
     5546  { STRING_SIZE_TUPLE("get-umask"),     0,  0,  0,  func_get_umask},
    54465547#endif
    54475548};
Note: See TracChangeset for help on using the changeset viewer.