File: jchmod.c

package info (click to toggle)
emoslib 000380%2Bdfsg-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 47,712 kB
  • ctags: 11,551
  • sloc: fortran: 89,643; ansic: 24,200; makefile: 370; sh: 355
file content (63 lines) | stat: -rwxr-xr-x 1,289 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Copyright 1981-2007 ECMWF
* 
* Licensed under the GNU Lesser General Public License which
* incorporates the terms and conditions of version 3 of the GNU
* General Public License.
* See LICENSE and gpl-3.0.txt for details.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "fortint.h"

/*
// FORTRAN callable chmod:
//
//   INTEGER FUNCTION JCHMOD (NAME, MODE)
//   CHARACTER*(*) NAME, MODE
//
//   The normal returned value is 0.  Any other value will be a system error
//   number.
//
*/

fortint jchmod_(char * filename, char * char_mode, long l1, long l2)
{
mode_t mode = 0;
int i, status = 0;
char * name;

    if( (*char_mode) == '0' )
    {
      for( i = 0; i < l2; i++)
        mode = (mode*8) + (*(char_mode+i)-'0');
    }
    else
    {
      for( i = 0; i < l2; i++)
        mode = (mode*10) + (*(char_mode+i)-'0');
    }

    name = (char*) malloc(l1+1);
    for( i = 0; i < l1; i++)
      name[i] = filename[i];
    name[l1] = '\0';

    status = chmod(name, mode);
    if( status ) {
      perror("JCHMOD error");
      exit(1);
    }

    free(name);

    return (fortint) status;
}

fortint jchmod(char * filename, char * char_mode, long l1, long l2) {
  return jchmod_(filename,char_mode,l1,l2);
}