Cygwin: access: Fix X_OK behaviour for backup operators and admins
[newlib-cygwin.git] / newlib / libc / sys / epiphany / e_printf.c
bloba93c3432004998e1f7e7fbde8b639582ea2fc14c
1 /* e_printf.c
3 Copyright (c) 2011, Adapteva, Inc.
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of Adapteva nor the names of its contributors may be
14 used to endorse or promote products derived from this software without
15 specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE. */
28 #include <stdarg.h>
29 #include <string.h>
34 int trap_7( char *s , int _bsize, int _argsize) {
35 volatile register void* buff_adrr asm("r0") = s;
36 volatile register unsigned bsize asm("r1") = _bsize;
37 volatile register unsigned argsize asm("r2") = _argsize;
38 volatile register int result asm("r0");
39 __asm__ __volatile__ ("trap 7" : "=r" (result) : "r" (buff_adrr), "r" (bsize) , "r" (argsize));
40 return result;
44 //#include <stdio.h>
45 //#include <string.h>
46 //#include <stdlib.h>
48 volatile static int*fp_int =0;
49 volatile int getIntFromFloat(float *f) {
50 fp_int= (int*)f;
52 return *fp_int;
56 int e_printf(const char *fmt, ...) {
58 char buf[256],*p,*fmt_p;
59 va_list args;
60 int percentMet=0;
61 int pos = 0;
63 char *v_arg_s;
64 unsigned v_arg_int;
65 float fl_f[1];
67 unsigned fmt_len = strnlen(fmt,128);
69 fmt_p = (char*)fmt;
71 //printf("---- 111 +++ %d \n", strlen(fmt));
73 va_start(args, fmt);
75 p = (char*)buf;
77 strcpy(buf,fmt);
78 pos =fmt_len;
79 p[pos] = '\0';
80 pos++;
82 va_start(args, fmt);
84 while (*fmt_p) {
86 // putchar(*p);
87 // puts("");
89 if(*fmt_p == '%') {
90 percentMet=1;
92 if(*fmt_p == 's' && percentMet == 1 ) {
93 percentMet=0;
94 v_arg_s = va_arg(args, char *);
95 if (!v_arg_s) v_arg_s = "<NULL>";
97 strcpy(p + pos , v_arg_s );
98 pos+=strlen(v_arg_s);
100 p[pos] = '\0';
101 pos++;
104 if((*fmt_p == 'i' || *fmt_p == 'd' || *fmt_p == 'u' || *fmt_p == 'x' || *fmt_p == 'f' ) && percentMet == 1 ) {
105 percentMet=0;
106 if(*fmt_p == 'f' ) {
107 fl_f[0] = (float)va_arg(args, double);
108 //printf("v_arg_ float --- %f \n", fl_f[0]);
109 //printf("v_arg_ p --- %x \n", *( (unsigned *)fl_f));
111 v_arg_int = getIntFromFloat (fl_f);
113 //v_arg_int = 0;
115 } else {
116 v_arg_int = (int)va_arg(args, int);
119 // if(*fmt_p == 'd') {
120 // printf("v_arg_int --- %d \n", v_arg_int);
121 // }
122 // if(*fmt_p == 'x') {
123 // printf("v_arg_int --- %x \n", v_arg_int);
124 // }
125 // if(*fmt_p == 'f') {
126 // printf("fff++v_arg_int --- %x \n", v_arg_int);
127 // fl = (float*)&v_arg_int;
128 // printf("fff++ v_arg_float --- %f \n", *fl);
129 // }
131 *(p + pos) = ((v_arg_int>>24) & 0xff);
132 pos++;
133 *(p + pos) = ((v_arg_int>>16) & 0xff);
134 pos++;
135 *(p + pos) = ((v_arg_int>>8) & 0xff);
136 pos++;
137 *(p + pos) = ((v_arg_int>>0) & 0xff);
138 pos++;
141 fmt_p++;
144 va_end(args);
146 //printf(" +++ %d %d \n" , strlen(fmt), pos);
148 return trap_7((char*)buf ,fmt_len, pos) ;
149 //return 1;