|
| 1 | +/**************************************************************************** |
| 2 | + * libs/libc/termios/lib_tcgetpgrp.c |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * |
| 6 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 7 | + * contributor license agreements. See the NOTICE file distributed with |
| 8 | + * this work for additional information regarding copyright ownership. The |
| 9 | + * ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 10 | + * "License"); you may not use this file except in compliance with the |
| 11 | + * License. You may obtain a copy of the License at |
| 12 | + * |
| 13 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | + * |
| 15 | + * Unless required by applicable law or agreed to in writing, software |
| 16 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 18 | + * License for the specific language governing permissions and limitations |
| 19 | + * under the License. |
| 20 | + * |
| 21 | + ****************************************************************************/ |
| 22 | + |
| 23 | +/**************************************************************************** |
| 24 | + * Included Files |
| 25 | + ****************************************************************************/ |
| 26 | + |
| 27 | +#include <nuttx/config.h> |
| 28 | + |
| 29 | +#include <sys/ioctl.h> |
| 30 | + |
| 31 | +#include <unistd.h> |
| 32 | + |
| 33 | +#include <nuttx/serial/tioctl.h> |
| 34 | + |
| 35 | +/**************************************************************************** |
| 36 | + * Public Functions |
| 37 | + ****************************************************************************/ |
| 38 | + |
| 39 | +/**************************************************************************** |
| 40 | + * Name: tcgetpgrp |
| 41 | + * |
| 42 | + * Description: |
| 43 | + * Return the value of the process group ID of the foreground process |
| 44 | + * group associated with the terminal. |
| 45 | + * |
| 46 | + * Input Parameters: |
| 47 | + * fd - The 'fd' argument is an open file descriptor associated with a |
| 48 | + * terminal. |
| 49 | + * |
| 50 | + * Returned Value: |
| 51 | + * Upon successful completion, the process group ID of the foreground |
| 52 | + * process group is returned. Otherwise, (pid_t)-1 is returned and errno |
| 53 | + * is set to indicate the error. |
| 54 | + * |
| 55 | + ****************************************************************************/ |
| 56 | + |
| 57 | +pid_t tcgetpgrp(int fd) |
| 58 | +{ |
| 59 | + pid_t pgrp; |
| 60 | + |
| 61 | + if (ioctl(fd, TIOCGPGRP, &pgrp) < 0) |
| 62 | + { |
| 63 | + return (pid_t)-1; |
| 64 | + } |
| 65 | + |
| 66 | + return pgrp; |
| 67 | +} |
0 commit comments