Changeset 2554 for trunk/src


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

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

Location:
trunk/src/kmk
Files:
2 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};
  • trunk/src/kmk/variable.c

    r2549 r2554  
    13311331  && defined (KMK_HELPERS)
    13321332  (void) define_variable ("KMK_FEATURES", 12,
    1333                           "append-dash-n abspath includedep-queue install-hard-linking"
     1333                          "append-dash-n abspath includedep-queue install-hard-linking umask"
    13341334                          " kBuild-define"
    13351335                          " rsort"
     
    13571357                          " root"
    13581358                          " length insert pos lastpos substr translate"
    1359                           " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one kb-exp-tmpl "
    1360                           " firstdefined lastdefined "
     1359                          " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one kb-exp-tmpl"
     1360                          " firstdefined lastdefined"
    13611361                          , o_default, 0);
    13621362# else /* MSC can't deal with strings mixed with #if/#endif, thus the slow way. */
    13631363#  error "All features should be enabled by default!"
    1364   strcpy (buf, "append-dash-n abspath includedep-queue install-hard-linking"
     1364  strcpy (buf, "append-dash-n abspath includedep-queue install-hard-linking umask"
    13651365               " kBuild-define");
    13661366#  if defined (CONFIG_WITH_RSORT)
Note: See TracChangeset for help on using the changeset viewer.